Randy, (and @ThanhTo), I think I have a solution that satisfies us all.
It turns out that the DOM API document.titlealso trims the source. Both Katalon and Firefox can be forgiven (although I would expect WebUI.getWindowTitle() to do what it says - but it may be limited to DOM functionality (a reality)).
So, Randy, get your window title in JS and do a NON-regex comparison. Here is the barebones Groovy/JS:
I’m trying to implement your suggestion now, just got the following error around the ‘null’ text. I wanted you to see it while I read through the Katalon documentation to make sure I implemented it correctly:
I changed the code to as follow and included tracing PRINTLN lines to share my output when the fail happened.
Sample Code I used:
String Test_DOM_Title = WebUI.executeJavaScript("return document.title;", null)
println ("This is the Test_DOM_Title value: " + ">>>" + Test_DOM_Title + "<<<")
'Get the value of the Test_Page_Title before any manipulation'
println ("This is the page title being tested: " + ">>>" + Test_Page_Title + "<<<")
'Check that the Test Page Title matches the expected result'
assert WebUI.verifyMatch(Test_DOM_Title, Test_Page_Title, false)
Failing Output from console comparing the value ‘Residents’ as the page title:
2020-08-24 14:47:29.097 DEBUG .2. Crawl Torontohousing Site Map - File - 4: Test_DOM_Title =
executeJavaScript("return document.title;", null)
2020-08-24 14:47:29.114 DEBUG .2. Crawl Torontohousing Site Map - File - 5: println("This is the
Test_DOM_Title value: " + ">>>" + Test_DOM_Title + "<<<")
This is the Test_DOM_Title value: >>>Residents<<<
2020-08-24 14:47:29.115 DEBUG .2. Crawl Torontohousing Site Map - File - 6: println("This is the page
title being tested: " + ">>>" + Test_Page_Title + "<<<")
This is the page title being tested: >>>Residents<<<
2020-08-24 14:47:29.116 DEBUG .2. Crawl Torontohousing Site Map - File - 7: assert
verifyMatch(Test_DOM_Title, Test_Page_Title, false)
2020-08-24 14:47:29.132 ERROR c.k.k.core.keyword.internal.KeywordMain - ❌ Unable to verify
match between actual text 'Residents' and expected text 'Residents' (Root cause:
com.kms.katalon.core.exception.StepFailedException: Actual text 'Residents' and expected text
'Residents' are not matched
Do you have NotePad++ or BeyondCompare on your computer (or other software for analysis and comparing)? NotePad++ will be able to show any unprintable symbols of the text and BeyondCompare can compare the two text for unprintable characters that may be the difference that we cannot see visually.
Sorry Russ, but I have never been able to use Strings with verifyEqual. So, I have since used verifyMatch. And, Randy’s error message would agree with me that KS does not treat Strings as Objects (and Yes, I know they should be)
And, the comparison should be false, not true as Randy has used above unless there are some regEx aspect to be done for the comparison.
Sorry, Mike I usually “def” stuff so I didn’t see the error. I tried straight “strings” and you’re right, it really does want Objects which is really dumb. String is an object, right?
@ThanhTo Where we are right now is confusing to me and I suspect everyone reading this thread. Apart from the foibles of Strings/Objects, you can see in Randy’s last post he should be getting a match. Any ideas what is going on?
It seems there is something left in the Page Title which is not matching what is recorded and a failure was reported that the two string did not match.
Error in Console:
Unable to verify match between actual text ‘Residents’ and expected text ‘Residents’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text ‘Residents’ and expected text ‘Residents’ are not matched
The attached project has the data file I used where you will see some web page titles pass(8 of 12). The test data line referencing the web page “Residents” is the one we have all been troubleshooting.