Script working fine on MAC Chrome headless but throwing error on Linux Chrome headless

Hello Team,

I am trying to run a script on Jenkins box on Linux. The script I have created is working fine on my local machine in Chrome headless but the same throws java.number.format exception on Jenkins box.

The script fails at this step :

cip_product_price = WebUI.getText(findTestObject('Customer_Information_Page/Product_Price')).replace('$', '')

Please post the error.

The error is :

Reason:
java.lang.NumberFormatException
	at Jenkins - Web Test.run(Jenkins - Web Test:453)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:133)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:116)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:83)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1562354754411.run(TempTestSuite1562354754411.groovy:35)

This happens when I run on Jenkins but works fine on my machine

What happens when you try a regex?

 ... .replace(/\$/, '')

The error is still same

2019-07-05 20:09:03.874 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/Jenkins - Website Sanity/Jenkins - Web Test FAILED.
Reason:
java.lang.NumberFormatException
	at Jenkins - Web Test.run(Jenkins - Web Test:455)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:133)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:116)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:83)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1562357253506.run(TempTestSuite1562357253506.groovy:35)

Are you certain the script line you posted is the line that causes the error?

The issue is getting caused by that line and it is causing the conversion to BigDecimal fail.

2019-07-05 20:09:03.834 DEBUG testcase.Jenkins - Web Test              - 147: cip_product_price = getText(findTestObject("Customer_Information_Page/Product_Price")).replace("\$", "")
2019-07-05 20:09:03.872 DEBUG testcase.Jenkins - Web Test              - 148: println("The cip_product_price is    : " + cip_product_price)
The cip_product_price is    : 
2019-07-05 20:09:03.872 DEBUG testcase.Jenkins - Web Test              - 149: cip_product_price_1 = new java.math.BigDecimal(cip_product_price)
2019-07-05 20:09:03.889 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/Jenkins - Website Sanity/Jenkins - Web Test
2019-07-05 20:09:04.239 INFO  com.kms.katalon.core.util.KeywordUtil    - Start generating HTML report folder at: /var/lib/jenkins/workspace/US Website - Katalon Test/Reports/Jenkins/20190705_200733...

The code line I published in my 1st post is basically not getting any text. The text it is getting is blank. The log shows blank info when I printed it

The code is :


cip_product_price = WebUI.getText(findTestObject('Customer_Information_Page/Product_Price')).replace(/\$/, '')

WebUI.println('The cip_product_price is    : ' + cip_product_price)

/* Converting the value of cip_product_price_1 to BigDecimal ' */

BigDecimal cip_product_price_1 = new BigDecimal(cip_product_price)

assert cip_product_price_1.equals(expected_total_item_wise_after_decrement)

WebUI.println('The Item Price on the Customer Information Page is  : ' + cip_product_price_1)

Okay, so based on that, first you need to prove that findTestObject is working. Does this line complete successfully?

WebUI.waitForElementVisible(findTestObject("Customer_Information_Page/Product_Price"), 10)

If it does, I think I’d try getting the text via JavaScript…

1 Like

You are absolutely right, This WaitforElementVisible command failed. But it doesn’t seem to be any issue with the selector. I posted the Selector and HTML in 1st post. Can you please look and see if I am doing anything wrong.

Throw this at the browser console:

document.querySelector("td.product__price>span.order-summary__emphasis").innerText.replace("$","")

If that works, edit your properties to use this CSS selector:

td.product__price>span.order-summary__emphasis

It is returning correct value on Console but when I update properties to use the CSS selector it is throwing an error.

Error :


2019-07-05 20:55:36.827 WARN  k.k.c.w.k.b.WaitForElementVisibleKeyword - Object 'Object Repository/Customer_Information_Page/Product_Price' is not visible after 10 second(s)
2019-07-05 20:55:36.875 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/Jenkins - Website Sanity/Jenkins - Web Test FAILED.
Reason:
java.lang.NumberFormatException
	at Jenkins - Web Test.run(Jenkins - Web Test:457)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:133)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:116)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:83)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1562360032525.run(TempTestSuite1562360032525.groovy:35)

TestObjects are a pain…

String js = "return document.querySelector('td.product__price>span.order-summary__emphasis').innerText.replace('$','');"
String price = WebUI.executeJavaScript(js, null)
BigDecimal cip_product_price_1 = new BigDecimal(price) 

// ...

The issue is still there.

I updated the code based on the code you provided.


String js = "return document.querySelector('td.product__price>span.order-summary__emphasis').innerText.replace('${}', '');"

String cip_product_price = WebUI.executeJavaScript(js, null)

WebUI.println('The cip_product_price is    : ' + cip_product_price)

BigDecimal cip_product_price_1 = new BigDecimal(cip_product_price)


2019-07-05 21:21:51.612 WARN  k.k.c.w.k.b.WaitForElementVisibleKeyword - Object 'Object Repository/Customer_Information_Page/Product_Price' is not visible after 10 second(s)
2019-07-05 21:21:51.636 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/Jenkins - Website Sanity/Jenkins - Web Test FAILED.
Reason:
java.lang.NumberFormatException
	at Jenkins - Web Test.run(Jenkins - Web Test:451)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestCaseMainPhase(TestSuiteExecutor.java:133)
	at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:116)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:83)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1562361607453.run(TempTestSuite1562361607453.groovy:35)

Did you ensure that element was “ready” before accessing it? You don’t necessarily need to target it specifically, you could try waiting for something else on the page (preferably further down the hierarchy).

Does this code work in the working system? (You should be checking that as we move forward).

I’m also wondering if we followed a false trail here - it’s hard for me to tell from here.

Try this…

WebUI.delay(5)
String js = "return document.querySelector('td.product__price>span.order-summary__emphasis').innerText.replace('${}', '');" 

//...

If that fails… something else is screwy…

Thanks @Russ_Thomas I was also trying by adding delay. I will try to work on this but I can comment out this part of code for now and let the remaining verifications run.

Thanks for you help again.

1 Like

@Russ_Thomas One question for you. Do you think if the Maximize Browser statement ( WebUI.maximizeWindow() )will work differently on Chrome Headless on Mac and Chrome Headless on Linux ?

I was looking at the screenshots taken by Katalon while executing the same test on Chrome Headless Linux and noticed that the Browser is not actually fully opened but I have the command in code and it works fine on Chrome Headless on Mac

Maximize means only one thing: maximize the browser to the size of the display wherein lies the top/left coordinate of the browser window.[1]

That’s it. If you have evidence of it behaving differently, you have found a bug (in the webdriver).

But to answer your question, no, I don’t test on Linux, or Mac. And I rarely test on Chrome. Even so, I stand by my statement in italics above.


[1] You can test this yourself. Move the browser window to another screen using driver.manage().window().setPosition(new Point(x, y)) and then maximize it.

1 Like

@Russ_Thomas Thanks, I was able to fix the issue of resolution using Set view port size.

1 Like