Test variables
A test variable is a user-defined, name-value pair that stores and refers to information throughout a test and between tests.
- Provide a default value to the variable during declaration.
- Change the value of the variable using the 'Variable set' statement.
- 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.
- Compound test setting in the variable table UI
- Compound test specified in a var file
- User group setting in the variable table UI
- User group specified in a var file
- Schedule specified setting in the variable table UI
- Schedule specified in a var file
- Command line
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 a 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.
- 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.
- Create and use the variables in the following sequence for different types of tests in a
compound test:
If Then You want to share a variable from a functional test to a Web UI test Perform the following steps: - Create a variable in the functional test by using createOutputVariable("name", value).
- Create a variable with the same name in the Web UI test and set Visible in to All tests for this user.
You want to share a variable from a Web UI test to a functional test Perform the following steps: - Create a variable in the Web UI test and set Visible in to All tests for this user.
- Set an initial value for the variable in the Web UI test.
- Retrieve and use the same variable in the functional test by using getInputParameter("name").
You want to share a variable from a Web UI test to a Web UI test Perform the following steps: - Create a variable in the Web UI test and set Visible in to All tests for this user.
- Set an initial value for the variable in the Web UI test.
- Create a variable with the same name in the other Web UI test and set Visible in to All tests for this user.
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.
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.