Docs » Advanced test configurations » Create and use Global Variables

Create and use Global Variables ๐Ÿ”—

Define a global variables once, then you can use the variable across all of your Browser and API tests.

How can you use global variables? ๐Ÿ”—

Global variables are stored securely in the Splunk Synthetic Monitoring platform, but the keys and values of all global variables in your account are visible to all users.

To preserve your accountโ€™s security, donโ€™t use production credentials, real credit card information, or other sensitive data in global variables for your checks. Instead, try using placeholder credentials to test workflows that require information to be entered during a test.

To use data such as test login credentials, API keys, or other test information, you can permanently conceal the value of a global variable from all users of your account.

What happens when you conceal a global variable? ๐Ÿ”—

When you conceal a global variable, its value is permanently concealed from all users of the account. This lets you create and save variables such as test login credentials, API keys, and other sensitive information to use in Browser and API tests.

To preserve security, the value of a concealed global variable is never revealed to any user of the account after it has been created and saved. The value is scrubbed from the Splunk Synthetic Monitoring UI, from test results, and from alert messages.

Create a global variable ๐Ÿ”—

There are two ways to create a global variable:

  1. Add a new global variable in the vault:

    1. From the Splunk Synthetic Monitoring landing page, select Synthetics configuration. The Synthetics configuration page opens, on the Global variables tab.

    2. Select + Add to open the creation dialog box.

  2. Add a new global variable while editing a test:

    1. In the right-hand Variables column, scroll to Global variables and select Add.

Once youโ€™re in the Add global variable dialog box, enter the following:

  1. In the env field, enter the name of the variable. You will use this key to access your variable within a test.

  2. In the value field, enter the value that will replace the variable when the test is run.

  3. (Optional) In the Description field, enter a description to explain the purpose of the variable for future reference. A description is particularly helpful when you conceal the variable and cannot reveal its value.

  4. (Optional) Select Conceal value to permanently conceal the value to all users.

  5. Once youโ€™re satisfied with your global variable, select Add.

Edit a Global Variable ๐Ÿ”—

To edit the key or description of a global variable, visit the global variables page and edit within the field. Select Save when youโ€™re finished editing.

Editing the value of a saved concealed global variable clears the previous value. You must provide a new value and select Save to apply it.

Use a global variable in a synthetic test ๐Ÿ”—

You can use a global variable to fill in fields in the Steps and synthetic transactions of a Browser test, or in the requests of an API test. Global variables cannot be used in cookies.

While creating or editing a test, the right-hand Variables tab provides list of built-in variables and global variables you can use. Select the name of a variable to copy it to your keyboard.

Use a global variable in a Browser test ๐Ÿ”—

Follow these steps to add a variable to your Browser test:

  1. While creating or editing a transactional Browser test, go to your Steps.

  2. Under Action, select Fill in field from the dropdown menu.

  3. Under Value, enter the key for the global variable you want to use, use the env. prefix and enclosed in double curly braces. For example, to reference a global variable with the key dev-username, enter {{env.dev-username}} in the Value field.

  4. Finish editing or creating the test.

  5. Save your test.

Use a global variable in an API Test ๐Ÿ”—

You can also use a global variable to fill in any field in an API test. For instance, you can use a global variable to provide a URL for any request, a header value, or any other value.

Follow these steps to add a variable to your API test:

  1. While creating or editing an API test, go to your Requests.

  2. In a variable field for any setup, request, or validation step, enter the key for the global variable you want to use, use the env. prefix and enclosed in double curly braces. For example, to reference a global variable with the key staging-url, enter {{env.staging-url}} in the field.

  3. Finish editing or creating the test.

  4. Save your test.

This page was last updated on Oct 18, 2024.