Blank/empty screenshot when WebUI.navigateToUrl() fails

Hi, I’m running a script in headless mode (chrome), once in a while the script fails to navigate to the url, and I’m getting the following error from Katalon:
Unable to navigate to ‘<the_url:I’m_navigating to>’,

The whole script is in a try catch, so when an error occurs I’m taking a screenshot.

Each time this problem occur I’m getting a blank (white screenshot whit no content), is this expected behavior: If a navigate to url fails the content is blank/empty?

Thanks.

@Thomas_Enge, can you provide your script and screenshots of the process. You can follow the thread [TIP] How To Help Us Help You! to provide more information.

Hi Chen,
Below you’ll find the script I’m running:

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys


import com.kms.katalon.core.exception.StepErrorException as StepErrorException
import com.kms.katalon.core.exception.StepFailedException as StepFailedException
import com.kms.katalon.core.configuration.RunConfiguration


//custom imports:
import groovy.json.*
import java.text.SimpleDateFormat as SimpleDateFormat
import java.util.Date as Date
import groovy.time.TimeCategory as TimeCategory
import groovy.time.TimeDuration as TimeDuration
import java.nio.file.Paths as Paths
import java.io.File as File
import org.eclipse.jetty.util.ssl.SslContextFactory as SslContextFactory

import org.eclipse.jetty.client.util.MultiPartContentProvider as MultiPartContentProvider
import org.eclipse.jetty.client.util.StringContentProvider as StringContentProvider
import org.eclipse.jetty.client.util.PathContentProvider as PathContentProvider


import org.eclipse.jetty.client.api.ContentResponse as ContentResponse
import org.eclipse.jetty.client.HttpClient as HttpClient
import org.eclipse.jetty.http.HttpMethod as HttpMethod

//RunConfiguration.setWebDriverPreferencesProperty(“args”, [“window-size=1920,1080”])

static void runBatchFile(String batchFile) {
	String bf = RunConfiguration.getProjectDir() + '/' + batchFile
	println("Running batch file: " + bf)
	Runtime.runtime.exec(bf)
  }

def postData (def url, def api, def service, def element, def aggregate, def threshold, def qualifier, def missing, def breach, def unit, def timeStart) {
	//println( url + api + service, def element, def aggregate, def threshold, def qualifier, def missing, def breach, def unit, def timeStart)
	
	String value
	def ceeBody = []
	
	if (timeStart.getClass() == Date) {
		def timeStop = new Date()

		duration = TimeCategory.minus(timeStop, timeStart)

		value = String.format('%.2f', ((duration.toMilliseconds()) as double) / 1000)

		value = value.replaceAll(',', '.')

		total = (Double.parseDouble(value) + total)
		println("Total time= "+total)
	} else if (timeStart == 0) {
		value = ''
	} else {
		value = timeStart
	}
		
	println("Step time for:"+element+"\\"+qualifier+" ======"+value)
	
	if ((step==0) || (step==max)) {
		ceeBody = [
		  "apiToken"  : api,
		  "threshold" : threshold,
		  "operator"  : "LT",
		  "unit"      : unit,
		  "data"      : [
			[
				"service" : service,
				"element" : element,
				
				"aggregate" : aggregate,
				"qualifier" : qualifier,
				"value" : value,
				"asset" : "app-server",
				"errorOnMissing":missing,
				"breachOnMissing":breach,
				"interval":sqInterval
			]
		  ]
		]
	} else{
		parent = arrElement.get(step-1)
		ceeBody = [
			"apiToken"  : api,
			"threshold" : threshold,
			"operator"  : "LT",
			"unit"      : unit,
			"data"      : [
			  [
				  "service" : service,
				  "element" : element,
				  "parent":parent,
				  "aggregate" : aggregate,
				  "qualifier" : qualifier,
				  "value" : value,
				  "asset" : "app-server",
				  "errorOnMissing":missing,
				  "breachOnMissing":breach,
				  "interval":sqInterval
			  ]
			]
		  ]
	}
	println("Parent = "+parent)
	
	jsonBody = new JsonBuilder(ceeBody).toPrettyString()
	println(jsonBody)
	
	
	def putCeeview = new URL(url).openConnection();
	putCeeview.setDoOutput(true)
	putCeeview.setRequestMethod("POST")
	putCeeview.setRequestProperty("Content-Type", "application/json")
	
	def httpRequestWriter = new BufferedWriter(new OutputStreamWriter(putCeeview.getOutputStream()))
	httpRequestWriter.write(jsonBody)
	httpRequestWriter.close()
	
	def getCRC = putCeeview.getResponseCode();
	println ("Return code from auth request is: "+getCRC)
	
	putCeeview.disconnect();
	
	if (step < max) {
		step = (step + 1)
	}
	
	println('Current step is: ' + step)
}

/*
def verify(def test) {
	if (test == false) {
		println('Currently inside verify function...........for step: ' + arrElement.get(step))

		throw new StepFailedException(arrElement.get(step))
	}
}
*/

