verifyElementText more accomodating

Hi,

I receive the following error which is correct because of a comma instead of a point.

Actual text ‘CHF 60,79’ and expected text ‘CHF 60.79’ of test object ‘Object Repository/page_checkout/_ayden/klarna_total2’ are NOT matched. (Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text ‘CHF 60,79’ and expected text ‘CHF 60.79’ of test object ‘Object Repository/page_checkout/_ayden/klarna_total2’ are NOT matched.

The check looks like this:

WebUI.verifyElementText(findTestObject('page_checkout/_ayden/klarna_total2'), GlobalVariable.cached_total, FailureHandling.CONTINUE_ON_FAILURE)

How can I tell the check that point or comma are not relevant on exact this place? On another place I still check if point or comma are used.

Regards

You can either take the Regular Expression route or figure out how to persuade the Java runtime to use a different culture (which I don’t know about).

@kazurayam @Brandon_Hein

thank you @Russ_Thomas

I am not sure how to handle this as I compare with a GlobalVariable I saved earlier in the test.

I found this…

Ok thanks. Will forward to a developer as I am only a QA manager.

You can also use an “or” inside your xpath. That’s what we do for English/French.

For example, English-speakers write

1,234,567.89

while Italian people write

1.234.567,89

How to handle different cultures of Decimal presentation in Java? See the section “Localized Formatting” of the following article:

IMHO, Locale-aware UI testing requires endless efforts. I would not like to dig into it.

1 Like

This doesn’t help in this case. the xpath isn’t a problem.

If you want to compare if the amount shown on your order confirmation matches the one on the thank you page and the payments provider page, than it’s necessary.

I somehow have to change the GlobalVariable validation in this step without changing and resaving the GlobalVariable itself. But I have no idea how. Also not if I see your guide (thank for that)

WebUI.verifyElementText(findTestObject('page_checkout/_ayden/klarna_total2'), GlobalVariable.cached_total, FailureHandling.CONTINUE_ON_FAILURE)

def x = GlobalVariable.thing
 x = // modify x

thank you.
you mean

` WebUI.delay(15, FailureHandling.CONTINUE_ON_FAILURE)

		def cached_total = GlobalVariable.cached_total
		cached_total =
		assertThat(new DecimalFormat("##,##",
			new DecimalFormatSymbols(Locale.ENGLISH)).format(d))
			.isEqualTo("12,34");
		
		WebUI.verifyElementText(findTestObject('page_checkout/_ayden/klarna_total2'), cached_total, FailureHandling.CONTINUE_ON_FAILURE)`

Test Cases/CC/Template Journeys/sc10h_john_doe_enters_payment_details_adyen_sofort FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: d for class: Script1588241735394
at sc10h_john_doe_enters_payment_details_adyen_sofort.run(sc10h_john_doe_enters_payment_details_adyen_sofort:133)
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.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:59)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.call(CallTestCaseKeyword.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.callTestCase(CallTestCaseKeyword.groovy:81)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.execute(CallTestCaseKeyword.groovy:44)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.keyword.BuiltinKeywords.callTestCase(BuiltinKeywords.groovy:334)
at payment_switch_login.run(payment_switch_login:147)
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.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:59)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.call(CallTestCaseKeyword.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.callTestCase(CallTestCaseKeyword.groovy:81)
at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.execute(CallTestCaseKeyword.groovy:44)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.keyword.BuiltinKeywords.callTestCase(BuiltinKeywords.groovy:334)
at Payment_Flow_Login.run(Payment_Flow_Login:42)
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:169)
at com.kms.katalon.core.main.TestSuiteExecutor.accessTestSuiteMainPhase(TestSuiteExecutor.java:142)
at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:91)
at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:157)
at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
at TempTestSuite1590671378170.run(TempTestSuite1590671378170.groovy:37)

it’s simply stopping there:

Katalon is having and issues figuring out what d is.

image

This line…

is saying you used d in your script (which is a Script Class) but did not declare/define it.

yes I took it from here https://www.baeldung.com/java-decimalformat

and am searching at the same time what this means and what I have to do with it.

A few points.

  1. It is a poor idea using GlobalVariable as container of your expected values, as you will soon feel like to check hundreds of items. You had better use external CSV file or Excel. You can read them using Data Binding feature of Katalon Studio. See https://docs.katalon.com/katalon-studio/docs/run-test-case-external-data.htm

  2. Comparing text-to-text (“60.79” to “60,79”) is not a good approach. The difference of ‘.’ and ‘,’ matters in text comparison, which is not really essential when you want to compare “values”. You should rather convert the data type: from a decimal Text in localised format into a Number. In Number comparison, the difference of ‘.’ and ‘,’ is not concerned at all, just the number values are compared. Once you get a pair of Numbers, then you can easily compare them using arithmetic operators: <,<=, ==, =>, >.

  3. Anyway you need to write some amount of Groovy code to convert a decimal text in localised format into a Number.

1 Like

Thank you @kazurayam

1.) I use up to 100 variables via Excel. But Global Variables are used to save values which I wrote dynamically in a test suite but which I have to transport from one test case to another.

2.) Also a good idea.

3.) In this case this is again the part where I will forward the topic to a developer :wink: