I have 2 global variables defined at Profiles “default” called:
SaverValue_1, value = 0
SaverValue_2, value = 0
And what I wish to do with them is to extract the value (which is a monetary number value, like 0.00) and do a simple sum up. So I have the following code which isn’t working…
what types those values are, String?
one way to do it
String strVal = “123.456”
String strVal2 = “321.654”
double dVal = Double.parseDouble(strVal);
double dVal2 = Double.parseDouble(strVal2);
double dVal3 = dVal + dVal2
import java.text.DecimalFormat;
DecimalFormat money = new DecimalFormat (“0.00”);
System.out.println(money.format(dVal3));
The goal here is to use global variables to save the content in Script 1, and then recall them (after the calculations part also in Script 1) to use for final total-type comparisons on Script 2 and 3, within the same project of course.
Thank you for asking this. I just had a minute to check this out, and apparently what happens is that it combines both strings together.
3.496.49
How can I appropriate fetch an element’s numeric content without using Get Text, or, how to convert String to Int within Katalon, and then do the mathematical operation?
There are two ways, you can create another GlobalVariable.dVal3 which stores the computation result, or you can use def dVal3 = WebUI.callTestCase('your test case ID')
Where your test case would be like:
// compute dVal3
return dVal3
Use global variables when you want test cases that are relatively independent of each other to read it. Return value from WebUI.callTestCase if you want to orchestrate a logic flow where one test case returns a value which to be used by another test case. Note that all of this coordination occurs in another test case which can be called a master test case that simply orchestrates the flow between test cases.