nav-img
Advanced

Setting Global Variables

Global variables are used in many scenarios. For example, in a service that requires a username and password, different usernames and passwords must be used for pressure tests in multi-user scenarios.

Note
  • Before using global variables, ensure that the resource group for the pressure test has been upgraded to the latest version. Otherwise, the global variable function is unavailable.
  • A pressure test task reads the value of the corresponding global variable in sequence when it is running. That is, the first virtual user obtains the first value of the variable, and the second virtual user obtains the second value. .

Setting Global Variables

  1. Log in to the CPTS console and choose CPTS Test Projects in the navigation pane on the left.
  2. Locate a CPTS test project to be edited and click Edit Test Task.
  3. On the Test Tasks tab, click Global Variable.
  4. You can add a global variable in either of the following ways:

    Method 1: Adding a global variable manually

    1. Click Add Variable.
    2. Set parameters by referring to Table 1.
      Table 1 Setting global variables

      Parameter

      Description

      Name

      Name of a new global variable.

      Type

      Variable type, including the integer and the enumerated type.

      Value

      A pressure test task reads the value range of the corresponding global variable when it is running. For each virtual user, the variable value is polled. That is, the first virtual user obtains the first value of the variable, and the second virtual user obtains the second value. If the values are exhausted, the next virtual user obtains the first value again.

      NOTE:

      Variable content is transmitted in plain text during the pressure test. Exercise caution when entering the content.

      • When the variable type is Integer, enter the value range of the variable.
      • When the variable type is Enumerated, click to enter a variable value.
    3. When the setting is complete, click to save.

      After a variable is created, click Edit to modify it. If the global variable is referenced by a transaction, the value of the global variable in the transaction will be changed synchronously after the modification.

    Method 2: Importing file variables

    Note

    Prepare .csv or .xlsx file to be imported in advance.

    1. Click Import File Variable to import a .csv or .xlsx file.
      • Name: name of the file to be imported
      • Value: actual variable name. Multiple variable names are separated by commas (,).
      • Type: file
    2. After importing the global variable, you can perform the following operations:
      • Click Import Again to import a new global variable file.
      • If the imported global variable file is modified locally, click Upload Again to upload again.
      • Click Delete to delete the imported global variable file.
        Note

        The global variable file cannot be deleted when it is referenced.

Inserting a Variable

When adding a request, enter $ in the text box to add a variable. For details, see Adding Request Information (Packet) and Adding Request Information (Think Time).

Figure 1 Inserting a variable


When Type is set to Custom, set the following parameters:

  • Name: name of a customized variable.
  • Range: Select a variable range.
    Notice

    When the transaction type is set to Normal, preset variables can be inserted but preset transactions cannot.

When Type is set to System, select a function name.

  • ID card number: the randomly generated ID number
  • Mobile phone number: the randomly generated cell-phone number
  • Random number in a range: a randomly generated integer within the range entered by a user
  • Random character string: a randomly generated combination of lowercase letters and digits containing the number of digits entered by a user (1-32)
  • Time stamp: the current time stamp generated based on the user selection (second (s)/millisecond (ms)). Second (s) corresponds to a 10-digit time stamp, and millisecond (ms) corresponds to a 13-digit time stamp.
  • UUID: 32 randomly generated hexadecimal characters not including -