The Compare extension compares two provided values and returns a pass-style message when both values match exactly.
This is useful when a journey needs to compare an expected value with an actual value stored in variables, table data, API output, or text captured from the application under test.
Parameters:
-
arequired, the first value to compare. This input represents the first comparison value from the source code; -
brequired, the second value to compare. This input represents the second comparison value from the source code.
Note: The comparison uses JavaScript strict equality, so the values must match in both value and type. For example, a number 10 and a string 10 are not the same when passed as different JavaScript types.
How to apply this to your journey
Use the extension in a journey by calling Compare with the execute command. Pass each value to the matching extension input using as a and as b.
Note: The source comments show the conceptual syntax as Compare ("input1","input2"), but the implementation reads inputs named a and b. Configure and call the extension with a and b unless you update the source code to use different input names.
execute "Compare" using "Approved" as a and "Approved" as b returning $responseexecute "Compare" using "Approved" as a and "Rejected" as b returning $responseYou can also pass stored variables into the comparison.
execute "Compare" using "$actualStatus" as a and "$expectedStatus" as b returning $responsestore value "Approved" in $actualStatus
store value "Approved" in $expectedStatus
execute "Compare" using "$actualStatus" as a and "$expectedStatus" as b returning $responseExample output when both values match:
Passed: the two value match!Example output when the values do not match:
Failed: the two values do not match!This extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension performs only a direct JavaScript strict-equality comparison using a === b. It does not trim whitespace, ignore case, normalize dates, coerce numbers and strings, compare object contents deeply, compare arrays item by item, or parse JSON before comparing. The source catches mismatch errors and returns the failure message as text, so the journey should assert the returned $response when a mismatch needs to fail a later step. Because the implementation reads variables named a and b, calls that use input names such as input1 and input2 will not supply the values expected by this source unless the extension configuration or source code is changed. Cross-browser note: This extension does not intentionally use browser-specific APIs beyond standard JavaScript. Still, validate it in the browser/device configurations used by your plans when it is combined with page state, network calls, external libraries, or DOM-dependent journey steps.
Add the extension to your Virtuoso instance
Select the domain that matches your Virtuoso account.
View source
Last updated: 04/06/2026
Resources:
This extension does not require any external resource.
// Note this extension is not a product feature of Virtuoso and is not officially supported
// Extensions use javascript which may or may not be compatible with systems under test (SUTs)
// We welcome you to use this extension or adapt it for your needs
// Instructions:
// Write a step: Compare ("input1","input2")
// This compares the values and returns a Pass or Fail result
function compare() {
if(a === b) {
return "Passed: the two value match!";
}
throw new Error("Failed: the two values do not match!");
}
try {
return(compare());
} catch (error) {
return(error.message);
}
Comments
0 comments
Please sign in to leave a comment.