Arithmetic Operations
The Arithmetic Expression feature in Sofy allows you to perform mathematical operations within test cases and assert the results dynamically. This functionality is designed for scenarios where numeric values on screen (such as counters, points, balances, or quantities) must be validated after user actions like increment/decrement or multiplication.
Supported operations:
- Addition (
+
) - Subtraction (
-
) - Multiplication (
×
) - Division (
/
) - Parentheses for grouping
- Precision up to 8 decimal places for float values (e.g., cryptocurrency scenarios)
Creating an Arithmetic Expression
- Add Step → Arithmetic Expression (During Recording)
- While recording a test, click on Add Step
- Choose Arithmetic Expression from the options
- Build Your Expression
- Select variables or input numeric values to build your expression
- Use Add Expression to insert numeric variables, text and operators(
+
,-
,×
,/
,(
,)
). - The Expression Preview updates live.
- You may undo the expression or clear the full expression to start fresh.
- Evaluate Expression
- Click Evaluate to calculate the result.
- Save the result as a new variable (Integer or Float).
- Specify precision (default 2 decimals, configurable up to 8).
Editing an existing arithmetic expression
- In Offline Edit, you can:
- Edit existing arithmetic steps.
- Add new arithmetic steps
In the Test Result view:
- The executed expression and all variable values are displayed.
- Compare modal shows a grayed-out “Arithmetic Operation” watermark since this step is screen-agnostic.
Error Handling
- Edit existing arithmetic steps.
- Validation Rules
- Expressions cannot end with an operator.
- No continuous values/variables without an operator (e.g.,
2var1+4
is invalid).
- Runtime Errors
- Division by zero → result =
N/A
(step continues without breaking). - Undefined variables →
Result: Undefined due to an undefined variable used
.
- Division by zero → result =
Best Practices
- Always define variables as Integer or Float (Strings are not supported in arithmetic steps).
- For float variables, define the required decimal precision.
- Use parentheses for clarity in complex expressions (BODMAS order).
- Keep expressions simple—complex percentage difference calculations may require multiple steps.
✅ With this feature, Sofy now enables assertions for dynamic arithmetic operations across customer scenarios, ensuring accuracy in numeric validations such as balances, counters, and totals.