Test variables

A test variable is a user-defined, name-value pair that stores and refers to information throughout a test and between tests.

A variable is declared in the test variables section of the test. You can use it throughout the test as a reference for any field that can be substituted. Substituting data from a test variable is achieved using the Test Variables page of the Test Data Source view. You can do the following actions to a test variable:
  • Provide a default value to the variable during declaration.
  • Change the value of the variable using Set Variable statement. You can use the Add and Insert menus of the Test Editor to create Set Variable statements.
  • Set hard-coded value or value retried from a data source, such as dataset or reference that appears before the Set statement to the variable.
If a variable is initialized at various places such as test, compound test, schedule, or user group, the product uses the following order to initialize the value of the variable when running the test. The variable set in the variable table of the compound test editor takes the highest precedence followed by others:
  1. Compound test setting in the variable table UI
  2. Compound test specified in a var file
  3. User group setting in the variable table UI
  4. User group specified in a var file
  5. Schedule specified setting in the variable table UI
  6. Schedule specified in a var file
  7. Command line
Note: You must select All tests for this user from the Visible in drop-down list to take the precedence of variable initialization.

Sharing variables among tests

In order to share variables between tests, all the tests must contain the variables with the same name. The variables must also have Visible in set to All tests for this user. When these conditions are met and multiple tests have been placed in a schedule, then variable in the dataset of one test can be used in the other test.

A common reason to share data between tests is to perform data correlation. With data correlation, a variable is set to a response that comes from a request in one test and is used in requests performed in a different test. Assume that you are testing an employee database. The Create Employee test creates an employee record and the Modify Employee test modifies an employee record. When a new record is created, it is assigned a record ID. Variables can be used to pass the record ID from a response in the Create Employee test to the Modify Employee test. A user-defined variable is not shared among different virtual users. The variable is shared only among the different tests of the same virtual user. If you set Visible in to This test only, then dataset from a test is not available to another even if both tests contain variables with the same name.

If you want to share variables between the different types of test scripts in your product, consider the following points:
  • Declare the test variables with the same name across all the test scripts for the variables to communicate with each other. Set Visible in to All tests for this user.
  • Include the required test scripts into a compound test.

Using test steps, you can share the default values of the variables to another test script. You can also assign new values to the variables and use the latest values in another test script.

If you want to share variables between the test scripts of different testing products such as HCL OneTest UI, HCL OneTest Performance, or HCL OneTest API, you must consider the following points:

  • If you are using Installation Manager, you must shell-share or install the products in the same package group.
  • If you are using InstallAnywhere, you must use the installer that installs both HCL OneTest UI and HCL OneTest Performance together.
    Note: By using InstallAnywhere, you cannot shell-share your product with HCL OneTest API.
  • Declare the test variables with the same name across the HCL OneTest UI and HCL OneTest Performance test scripts. Set Visible in to All tests for this user.
  • Include the required test scripts into a compound test.
  • If you are using HCL OneTest API test scripts, you must map your tags with the test variables of HCL OneTest UI or HCL OneTest Performance.

Using variables to access datasets

You can define variables so that they share data from a dataset throughout tests. This is achieved by having the value field of a Set Variable statement substituted from a dataset. By doing so, the first test which appears in the schedule can set the variable from a dataset and share it with the other test in a schedule.

Assume that you have two tests that log in to an application using a user ID from a dataset. The first test can set the value of a variable from the dataset, and both tests can use the variable, instead of directly using the dataset. In this case both use the same record from the dataset. This is similar to the fetch-only-once-per-user behavior of a dataset. However, fetching once means that during playback, a virtual user gets only one record from the dataset. The one-record limit holds even if the tests are in a loop, and are run several times by the virtual user. By using the user-defined variables, the virtual user retrieves a new record each time through the loop, and both tests can use the same record.

Note: Assignment (set) operators can not only have a variable value substituted from a dataset, but also in the declaration of a variable. You can substitute the assignment operator and variable value from any data source, and thus that value can be shared between tests as well.

Array variables

You create an array variable to add multiple values to a variable. If you create a secondary HTTP request, add complete paths of the requests in the array variable that can be used a custom code during playback.