Default keywords related to element checks e.g. verifyElementPresent , returns exception instead of boolean false


#1

Commands like verifyElementVisible, verifyElementNotVisible, verifyElementPresent, verifyElementNotPresent, verifyElementHasAttribute, etc. returns an exceptions instead of boolean false if the condition fails.

All these commands are marked with return type as boolean, however, there is no proper handling to it and throws exception if condition fails.

As a workaround, I am using it like below , bu this is not an optimal solution as you end up with unwanted warnings in the console logs.
if (WebUI.verifyElementNotPresent(findTestObject(‘ab/xyz/rrr’),10,FailureHandling.OPTIONAL)


#2

Hello,

you’re true, currently there’s no way how to do it without warnings. If you don’t like it, you can write your own method for presence validation.

def boolean isElementPresent(TestObject to) {
	try {
		WebUiCommonHelper.findWebElement(to, 1)
	} catch (WebElementNotFoundException ex) {
		return false
	}
	return true
}

And call this one instead of native WebUI keywords.


#3

Thanks, will check on this one.

But with this solution, I will end up creating hell lot of custom methods corresponding to different verify… methods which I will consume.


#4

True. And I’m sorry I can’t help you better now.

You can create a feature request to introduce new FailureHandling value, which won’t write anything into logs and it just returns boolean value.


#5

Hey, Thanks for the help and don’t be sorry. Appreciate your help here.

I really cannot categorize this as a new feature for Katalon team, its a defect in existing code itself that should get fixed in the product. I am not sure if a defect is already logged for this or not.


#6

I’d say it’s more like non-existing feature - I also use FailureHandling.OPTIONAL for preventing exceptions, but I don’t care about warnings - but I agree, it may be annoying.

@devalex88 @ThanhTo Guys, could you create this feature request and prioritize it in your project? Thank you!


#7

Thank you all for the report. The behavior will be corrected in Katalon Studio 6.4.0.


#8

Awesome. Thanks much for the update !!


#9

Hi everyone,

In Katalon Studio 7.0.0, we have already fixed the bug that caused the verifyElementPresent() and verifyElementNotPresent() keywords to throw an exception instead of returning false when the verified elements do not exist.

Please first check out the release note and click here to download if you want to try version 7.0.0 (beta) in advance.

Happy Testing!

Jass


#10

Thanks Jass for the fix and update.

Wanted to know if the fix is limited to verifyElementPresent() & verifyElementNotPresent() only , or its applicable to other verify functions too ?

I believe its important to have this behavior consistent across other verifyElement*** keywords too.


#11

It’s only for the two keywords. Other keywords still require that the elements exist. You can combine them with verifyElementPresent() and verifyElementNotPresent().


#12

What if there is need to check :

  1. if element has/not has the given attribute
  2. if element visible/not visible
  3. if element checked/not checked
  4. etc.

The workaround you suggested to use verifyElementPresent/verifyElementNotPresent , won’t work here :(.

Regards,
Madhav