How to obtain element monetary value onto variable, and calculate it among variables?

Good afternoon,

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…

GlobalVariable.SaverValue_1 = WebUI.getText(findTestObject('Basic_Objects_1/td_349'))
GlobalVariable.SaverValue_2 = WebUI.getText(findTestObject('Basic_Objects_1/td_649'))
WebUI.comment(GlobalVariable.SaverValue_1 + GlobalVariable.SaverValue_2)

What am I doing wrong?


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”);

print out

They are monetary numbers, like “100.00”

Hi @leandro.rodeia

Please give us the screenshot of the profile where you declare the variables.

There you go @ThanhTo

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.

Hi @leandro.rodeia

You mentioned

What exactly wasn’t working. Please give us the console log when you execute this script.

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.


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?

So this can be done by using what @Timo_Kuisma suggested. Copy and paste this to your script

Press Ctrl + Shift + O to import the necessary import statements.

I see, thank you.

Considering I use that solution, how can I apply it in a global way so I can also use the final output variable of “dVal3” on other scripts aswell?

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.

Perfect, this is exactly what I wanted.

Thank you very much.

1 Like