When you declare a variable, you can create a container
for it, initialize it to a string or a datapool value, and set its
scope. Then, within the test, you can reassign another value to the
variable.
Procedure
To create, initialize, and assign a value to a test variable:
- In the Test Navigator, browse to the test and double-click
it. The test opens.
- To create a container for the test variables that you create
in a test:
- Open the test, and in the Test Contents area,
click Test Variables, at the top of the test
- Select . A container
named Test Variables is created for the user-defined
variables.
- Select the container to rename it. The Test
Element Details area opens for you to type a new name
in the Name field.
- To view or initialize a test variable:
- Open the test, and in the Test Contents section,
click the user-defined container to contain the variable.
- Select .
- Type the name of the variable, and click OK. The variable is added as the last element in the container
and the Test Element Details area opens.
- In the Test Element Details area,
set the scope and initial value for the variable.
Visible
in: Select This test only to restrict
data to the current test only. Even if another test has a variable
with the same name, that variable will not change. Select All
tests for this user to share the value of this variable
when the test runs in a schedule. For the variable to be shared, both
tests must have a variable with the same name and must have this option
enabled.
If not initialized, set to:
Select Text to initialize the variable to a
specific value whenever the test runs in the schedule. Select Datapool
value and, in the Select Data Source window,
select the datapool that will initialize the variable.
Run-time
error if variable not initialized: Select the action for
the run when it encounters an uninitialized test variable. If you
select Issue test log warning or Issue
test log error, verify that the Test log page
in the schedule sets errors and failures, and warnings to All,
which is the default setting. If you select Exit the test,
the schedule continues to run although the virtual users that have
the uninitialized variable stop. If you select Do nothing,
the test continues to run.
- To
assign a value to a test variable:
- Open the test, and in the Test Contents area,
select a test element.
- Select , which inserts
the assignment before the selected element. The Test
Editor window opens and lists the variables available to
the test.
- Select the variable that you are assigning a value to,
and, in the Set to box in the Test
Element Details area, set the value for the variable. You can set the value to a text string, to any data source that
exists in the test before the assignment statement, or to Not
initialized. A Set statement
is added to the test, with the value you chose.