Problems verifying 'contains' text (substring, regex etc.)

I’m having difficulties trying to verify text content that ‘contains’ the text I’m trying to verify. I’ve tried various ‘substring’ and ‘regex’ solutions on this forum but nothing seems to work. For example…

Using substring, I’m trying to verify that the Priority field contains / ends with the word ‘(Critical)’. I see something like ‘Before 21/07/2020 16:34 (Critical)’ in the app. Here’s my script…

def Priority = Mobile.getText(findTestObject('Priority FIELD'), 0)

Priority = Priority.substring(result.length() - 10)

Mobile.verifyMatch(Priority, '(Critical)', false, FailureHandling.CONTINUE_ON_FAILURE)

The logs show the following:

Unable to verify match between actual text ‘Before 21/07/2020 16:34 (Critical)’ and expected text ‘(Critical)’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text ‘Before 21/07/2020 16:34 (Critical)’ and expected text ‘(Critical)’ are not matched

Any suggestions for how I can achieve this please? Thanks :slight_smile:

How about putting the whole into one statement and comparing via REGEX like below?

Mobile.verifyMatch(Mobile.getText(findTestObject('Priority FIELD'), 0), '.*\\(Critical\\)', true, FailureHandling.CONTINUE_ON_FAILURE)

OR

Mobile.verifyMatch(Mobile.getText(findTestObject('Priority FIELD'), 0), '.*\\(Critical\\).*', true, FailureHandling.CONTINUE_ON_FAILURE)

The difference between the two statements is whether there are any characters that cannot be seen after the last parenthesis in the phrase.

1 Like

This is awesome - thank you so much, it worked straight away :smiley: