Test variables
A test variable is a user-defined, name-value pair that stores and refers to information throughout a test. You can assign the value of a variable to a test element or assign the value of a UI object property to a test variable.
When you record a test, the URL of the application is stored in the default variable,
APP_APP1_URL. You can create variables by using the following
options:
- By using the Add
option
in the Configure settings and data pane. - By using the Add new variable option when you assign the property of an object to a variable in the Assign step.
- By adding var_name: var_value under vars: section in the Code view of the test script in Test Editor.
You can use the variables for substitution. To substitute data from a test variable, you can
use the Details section of the step details pane. You can perform the
following actions with test variables:
- Provide a default value to the variable during variable creation.
- Change the value of a UI object by replacing the value with a variable. The UI object assumes the value of the variable when the test is run.
- Change the value of the variable using the 'Assign' statement. You can assign an object property to a variable.
- Modify the value of a variable by using the values extracted through RegEx patterns.
Types of variables
Variables are classified as input, local, or output variables based on their purpose and scope.
- Input variables
: Provide a
way to receive values from calling tests or configurations. Use them to pass data into a
test or module at runtime. - Local variables
: Define
values that are used within a test or a suite. These variables remain internal and are not
accessible outside the test or suite in which they are declared. - Output variables
: These
variables are used to return values to the calling test or a suite. You can map these
variables to existing or new variables to capture the returned data.
Random number generation
You can generate random numbers and assign the value to a variable by defining a random
expression. For example, you can define ${Math.floor(Math.random()*100)}
and assign it to a variable, ${value}.
You can use a random expression in the following ways:
- Create a new variable in the Configure settings and data step, and assign the random expression to the variable.
- Create a new variable in the test, and insert an Assign step before any step where the random number is needed. Then, in the Assign step details, you can assign the random expression to the variable.