Question about Testing Page Titles with Non Printable Characters

Randy, (and @ThanhTo), I think I have a solution that satisfies us all.

It turns out that the DOM API document.title also 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)).

image

So, Randy, get your window title in JS and do a NON-regex comparison. Here is the barebones Groovy/JS:

(CORRECTED)

String domTitle = WebUI.executeJavaScript("return document.title;", null)
assert WebUI.verifyMatch(domTitle, 'Residents', false)
2 Likes

No, I am not satisfied.

Randy wrote that his code

WebUI.verifyMatch(WebUI.getWindowTitle(), ".*" + Test_Page_Title + ".*", true)

failed. Why? It is still not clear.

Two things:

I believe Randy’s initial topic now has an answer.

I believe your solution from a few years ago (linked above) answers your question.

Well, I want to hear from @Randy if his problem has been solved or not.

Hi Kazurayam,

I wanted to answer your question. The ‘Residents’ Regex solution is still not working when input is from a file.

I deployed your suggested code and below is the output:

2020-08-24 13:48:28.556 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/2. 
Content Tests/2. Crawl Torontohousing Site Map - File
2020-08-24 13:48:28.558 INFO  c.k.katalon.core.main.TestCaseExecutor   - Test_Page_URL =             
https://www.torontohousing.ca/residents
2020-08-24 13:48:28.558 INFO  c.k.katalon.core.main.TestCaseExecutor   - Test_Page_Title = 
Resident​​s
2020-08-24 13:48:28.558 INFO  c.k.katalon.core.main.TestCaseExecutor   - Test_Page_Content = If 
you\'re having trouble finding the information you\'re looking for, email 
webmaster@torontohousing.ca or call the Client Care Centre at 416-981-5500.​
2020-08-24 13:48:28.558 INFO  c.k.katalon.core.main.TestCaseExecutor   - Test_Page_Breadcrumb 
= Home > Residents
2020-08-24 13:48:28.573 INFO  c.k.katalon.core.main.TestCaseExecutor   - (Default) 
Test_Page_Layout = 
2020-08-24 13:48:28.605 INFO  c.k.katalon.core.main.TestCaseExecutor   - (Default) reTitle = 
2020-08-24 13:48:28.612 DEBUG .2. Crawl Torontohousing Site Map - File - 1: "Test all URL from 
the 'TorontoHousing-Site-Map-Content.xlsx' file"
2020-08-24 13:48:28.613 DEBUG .2. Crawl Torontohousing Site Map - File - 2: enableSmartWait()
2020-08-24 13:48:28.619 DEBUG .2. Crawl Torontohousing Site Map - File - 3: openBrowser("")
2020-08-24 13:48:28.619 INFO  c.k.k.core.webui.driver.DriverFactory    - Starting 'Chrome' driver
Aug 24, 2020 1:48:28 PM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
2020-08-24 13:48:28.629 INFO  c.k.k.core.webui.driver.DriverFactory    - Action delay is set to 0 
milliseconds
Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch- 
heads/4103@{#416}) on port 21046
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping 
ChromeDriver safe.
ChromeDriver was started successfully.
Aug 24, 2020 1:48:29 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
2020-08-24 13:48:29.679 INFO  c.k.k.core.webui.driver.DriverFactory    - sessionId =         
11402a8f456c4eafff927c5c7133c25c
2020-08-24 13:48:29.692 INFO  c.k.k.core.webui.driver.DriverFactory    - browser = Chrome 
83.0.4103.61
2020-08-24 13:48:29.693 INFO  c.k.k.core.webui.driver.DriverFactory    - platform = Windows 10
2020-08-24 13:48:29.693 INFO  c.k.k.core.webui.driver.DriverFactory    - seleniumVersion = 
3.141.59
2020-08-24 13:48:29.694 INFO  c.k.k.core.webui.driver.DriverFactory    - proxyInformation = 
ProxyInformation { proxyOption=MANUAL_CONFIG, proxyServerType=HTTP, username=, 
password=********, proxyServerAddress=httpproxy.torontohousing.ca, proxyServerPort=8888, 
executionList="", isApplyToDesiredCapabilities=true }
2020-08-24 13:48:29.703 DEBUG .2. Crawl Torontohousing Site Map - File - 4: maximizeWindow()
2020-08-24 13:48:29.853 DEBUG .2. Crawl Torontohousing Site Map - File - 5: 
navigateToUrl(Test_Page_URL)
2020-08-24 13:48:32.369 DEBUG .2. Crawl Torontohousing Site Map - File - 6: 
delay(G_Page_Load)
2020-08-24 13:48:37.372 DEBUG .2. Crawl Torontohousing Site Map - File - 7: if 
(Test_Page_Layout == "Parent")
2020-08-24 13:48:37.373 DEBUG .2. Crawl Torontohousing Site Map - File - 8: else if 
(Test_Page_Layout == "1-Pane")
2020-08-24 13:48:37.373 DEBUG .2. Crawl Torontohousing Site Map - File - 9: else if 
(Test_Page_Layout == "2-Pane")
2020-08-24 13:48:37.374 DEBUG .2. Crawl Torontohousing Site Map - File - 10: else
2020-08-24 13:48:37.374 DEBUG .2. Crawl Torontohousing Site Map - File - 1: "Take a screen shot 
of the Webpage after it loads before the tests"
2020-08-24 13:48:37.375 DEBUG .2. Crawl Torontohousing Site Map - File - 2: assert getUrl() == 
Test_Page_URL
2020-08-24 13:48:37.391 DEBUG .2. Crawl Torontohousing Site Map - File - 3: println(">>>" + 
Test_Page_Title + "<<<")
>>>Resident​​s<<<
2020-08-24 13:48:37.392 DEBUG .2. Crawl Torontohousing Site Map - File - 4: reTitle = ".*" + 
Test_Page_Title + ".*"
2020-08-24 13:48:37.393 DEBUG .2. Crawl Torontohousing Site Map - File - 5: 
verifyMatch(getWindowTitle(), reTitle, true)
2020-08-24 13:48:37.424 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ Unable to verify 
match between actual text 'Residents' and expected text '.*Resident​​s.*' using regular expression 
(Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text 'Residents' and 
expected text '.*Resident​​s.*' are not matched using regular expression

Hi Russ,

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:

My bad. I missed out a comma - I corrected my original code.

Hi Russ,

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: >>>Resident​​s<<<
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 'Resident​​s' (Root cause: 
com.kms.katalon.core.exception.StepFailedException: Actual text 'Residents' and expected text 
'Resident​​s' are not matched

weird.

What does WebUI.verifyEqual() produce?

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.

This also failed.

Change in the Code:
WebUI.verifyequal(Test_DOM_Title, Test_Page_Title)

Output from the Katalon Console:

08-24-2020 03:10:21 PM Test Cases/2. Content Tests/2. Crawl Torontohousing Site Map - File

Elapsed time: 9.331s

Test Cases/2. Content Tests/2. Crawl Torontohousing Site Map - File FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyequal() is applicable for argument types: (java.lang.String, java.lang.String) values: [Residents, Resident​​s]
Possible solutions: verifyEqual(java.lang.Object, java.lang.Object), verifyEqual(java.lang.Object, java.lang.Object, com.kms.katalon.core.model.FailureHandling)

@Randy.Ramkissoon Just a note that verifyEqual expects to have two Objects. You should use verifyMatch(str1, str2, boolean) like:

WebUI.verifyMatch(Test_DOM_Title, Test_Page_Title, false)

Groovy Strings are Objects.

He did. Read the thread please.

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) :slight_smile:

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 :wink: 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?

def s1 = "russ", s2 = s1

assert WebUI.verifyEqual(s1, s2) // true

assert WebUI.verifyEqual("russ", "russ") // bang

Oh well, we live and learn (hopefully). Fact is though, I never assert so it’s a lesson I’ll likely forget :confused:

1 Like

@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?

@Randy.Ramkissoon

Could you make a zip file of your project and share it to us?
We need to reproduce the problem on our own PC.

On my side using 7.6, this test passes:

Am I doing something differently ?

No, that looks fine to me. My code definitely went bang right where I left the comment. I just reran it and it’s fine.

I’m ducking out now - I’m too confused by this to offer anything but more confusion :blush: :angry:

@kazurayam @ThanhTo @Russ_Thomas

Good Morning All,

Thanks for your feedback. The main item I can see which is missed is:

  • The several examples all use test data directly inputed in the test case (this has always worked).
  • Where we have been failing is when reading the data from the Excel (which I had attached earlier).

Each time we call a compare function to compare:

  • assert WebUI.getWindowTitle() == Test_Page_Title
  • Test_Page_Title = “." + Test_Page_Title + ".
  • assert WebUI.verifyMatch (WebUI.getWindowTitle() “.” + Test_Page_Title + ".", true)
  • assert WebUI.verifyMatch(Test_DOM_Title, Test_Page_Title, false)
  • String Test_DOM_Title = WebUI.executeJavaScript(“return document.title;”, null)
    assert WebUI.verifyMatch(Test_DOM_Title, Test_Page_Title, false)

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 ‘Resident​​s’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text ‘Residents’ and expected text ‘Resident​​s’ 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.

Can’t wait to hear about your observations. Thank you.

torontohousing-ca-forum.zip (2.2 MB)