The StringOperations/containsEither extension checks whether an input string contains at least one of two expected values. If the input contains either value, the step passes. If neither value is found, the extension throws an error and the step fails.
This is useful when a journey needs to accept more than one valid text outcome, such as validating dynamic labels, alternate messages, regional wording, or page text where either of two expected values is acceptable.
Parameters:
-
inputrequired, the string value to search within; -
eitherrequired, the first expected substring to look for ininput; -
orrequired, the second expected substring to look for ininput. This input name follows the source code spelling;
Note: The check uses JavaScript indexOf(), so matching is case-sensitive and substring-based. For example, brown cow contains brown, but it does not contain Brown with an uppercase B.
How to apply this to your journey
Use the extension in a journey by calling StringOperations/containsEither with the execute command. Pass each value to the matching extension input using as inputName.
Note: This extension is an assertion-style extension. It does not return a success message when the condition passes. If neither expected value is found, it throws the message The string does not contain one of the expected values and the journey step fails.
execute "StringOperations/containsEither" using "brown cow" as input, "brown" as either, "sheep" as or returning $responseexecute "StringOperations/containsEither" using "Your order is pending" as input, "approved" as either, "pending" as or returning $responseYou can also pass stored variables into the extension when the text or expected values are captured earlier in the journey.
execute "StringOperations/containsEither" using "$text" as input, "$firstExpectedText" as either, "$secondExpectedText" as or returning $responsestore value "brown cow" in $text
store value "brown" in $firstExpectedText
store value "sheep" in $secondExpectedText
execute "StringOperations/containsEither" using "$text" as input, "$firstExpectedText" as either, "$secondExpectedText" as or returning $responseExample failure output when the input does not contain either expected value:
The string does not contain one of the expected valuesThis extension does not require any external resource.
The extension should be configured as:
- Run asynchronously: No
- Scope: Global
Limitation: This extension performs a simple JavaScript substring check with indexOf(). It does not normalize case, trim whitespace, remove punctuation, compare whole words, handle regular expressions, or coerce non-string values safely. If input, either, or or is missing, null, undefined, or not a string-like value, the step may fail with a JavaScript error instead of a custom validation message. Because the code uses only standard synchronous JavaScript and does not intentionally use browser-specific APIs beyond the language runtime, there is no major DOM or page-state dependency. Still, validate it in each browser/device configuration used by your plans when it is combined with page-captured text, localization, responsive content, or upstream 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:
// This extension allows you to input a stored value e.g. a string of text
// You can then provide 2 inputs - an either and an or
// The extension then asserts whether the value you inputted contains the either/or values
// Write a step: containseither(value1,eithervalue,orvalue)
// Example: containseither($text,'brown','sheep')
// $text in this case could be "brown cow"
// The extension would pass as the text contains on of the values - brown
// If it does not find one of the values, the step will fail
var string = input;
var either = either;
var or = or;
var assert = function(condition, message) {
if (!condition) {
throw new Error(message);
}
};
assert(string.indexOf(either) !== -1 || string.indexOf(or) !== -1, 'The string does not contain one of the expected values');
Comments
0 comments
Please sign in to leave a comment.