hi.
in katalon studio, i want to check A*B is C.
(A,B,C is get text)
What keywords should I use?
if statement ? verify equal? verify match?
hi.
in katalon studio, i want to check A*B is C.
(A,B,C is get text)
What keywords should I use?
if statement ? verify equal? verify match?
You should be able to use either of them:
WebUI.verifyEqual(actualObject, expectedObject)
WebUI.verifyMatch(actualObject, expectedObject, false)
You will have to remove the comma from the String text before you do your calculation though. That is likely the NumberFormatException you are getting.
// as a String
actualObject = actualObject.replace(",", "")
// as a Double or Number
WebUI.verifyEqual(nActualObject, nExpectedObject)
WebUI.verifyMatch(nActualObject, nExpectedObject, false)
Edit:
Just a note that with verifyEqual, it expects both parameters to be Objects. We had a discussion on this forum when comparing two Strings, which are Objects, that verifyEqual would fail the comparison if the Strings were declared as:
String actualObject
but would pass if the Strings were declared as:
def actualObject
So do the comparison with both of the parameters as Objects, like Double.
You should read the message carefully. Mind that you got an error
java.lang.NumberFormatException: For input string: "1,000.00000000"
To reproduce your problem, I wrote a Test Case:
String a = '1,000.00000000'
String b = '2.71828'
Double c = a.toDouble() * b.toDouble()
print(c)
When I run this, I got the following error:
2022-08-27 07:07:54.397 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/kwang2 FAILED.
Reason:
java.lang.NumberFormatException: For input string: "1,000.00000000"
at kwang2.run(kwang2:3)
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:445)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1661551670729.run(TempTestCase1661551670729.groovy:25)
2022-08-27 07:07:54.418 ERROR c.k.katalon.core.main.TestCaseExecutor - ❌ Test Cases/kwang2 FAILED.
Reason:
java.lang.NumberFormatException: For input string: "1,000.00000000"
at kwang2.run(kwang2:3)
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:445)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:436)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:415)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:407)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:284)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1661551670729.run(TempTestCase1661551670729.groovy:25)
The input string 1,000.00000000
contains a comma character ,
which causes a NumberFormatException
when you carelessly call a.toDouble()
.
To use verify equal or verify match? That is not the question you should ask.
How to parse a string with a comma character into a Double? The following code is an example.
import java.text.NumberFormat
NumberFormat format = NumberFormat.getInstance(Locale.US);
String a = '1,000.00000000'
String b = '2.71828'
Number number_a = format.parse(a)
Number number_b = format.parse(b)
Double c = number_a.doubleValue() * number_b.doubleValue()
println("c is " + c.toString())
There could be many other ways.
is there a way to codeless in katalon?
No. You need to study Java/Groovy programming to solve this problem. If you stay a Manual mode user, you can not solve it.
Thanks a lot