Help Center/ CodeArts PerfTest/ Best Practices/ Configuring Global Variables
Updated on 2025-12-16 GMT+08:00

Configuring Global Variables

Scenarios

Global variables are used to build data sets and enrich test data. When a global variable is used in a request, its value in the packet will be dynamically replaced with a specified value during a pressure test.

Global variables can be used in various scenarios. The following lists three common scenarios:

  • Simulate multi-user concurrent login: Simulating concurrent multi-user logins requires that each user access the system with a unique username and password. After login, subsequent operations (such as browsing and placing orders) rely on the user's session token (such as JWT or cookie). To effectively simulate many users logging in simultaneously during pressure tests, you can pre-record the user login credentials in a variable file. You can then add global variables to the requests to invoke these credentials when needed.
  • Ensure the uniqueness of test data: When testing services such as customer registration and order creation, ensure that the key identifiers (such as order No., customer mobile number, and email address) used in each operation are unique. This prevents database primary key conflicts or service logic verification failures.
  • Configure global parameters: For example, if a test case defines common parameter values such as Region and BaseURL, you only need to modify the variable content once to make the modification take effect globally. This improves efficiency and helps prevent omissions and errors.

Process Flow

  1. Create a test project.
  2. Create a test case.
  3. Add a global variable.
  4. Insert the added global variable into the test case.

Procedure

  1. Log in to the CodeArts PerfTest console.
  2. In the navigation pane, choose PerfTest Projects.
  3. Click Create Test Project.
  4. In the displayed dialog box, enter a test project name (for example, Web-test), and click OK.
  5. Click the name (Web-test) of the created test project to access its details page. On the Cases tab page, you can view the default directory and sample cases that are automatically generated.
  6. On the Cases tab page, click Global Variables.
  7. Add a global variable. You can directly add global variables of the integer, enumerated, or text type, or add file global variables with CSV or XLSX files.

    • Adding an integer, enumerated, or text global variable

      In the Global Variable dialog box, click Add Variable, enter a variable name, select a variable type, enter a variable value, select a read mode and sharing mode, and click Save in the Operation column. In this practice, add an integer global variable named number.

      Figure 1 Adding a global variable of the integer type
    • Adding a global variable of the file type
      1. In the Global Variable dialog box, click Download the .csv Template or Download the .xlsx Template as required.
      2. Enter the variable names and values by referring to the template. As shown in Figure 2, enter variable names in the first row and enter variable values from the second row. The rules for filling in the .csv and .xlsx files are the same.
        Figure 2 Example of filling file variables

        The file variables are described as follows:

        1. Use letters, digits, and underscores (_) for variable names. Variable values are not limited.
        2. Only .csv (UTF-8 without BOM) and .xlsx files can be imported.
        3. A file name (including the extension) can contain up to 50 bytes. Letters, digits, and underscores (_) are allowed.
        4. The maximum size of an .xlsx file is 20 MB and that of a .csv file is 80 MB.
      3. Click Import File Variable to upload the configured variable file.

  8. After global variables are added, close the Global Variable dialog box.
  9. Insert the added global variable into the test case. For example, insert the created global variable number to the sample case request information in 5.

    1. Enter $ in the request information input box.
    2. In the Insert Variable dialog box, set Type to Custom and Range to Global, and enter number as the variable name.
    3. Click Select to insert a variable.
      Figure 3 Insert the variable named number