Declare and assign test variables


+

Search Tips   |   Advanced Search

 

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.

To create, initialize, and assign a value to a test variable:

  1. Double-click a test

  2. To create a container for the test variables that you create in a test:

    1. Open the test, and in the Test Contents area, click Test Variables, at the top of the test

    2. Select...

        Add | Test Variable Container

      A container named Test Variables is created for the user-defined variables.

    3. Highlight the container to rename it.

      The Test Element Details area opens for you to type a new name in the Name field.

  3. To view or initialize a test variable:

    1. Open the test, and in the Test Contents section, click the user-defined container to contain the variable.

    2. Select...

        Add | Variable Declaration

    3. 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.

    4. In the Test Element Details area, set the scope and initial value for the variable.

      Visible in: This test only Restrict data to the current test only. Even if another test has a variable with the same name, that variable will not change.
      Visible in: All tests for this user 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: Text Initialize the variable to a specific value whenever the test runs in the schedule.
      If not initialized, set to: Datapool value 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.

      For "Issue test log warning" or "Issue test log error", verify the Test log page in the schedule sets errors and failures, and warnings to All (default)

      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.

  4. To assign a value to a test variable:

    1. Open the test, and in the Test Contents area, select a test element.

    2. Select...

        Insert | Variable Assignment

      ...which inserts the assignment before the selected element. The Test Editor window opens and lists the variables available to the test.

    3. 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.