def error(def ts) {
	println('Currently inside error function............for step: '+ arrElement.get(step))

	Date data = new Date(System.currentTimeMillis())
	SimpleDateFormat formatarDate = new SimpleDateFormat('yyyyMMddHHmmss')
	file = file + formatarDate.format(data) + '.png'
	println('Current file name is: ' + file)
	WebUI.delay(1)
	WebUI.waitForPageLoad(5)
	WebUI.takeScreenshot(file)
	//WebUI.takeFullPageScreenshot(file)
	u=WebUI.getUrl()
	println("The current url is: "+u)
	
	println("api="+api)
	println("service="+service)
	println("element="+arrElement.get(step))
	println("qualifier="+arrQualifier.get(step))
	println("error="+(('Script failed in Qualifier: ' + arrQualifier.get(step)) +
		' , Error is: ') + stack + ", the current url is: "+u)
	println("file="+file)
	
	// Instantiate and configure the SslContextFactory
	
	SslContextFactory sslContextFactory = new SslContextFactory();
	//sslContextFactory.setTrustAll(true);
	HttpClient httpClient = new HttpClient(sslContextFactory)
	
	//HttpClient httpClient = new HttpClient()
	httpClient.start()
	MultiPartContentProvider multiPart = new MultiPartContentProvider()
	multiPart.addFieldPart('apiToken', new StringContentProvider(api), null)
	multiPart.addFieldPart('service', new StringContentProvider(service), null)
	multiPart.addFieldPart('element', new StringContentProvider(arrElement.get(step)), null)
	multiPart.addFieldPart('qualifier', new StringContentProvider(arrQualifier.get(step)), null)
	multiPart.addFieldPart('error', new StringContentProvider((('Script failed in Qualifier: ' + arrQualifier.get(step)) +
		' , Error is: ') + stack + ", the current url is: "+u), null)
	//multiPart.addFieldPart('error', new StringContentProvider((('Script failed in Qualifier: ' + arrQualifier.get(step)) +
	//	' , Error is: ') + stack ), null)
	multiPart.addFilePart('file', 'img.png', new PathContentProvider(Paths.get(file)), null)
	multiPart.close()
	
	println(multiPart)
	 
	ContentResponse response = httpClient.newRequest(url).method(HttpMethod.POST).content(multiPart).send()
	println('Current element is: ' + arrElement.get(step))
	println('Current qualifer is: ' + arrQualifier.get(step))
	println('Response from current error is: ' + response)

	MultiPartContentProvider multiPart2 = new MultiPartContentProvider()
	multiPart2.addFieldPart('apiToken', new StringContentProvider(api), null)
	multiPart2.addFieldPart('service', new StringContentProvider(service), null)
	multiPart2.addFieldPart('element', new StringContentProvider(arrElement.get(max)), null)
	multiPart2.addFieldPart('qualifier', new StringContentProvider(arrQualifier.get(max)), null)
	multiPart2.addFieldPart('error', new StringContentProvider((((('Failed due to error in previous step: --Element: ' +
		arrElement.get(step)) + ' --Qualifier: ') + arrQualifier.get(step)) + ' , Error is: ') + stack + ", the current url is: "+u), null)
	//multiPart2.addFieldPart('error', new StringContentProvider((((('Failed due to error in previous step: --Element: ' +
	//	arrElement.get(step)) + ' --Qualifier: ') + arrQualifier.get(step)) + ' , Error is: ') + stack), null)
	multiPart2.addFilePart('file', 'img.png', new PathContentProvider(Paths.get(file)), null)
	multiPart2.close()
	
	println('Total element is: ' + arrElement.get(max))
	println('Total qualifier is: ' + arrQualifier.get(max))

	ContentResponse response2 = httpClient.newRequest(url).method(HttpMethod.POST).content(multiPart2).send()

	println('Response from root is: ' + response2)
	WebUI.closeBrowser()

	println('Should now exit, error is: ' + stack)
	runBatchFile("prune.bat")
}

for (int i = 0; i <=1; i++) {
	total = 0
	timeStart = 0
	
	url = 'https://xxxxxxx.com/api/v1/dataintegration/service'
	api = 'xxxxxx'
	logDir = RunConfiguration.getProjectDir() + "/Reports"
	file = RunConfiguration.getProjectDir() + "/Data Files/screenshot_"
	service = 'BorDrilling-Docmap'
	aggregate = 'false'
	threshold = '25'
	missing = 'false'
	breach = 'true'
	unit = 'SECOND'
	sqInterval = 300
	parent=""
	
	arrElement = ['Open browser', 'Launch site', 'Verify login', 'Verify main page', 'Logout and close', service]
	arrQualifier = ['Open browser time', 'Launch time', 'Login time', 'Verify main time', 'Logout time', 'Total']
	max = (arrElement.size() - 1)
	println('max= '+max)
	stack = ''
	step = 0
	
	try {
		
		
		
		//open browser
		timeStart = new Date()
		WebUI.openBrowser('')
		WebUI.maximizeWindow()
		postData(url, api, service, arrElement.get(step), aggregate, threshold, arrQualifier.get(step), missing, breach, unit, timeStart)
		
		//WebUI.navigateToUrl('https://google.com')
		
		//launch site
		timeStart = new Date()
		WebUI.navigateToUrl('https://borr.docmap.com/BorrDrilling/page/common/dmpLogin.html')
		WebUI.verifyElementVisible(findTestObject('Object Repository/Page_Docmap Please sign in/input_Docmap Sign in_USER'))	
		postData(url, api, service, arrElement.get(step), aggregate, threshold, arrQualifier.get(step), missing, breach, unit, timeStart)
		
		//login	
		timeStart = new Date()
		WebUI.setText(findTestObject('Object Repository/Page_Docmap Please sign in/input_Docmap Sign in_USER'), 'xxxxx')
		WebUI.setEncryptedText(findTestObject('Object Repository/Page_Docmap Please sign in/input_Docmap Sign in__PASSWORD'), 'xxxxxxxxx')
		WebUI.click(findTestObject('Object Repository/Page_Docmap Please sign in/div_Sign in'))
		
		postData(url, api, service, arrElement.get(step), aggregate, threshold, arrQualifier.get(step), missing, breach, unit, timeStart)
		
		//verify login	
		WebUI.delay(1)
		timeStart = new Date()
		//WebUI.verifyElementVisible(findTestObject('Object Repository/Page_Docmap Documents/span_Sign out'))
		WebUI.click(findTestObject('Object Repository/Page_Docmap Documents/span_Sign out'))
		WebUI.delay(1)
		
		WebUI.verifyElementVisible(findTestObject('Object Repository/Page_Docmap Documents/div_Yes'))
			
		WebUI.click(findTestObject('Object Repository/Page_Docmap Documents/div_Yes'))
		
		WebUI.delay(1)
		
		postData(url, api, service, arrElement.get(step), aggregate, 60, arrQualifier.get(step), missing, breach, unit, timeStart)
		
		//logout & close
		timeStart = new Date()
		WebUI.closeBrowser()
		println("Posting Last check :"+arrElement.get(step))
		postData(url, api, service, arrElement.get(step), aggregate, 35, arrQualifier.get(step), missing, breach, unit, timeStart)
	
		//post data for total
		println("Posting final :"+arrElement.get(step))
		postData(url, api, service, arrElement.get(step), aggregate, 140, arrQualifier.get(step), missing, breach, unit, total)
		
		//clean up all temp files, leave reports for 6 hrs:
		runBatchFile("prune.bat")
		//end if no errors
		break;	
		
	
	}
	catch (IllegalArgumentException e) {
		println 'IllegalArgumentException'
		stack = e.getMessage()
		println(stack)
		error(timeStart)
	}
	catch (StepFailedException e) {
		println 'StepFailedException'
		stack = e.getMessage()
		println(stack)
		error(timeStart)
	}
	catch (StepErrorException e) {
		println 'StepErrorException'
		stack = e.getMessage()
		println(stack)
		error(timeStart)
	}
	catch (AssertionError e) {
		println 'AssertionError'
		stack = e.getMessage()
		println(stack)
		error(timeStart)
	}
	catch (Exception e) {
		println 'Exception'
		stack = e.getMessage()
		println(stack)
		error(timeStart)
	}
	catch (Throwable e) {
		println 'Throwable'
		stack = e.getMessage()
		println(stack)
		error(timeStart)
	}
}



The problem happens intermittently (once a day) on line 270:
WebUI.navigateToUrl(‘Sign in to your account’)

Once Katalon is unable to navigate to the url, the code goes into my error routine and generates the screenshot, which is always /blank/empty/white.

I currently only have a copy of one of these screenshots,files (the file is renamed) and can be downloaded from dropbox:

https://www.dropbox.com/s/1559pxt8duguv0b/screenshot.png?dl=0

Thanks!

@Thomas_Enge, I did a minor test by opening the browser and navigating to the given URL. From what I see, I assume when Katalon is trying to open and load the page, it presents a white screen, so your catch method immediately captures that instead of waiting for an error page.

@chen.lee , the screen you display in your previous comments, is what happens after the first 2 WebUi functions:

WebUI.openBrowser('')
WebUI.maximizeWindow()

So when the next command is initiated:

WebUI.navigateToUrl('https://borr.docmap.com/BorrDrilling/page/common/dmpLogin.html')

This commands fails, and my code goes into the catch method, and generates a screenshot. To me it seems like the screenshot is from the previous command, and that the navigateToUrl() has failed to initiate?? (I’m getting the screenshot of the last successful command :slight_smile:
WebUI.maximizeWindow() ??? Since Katalon is unable to navigate to the url specified?

This is exactly what I don’t understand: I would expect the screenshot to display an error page from the failed WebUI.navigateToURl(), to me it seems like the command fails to run in Katalon…

Am I misunderstanding something here?