Conditional statements

Katalon seems to be an easy to use testtool to create aut testscripts very easy. But now and than there is something strange in appearantly simple constructions in the testcases.
I want to make a conditional step in my case ( if this is true, then do that). It seems that it only works if the condition is indeed true. If the condition is false, then i get the message
statement:

if (!WebUI.verifyElementAttributeValue(findTestObject(‘InProces/Inproces 2.12-SNAPSHOT/md-switch_afgehandeld’), ‘aria-checked’,

'false', 0)) {

WebUI.click(findTestObject('InProces/Inproces 2.12-SNAPSHOT/md-switch\_afgehandeld'), FailureHandling.CONTINUE\_ON_FAILURE)

}

error:
Test Cases/koppel CB in Squit2020 FAILED because (of) Unable to verify if object ‘Object Repository/InProces/Inproces 2.12-SNAPSHOT/md-switch_afgehandeld’ has attribute ‘aria-checked’ with value ‘false’ (Root cause: Object ‘Object Repository/InProces/Inproces 2.12-SNAPSHOT/md-switch_afgehandeld’ has attribute ‘aria-checked’ with actual value ‘true’ instead of expected value ‘false’)

is this a bug or am I causing this failure? Is there anybody with an idea how to solve this?

It’s not a bug. Katalon really will throw an error if a verify method returns false. I did a quick test on YOPmail.

**Code:
**WebUI.verifyElementAttributeValue(findTestObject(‘YOPmail - Inbox/txtRecipient’), ‘name’, ‘poi’, 0)

**Error:
**Test Cases/Send Mail FAILED because (of) Unable to verify if object ‘Object Repository/YOPmail - Inbox/txtRecipient’ has attribute ‘name’ with value ‘poi’ (Root cause: Object ‘Object Repository/YOPmail - Inbox/txtRecipient’ has attribute ‘name’ with actual value ‘mailto’ instead of expected value ‘poi’)

I was able to solve this using the FailureHandling.OPTIONAL in my condition.
Instead of using the “!” I used “== false” in the condition. See the example below:

if ((WebUI.verifyElementVisible(button_Create, FailureHandling.OPTIONAL)) == false) {

def Text = WebUI.getText(div_ErrorMessage)

println(Text)  

return null   

} else {

WebUI.click(findTestObject(‘button_Create’))

}

Hope this helps.

2 Likes