Verify Text Present not verifying text that is present

Hi,
I am writing an assertion that the string amount is the same on two different pages. I took the payment amount string from one page (below) and I stored it in a variable like this:

money = WebUI.getText(findTestObject('RCGP_Portal/RCGP_Exams_Page/Training_Tab/My_RCGP_Exam_Page/ExaminationFee'))

Page 1:image

Then I want the test to check that the text from the variable is found anywhere on this page, and I did it this way:

WebUI.verifyTextPresent(money, false)

Page 2: image

However the test fails and is giving me this error: Caused by: com.kms.katalon.core.exception.StepFailedException: Text '£1050.0' is not present on page

I think this might be because of the formatting as there is a comma on the second amount, but should it matter if I used ‘VerifyTextPresent’, as the text is still all there on the page but just with a comma?

TLDR: Script fails as it can’t find £1050 on a page even though the text is present

Thanks!

Yes. A comma here matters very much.

£1050.00 and £1,050.0 — these 2 texts are NOT identical due to a comma. It is totally valid that WebUI.verifyTextPresent() throws an Exception.

If you want your test to pass, then you need to make 2 texts comparable.

Possibly you have to extract texts from web pages and format them before making any verification. So you can not rely on the WebUI.verifyTextPresent() keyword.

For example:

assert '£1,050.00'.replaceAll(',', '') == '£1050.00'

Comparing Monetary values can be complicated and often require some efforts. For example,

  • verify if 1050, 1050.0 and 1050.00 — are these values equal as monetary values?
  • verify if 1050 and £1050 are equal as monetary values?
  • verify if 1,050 and 1050 are equal?

Just for your interest, Java Money and the Currency API forcuses on these problems. But it might be too much for you.

Thank you, I’ve added a line of code that replaces the string with the one I need.