Understanding How VerifyVariable Handles Comparisons and Calculations

Overview

This article explains why a VerifyVariable step might pass unexpectedly when comparing a variable to a value that appears to be an undeclared variable or involves a calculation. It clarifies how the system interprets quoted values and provides the correct method for performing numerical comparisons and mathematical operations.

How It Works

The VerifyVariable action is designed to verify the contents of a variable that was previously created, typically using the SetVariable action. Confusion can arise when the comparison involves strings or mathematical logic.

  • String vs. Variable: If a value in the verification step is enclosed in double quotes (e.g., "fze.local.myvar-1"), the system treats it as a literal string. It does not attempt to resolve it as a variable, which is why a "variable not declared" error does not occur. The comparison is then made between the actual variable's value and this literal string, which may not produce the intended outcome.
  • Numerical Comparisons and Calculations: The standard VerifyVariable input field is not designed to execute mathematical operations directly (e.g., fze.local.myvar - 1). To perform calculations or compare numerical values accurately, it is necessary to use a conditional code block.

To correctly compare a variable's value after a mathematical operation, you should use a code-based condition. This involves parsing the variable values as integers to ensure they are treated as numbers, not strings.

For example, to verify if one variable's value is one less than another, use the following code structure:

if (parseInt(fze.local.AppBlockCount1) == parseInt(fze.local.AppBlockCount) - 1) {
return true;
} else {
return false;
}

You need to make sure that local variables are declared and have a value assigned before utilizing it. 

Limitations

The VerifyVariable action is intended for direct verification of a variable's content. For complex logic, including mathematical calculations or conditional checks, using a code-based approach within an appropriate step is required to ensure the logic is executed correctly.

Related Information

For more details, please see our documentation on creating verifications and using variables in tests.