Unable to verify match for Regular Expression in WebUI.verifyMatch keyword


I try to check the last word in the string. Example of the string:
mat-row cdk-row pointer ng-star-inserted highlight

highlighted= WebUI.getAttribute(findTestObject('Smoke Test Objects/Fleet/ConstructionProject High Speed 2 - Phase I/Overview Tab S1274 in a list_hardcoded as the 2nd line'), 

WebUI.verifyMatch( highlighted, '.highlight$', true)

What I do wrong?
Thank you for your answers in advance!

Pls check if the below solution works for you.

String text= "mat-row cdk-row pointer ng-star-inserted highlight"
WebUI.verifyMatch( text, '.*highlight', true)

// OR

WebUI.verifyMatch( text, '.*highlight.*', true)

Quoting from the javadoc of java.util.regex.Matcher

A matcher is created from a pattern by invoking the pattern’s matcher method. Once created, a matcher can be used to perform three different kinds of match operations:

  • 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.

@yakovlieva.olena you are assuming that verifyMatch() internally uses the java.util.regex.Matcher#find method. But, in fact, WebUI.verifyMatch() keyword internally uses the Matcher#matches method. Therefore your '.highlight$' won’t work.

@discover.selenium — his '.*highlight' would work. The leading part .* will match and consume the "mat-row cdk-row pointer ng-star-inserted " portion.


yes, it works

1 Like