VerifyTextPresent using OR logic

Is it possible to add some OR logic to a verifytextpresent check?

I need to know if a web page has certain text on it but sometimes it can be with spaces, sometimes it’ll be without spaces, so I want to check if one or the other is present.

For example, verifyTextPresent(‘01234 567890’) OR (‘01234567890’)

I’ve tried various methods but keep getting errors.

You can link two verifications:

assert WebUI.verifyTextPresent('01234 567890') || WebUI.verifyTextPresent('01234567890')

Thank you Mate Mrse

Unfortunately I’m new to Katalon so I may not be entering it correctly and got an error.

I’ve got the statement as follows:

assert WebUI.verifyTextPresent('03332124617') || WebUI.verifyTextPresent('0333 212 4617')

But when I run the test I get the following error:

Test Cases/TandCs UK CoverSheet FAILED because (of) groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyTextPresent() is applicable for argument types: (java.lang.String) values: [03332124617]
Possible solutions: verifyTextPresent(java.lang.String, boolean), verifyTextPresent(java.lang.String, boolean, com.kms.katalon.core.model.FailureHandling), verifyAlertPresent(int), verifyTextNotPresent(java.lang.String, boolean), verifyAlertPresent(int, com.kms.katalon.core.model.FailureHandling), verifyTextNotPresent(java.lang.String, boolean, com.kms.katalon.core.model.FailureHandling)

Hi Simon,

to make the solution more robust, you can use regex - to match 0 or more whitespaces after every character in your original string. For example:

String s = "test12345"String[] charray = s.split("(?!^)")String regex = ""for(int i = 0; i < charray.length; i++) {	regex += charray[i] + "\\s*"}WebUI.verifyTextPresent(s, true)

In this case, verifyTextPresent returns true in all of those cases:
- te st12345
- t e s t 1 2 3 4 5
- test 12345
- te st 12 345

By the way, Mate’s code is failing because of invalid number of parameters in method call - you have to specify true/false for isRegex in the method.

As Marek noticed, there is a parameter missing:

assert WebUI.verifyTextPresent('03332124617', false) || WebUI.verifyTextPresent('0333 212 4617', false)
(if you are using regex, as in the above example, set it to 'true')

Great, thank you both, really appreciate the help :slight_smile:

Hopefully someone can help me. I am trying to do something similar, but my “OR” statement does seem to work.

This is my line of code that is giving me problems

assert WebUI.verifyTextPresent(today , false) || WebUI.verifyTextPresent(yesterday, false)

This is the code where I define today and yesterday.

mydate = new Date()
String today = mydate.format("MM/dd/yyyy")
mydate2 = new Date()
mydate2 = mydate2.previous()
String yesterday = mydate2.format("MM/dd/yyyy")

Right now the test will pass, but if swap the today and yesterday variable it fails.

Any assistance would be appreciated

Hi Reece,

your test fails because WebUI.verifyTextPresent throws StepFailedException when text is not found. And when you switch today and yesterday (given that today is present and yesterday is not), only first verifyTextPresent method is executed and exception is thrown immediately (second method is not even called).

To prevent this exception, add FailureHandling.OPTIONAL as third parameter for a method. It throws only a warning and continues with script execution.

assert WebUI.verifyTextPresent(today , false, FailureHandling.OPTIONAL) || WebUI.verifyTextPresent(yesterday, false, FailureHandling.OPTIONAL)

1 Like

Marek Melocik said:

Hi Reece,

your test fails because WebUI.verifyTextPresent throws StepFailedException when text is not found. And when you switch today and yesterday (given that today is present and yesterday is not), only first verifyTextPresent method is executed and exception is thrown immediately (second method is not even called).

To prevent this exception, add FailureHandling.OPTIONAL as third parameter for a method. It throws only a warning and continues with script execution.

assert WebUI.verifyTextPresent(today , false, FailureHandling.OPTIONAL) || WebUI.verifyTextPresent(yesterday, false, FailureHandling.OPTIONAL)

  

Thank you this worked.

i have to check word “trial” present in webpage or not. when i use verifytextpresent keyword, the test passes even when “trial” is not present but “trial2” or “Trial” etc is present in webpage. please help me how to add regex in verifytextpresent for the word “trial”. thanks in advance.