TestObject text begins with - not working

Hey,

I’m trying to make sure the text of a TestObject I’m grabbing begins with a string I expect to be there. In this case, it’s today’s date. Here’s the relevant code snippet:

createdAtStr = WebUI.getText(findTestObject('My first row'))
mydate = new Date()
formattedDate = mydate.format('yyyy-MM-dd')
WebUI.verifyMatch(createdAtStr, formattedDate, true, FailureHandling.STOP_ON_FAILURE)

The object (My first row) DOES contain the string in the exact format I’m looking for (2018-07-10) but I’m still getting this failure:

[FAILED] - Unable to verify match between actual text ‘2018-07-10 13:49:47’ and expected text ‘2018-07-10’ using regular expression (Root cause: Actual text ‘2018-07-10 13:49:47’ and expected text ‘2018-07-10’ are not matched using regular expression)

Meaning I did create today’s date in the format I expected it to be, I did get the string containing this date out of the row, but I still can’t match them.

I’m assuming I need to use isRegex (hence the ‘true’) as I’m trying to match this with the beginning of the string.

**What am I doing wrong? **

Thanks.

1 Like

Try using real Regex:
formattedDate = ‘^’ + mydate.format(‘yyyy-MM-dd’) + ‘.*’

1 Like

from description:

Verify if two strings match each other, the second string can be a regular
expression.

so probably can be something like this?:

WebUI.verifyMatch(formattedDate, createdAtStr+" .*",  true)

but what i like is to prepare object wih parameter where i left to browser to find it using xpath functions like start-with() and then in script i’m using verifyElementPresent(TO_with_my_search_xpath)

1 Like

Thanks for the quick response Gerard and Andrej, it’s working now.
For some reason I thought placing just a string will do and Katalon/Groovy will take care of the rest as long as I mark it as a regex, which is - come to think of it - a wrong assumption as there are obviously different kinds of regex and we need to specify which kind of regex we’re looking for.

Thanks a lot, guys.

1 Like

Er Bear said:

Thanks for the quick response Gerard and Andrej, it’s working now.
For some reason I thought placing just a string will do and Katalon/Groovy will take care of the rest as long as I mark it as a regex, which is - come to think of it - a wrong assumption as there are obviously different kinds of regex and we need to specify which kind of regex we’re looking for.

Thanks a lot, guys.

Hi. How did you solve this problem? Can you show code? I have same problem

WebUI.verifyMatch is a pitfall. Have a look at the following previous discussion

http://forum.katalon.com/discussion/comment/14639

I would repeat the explanation here:
--------------------------------------------------------

java.util.regex.Matcher (https://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html) implements 3 methods:

  • The matches method attempts to match the entire input sequence against the pattern.

  • The lookingAt method attempts to match the input sequence, starting at the beginning, against the pattern.

  • The find method scans the input sequence looking for the next subsequence that matches the pattern.

I suppose that Katalon’s verifyMatch uses the Matcher.matches() method which requires entire match. I tried the following test case:

WebUI.openBrowser('')
WebUI.navigateToUrl('http://demoaut.katalon.com/')
def text = WebUI.getText(findTestObject('Page_CURA Healthcare Service/a_Make Appointment'))
WebUI.comment("text=\"${text}\"")
WebUI.verifyMatch(text, 'Make Appointment', true)
WebUI.verifyMatch(text, '.*ment$', true)
WebUI.verifyNotMatch(text, 'ment$', true)
WebUI.verifyMatch(text, '^M.*', true)
WebUI.verifyNotMatch(text, '^M', true)
WebUI.verifyMatch(text, '.*', true)
WebUI.closeBrowser()

All of the invocations of verifyMatch and verifyNotMatch succeeded as I expected. This proves that verifyMatch uses the matches method

Many people expect WebUI.verifyMatch command uses Matcher.find() method, which is not the case actually. So they get confused and start complaining “WebUI.verifyMatch() does not work for me!”

# Solution

Beware, WebUI.verifyMatch requires attempts to match the entire input sequence against the pattern.

1 Like

@Katalon Team

The documentation of VerifyMatch is poor (https://docs.katalon.com/display/KD/%5BCommon%5D+Verify+Match)
Improvement required.

It should state that it requires entire match.

It should explain how to solve the above-mentioned case:

[FAILED] - Unable to verify match between actual text ‘2018-07-10 13:49:47’ and expected text ‘2018-07-10’ using regular expression (Root cause: Actual text ‘2018-07-10 13:49:47’ and expected text ‘2018-07-10’ are not matched using regular expression)

1 Like

kazurayam

Thank you so much! You safe my time.

def String FullTranNo = WebUI.getText(findTestObject('OPAL/BO/ModifyTransfer_page/Transaction_LastNo'))WebUI.verifyMatch(FullTranNo, GlobalVariable.TransNo1+".*", true)

This is my example with Global Variable