Failure Handling


This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/failure-handling.html

Looking to understand how i might use the failure method in a try catch function? Specifically I would like to move to the next item in the link array upon hitting a 404 page instead of just letting my code fall off a cliff. Just not sure what I should be working around with the pre-build error handling methods.

Hello,
if you want to catch error, you just have to use “FailureHandling.OPTIONAL” in your try instructions.

Example :

boolean browserAlreadyOpenedAtGoodUrl
String currentUrL
try {
	//	com.kms.katalon.core.webui.driver.DriverFactory.verifyWebDriverIsOpen()
	WebUI.switchToWindowUrl(GlobalVariable.url, FailureHandling.OPTIONAL)
	currentUrL= WebUI.getUrl()
	
	if (currentUrL.equals( GlobalVariable.url)) {
		browserAlreadyOpenedAtGoodUrl=true
	}
	
} catch (Exception e) {
	browserAlreadyOpenedAtGoodUrl=false
}

for (def rowNum = 1; rowNum <= 2; rowNum++) {
try {
KeywordLogger log = new KeywordLogger()
log.logInfo(“Execution strats”)
WebUI.callTestCase(findTestCase(‘CP/Dummy Case’), [:], FailureHandling.OPTIONAL)

	log.logInfo("in try")
}
catch (Exception ex) {
	KeywordLogger log = new KeywordLogger()
	log.logInfo("testmsg")
	
	
	
    WebUI.closeBrowser()
	

    continue
} 
WebUI.closeBrowser()

}

catch block code is not working i am not getting any log from catch block please refer above code…
I having issue for data driven, i want to execute 1k rows with 15 test cases in the in a loop,
e.g. when Tc5 from out of 15 test cases is getting failed then it is still getting execute the TC6 i want to continue it from TC1 from next excel row…

Hello,
I am having same issue with Katalon Studio 7.2.1.
Is there any idea how to get FAILURE instead of WARNING for Wait For Element Visible keyword?

This is some example:

Script:
‘Wait for object is visible (logo)’
WebUI.waitForElementVisible(findTestObject(‘wep_001_Login_Page/logo’), 5, FailureHandling.STOP_ON_FAILURE)

Execution log:
waitForElementVisible(findTestObject(“wep_001_Login_Page/logo”), 5, STOP_ON_FAILURE)
Start / End / Elapsed: 2020-02-10 11:15:36.700 / 2020-02-10 11:15:41.988 / 00:00:05.288
11:15:41.957 INFO Unable to find the element located by ‘By.xpath: //img[@name=‘isc_7main’]’. Please recheck the objects properties to make sure the desired element is located.
11:15:41.964 INFO [SMART_XPATH] Auto-trying out other XPath values in the test object.
11:15:41.974 INFO [SMART_XPATH] FAILED XPATH: ‘//img[@name=‘isc_7main’]’.
11:15:41.974 INFO [SMART_XPATH] No working XPath is found.
11:15:41.986 WARNING Web element with id: 'Object Repository/wep_001_Login_Page/logo’ located by ‘By.xpath: //img[@name=‘isc_7main’]’ not found

Project settings > Test Design > Test Case > Default Failure Handling for Test Step: STOP_ON_FAILURE

HELP!

From what I’ve seen by digging through the source code (https://github.com/katalon-studio/katalon-studio-testing-framework/blob/aec97e9b5ffb371676c205596ec2e54e7998528c/Include/scripts/groovy/com/kms/katalon/core/webui/keyword/builtin/WaitForElementVisibleKeyword.groovy#L78),
the waitForElementVisible (and waitForElementPresent) keyword catches the underlying WebElementNotFoundException or TimeoutException and instead only returns false if an element is not visible.

I think you would need to check the return value of waitForElementVisible and then throw some sort of Exception if it’s false in order to get the behavior you want.

Thank you Greg!
So, some solution exist, but this kind of things should be done by Katalon itself, so we can have smooth test building and execution. Not 100% sure now, but I think that long time ago Katalon had different behaviour for this keywords, meaning they throw simple FAILURE in case object is not visible or present.

I’m having an issue with being unable to compare the value of a string when soap:Fault appears.
Normally soap:Body is included in a return from my web service and when creating a locator string, it can be ignored.
E.G.
soap:Body
displayResponse xmlns=“urn:example”>
disExampleOutput> Example data not in database
</disExampleOutput
</displayResponse
</soap:Body>

the locator string is ‘displayResponse.disExampleOutput’

but if soap:Fault exists, my locator string breaks, always.
E.G.
soap:Body
soap:Fault
faultcode>9999
</faultcode
faultstring>Fault Message: Specified data was not found
</faultstring
</soap:Fault>
</soap:Body>

I’ve tried both ‘faultstring’ and ‘soap:Fault.faultstring’ but neither work.
Let me know if there is a solution for this.

Edit note: some <'s and >'s were removed because it was causing tags to not appear.

Thanks,
Chaseur

Is this setting done at test case level retained even at the test suite level? I mean, during the execution of test suite?

I’m writing a custom keyword that waits for text to be present on the page, and I’d like to have it reflect the same signature as waitForElementPresent:

public boolean waitForTextPresent(String text, int timeOut)
public boolean waitForTextPresent(String text, int timeOut, FailureHandling flowControl)

If no FailureHandling is supplied, I’d like to have it use the default FailureHandling set in Project > Settings > Test Design > Test Case instead of just FailureHandling.STOP_ON_FAILURE. i.e. something like FailureHandling.PROJECT_DEFAULT, but that doesn’t exist :stuck_out_tongue:

Is there any way I can get my function to access/use the same default FailureHandling defined in the project settings?

I’m having an issue.

instead of FailureHandling.STOP_ON_FAILURE, when Katalon detect failed while running, I want Katalon to do logout and close the browser.

any suggest? Help.

Thankyou

Hi @david.umboh, you can try Test Listeners (more detail on this document: Test Fixtures and Test Listeners (Test Hooks)). I found a sample test listener script here on our forum that might be helpful for you.

1 Like