TestProject Forum
Powered by leading experts in the test automation community

Evaluate mathematical expression

Is it possible to get 2 decimal place result?
I tried Evaluate mathematical expression but it returns a whole number result

Round((200000.01 + 580359.05),2) result = 780359

Expected result 780359.06

Hello,
Please consider using the Execute JavaScript action with the following script:
var x = 200000.01;
var y = 580359.05;
var z = Number(x) + Number(y);
return z;​
This will sum your numbers and keep the decimal, you can also replace the numbers in the script with parameters from your test if you want to make this dynamic.

Is Execute JavaScript action for web application only? Im testing a mobile application and No Execute JavaScript option in Actions menu

Yes, JavaScript is for web only.

For a solution, I can suggest creating a generic addon for yourself that will add the two numbers and with decimal points.

Create a new Java project using the SDK:

And use the following code:

import io.testproject.java.annotations.v2.Action;
import io.testproject.java.annotations.v2.Parameter;
import io.testproject.java.enums.ParameterDirection;
import io.testproject.java.sdk.v2.addons.GenericAction;
import io.testproject.java.sdk.v2.addons.helpers.AddonHelper;
import io.testproject.java.sdk.v2.enums.ExecutionResult;
import io.testproject.java.sdk.v2.exceptions.FailureException;
import io.testproject.java.sdk.v2.reporters.ActionReporter;

@Action(name = “Add”, description = “Add two numbers.”)
public class AddAction implements GenericAction{

@Parameter(description = "First input value")
public double inputOne;

@Parameter(description = "Second input value")
public double inputTwo;

@Parameter(description = "Output value", direction = ParameterDirection.OUTPUT)
public double output;

@Override
public ExecutionResult execute(AddonHelper helper) throws FailureException {
    output = inputOne + inputTwo;
    ActionReporter report = helper.getReporter();
    report.result("Added the two numbers successfully!");
    return ExecutionResult.PASSED;
} }

Then get a manifest from the addon upload process and create a jar file to upload.