Issue with text verification on Safari

Hello Team,

I am facing an issue with text verification on Safari. I am trying to verify the text of a particular object and when I run it on Safari I am getting failure because of this reason :

TempTestSuite1566858141573.run(TempTestSuite1566858141573.groovy:35)
Caused by: com.kms.katalon.core.exception.StepFailedException: Actual text '
            Free Shipping Over $50.00


          ' and expected text 'Free Shipping Over $50.00' of test object 'Object Repository/Shipping_Method_Page/US_Shipping/New/Free_Shipping_Over_50' are NOT matched.
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementTextKeyword$_verifyElementText_closure1.doCall(VerifyElementTextKeyword.groovy:57)

The same test case works fine when I run the test on Chrome or Firefox.


2019-08-26 22:42:16 - [TEST_STEP][PASSED] - verifyElementText(findTestObject("Shipping_Method_Page/US_Shipping/New/Free_Shipping_Over_50"), "Free Shipping Over $50.00"): Actual text and expected text of test object 'Object Repository/Shipping_Method_Page/US_Shipping/New/Free_Shipping_Over_50' are matched.

The HTML does have blank space before and after the text. Katalon seems to be auto truncating the blank spaces for Chrome and Firefox but not for Safari

How should I fix this issue, Should I add a trim() before and after the text or should I add an if statement which says if browser Safari then trim()

This is the approach I tried and is working. But I am not sure if this is the correct way


WebUI.verifyElementPresent(findTestObject('Shipping_Method_Page/CA_Shipping/New/Free_Shipping_Over_50'), 0)
		
Free_Shipping_Over_50_Text = WebUI.getAttribute(findTestObject('Shipping_Method_Page/CA_Shipping/New/Free_Shipping_Over_50'), 'textContent', FailureHandling.STOP_ON_FAILURE).trim()
			
System.out.println(Free_Shipping_Over_50_Text)			

CustomKeywords.'kms.turing.katalon.plugins.assertj.StringAssert.equals'(Free_Shipping_Over_50_Text, 'Free Shipping Over $50.00', true, '', FailureHandling.STOP_ON_FAILURE)

It’s pragmatic. You gotta do what you gotta do.

I’m pretty sure, like me, you don’t believe that’s true even if it seems to be true. Out of interest, where was the Inspector screenshot taken? Chrome?

Also, reading the docs, verifyElementText does NOT say it’s checking for equivalence. It says

true if the element has the desired text, otherwise false

Which sounds like a regex text or “contains”. All of which implies you don’t (or shouldn’t) need trim

My advice: be pragmatic. Leave a comment in the code that you’re not happy with the line you’re taking and explain why.

2 Likes

Looking at the documentation for verifyElementText(), no trimming is done at all, just a String equals() comparison, as expected.

In reality, it does check for equivalence. I think the problem is with the documentation’s “broken” english (not terribly broken, but not perfect either).

I’m with Russ tho, be pragmatic. I would trim the text as well. Ultimately what you care about is what the user sees in the UI, which generally doesn’t include whitespace.

2 Likes

@Russ_Thomas @Brandon_Hein Thanks for your replies. I would go ahead with what I did and leave a comment in the code as well saying why I did it.

2 Likes