Variables

Within API Testing there are multiple ways to define variables to address different requirements

Defining variables

Global Variables

Global variables are ones that are common across the whole test and typically does not change between runs based on Input sets

Add a Global variable

To add a Global Variable within the Test Editor Select Data Sets Click Add Global Variable Provide Variable Name and value Click Image of Confirm component icon

Edit A Global Variable

To edit an existing variable to change either the name or value For the given variable click Image of edit component icon

Input Set Variables

The input set, is a group of input variables representing a scenario (e.g product id). Where the number of input sets determines how many times the test will be executed using those values.

If 3 input sets are defined, the test will run 3 times using the inputs defined within each of those sets on each run.

Vault Variables

Variables can be defined within the vault which provides Test Suite scoped variables that can be used in all tests within that suite.

Vault variables can be defined as

  • Variable - Visible
  • Password - Hidden

Hook Variables

When Using API Hooks it is possible to override Global defined variables within the request payload when running tests.


    curl -X POST \
    -H X-API-Key:{API-Key} \
    -H X-API-Secret:{API-Secret} \
    -H Content-Type:application/json \
    -d "
        {
          "options": {
              "allAssertions": boolean,
              "JUnitFormat": boolean
          },
          "variables": {
              "url": "https://www.ibm.com",
              "username": "test",
              "password": "passw0rd"
          }
        }
      " \
    <API-Hook-URL>/tests/{Test-ID}/run

Variable Hierarchy

  • If a variable in defined in Vault and either in Global or Input sets, Global or Input will take precedence
  • If a variable is defined in both Global or Input set, Input set takes precedence
  • If a variable is supplied as part of a Hook request and is defined in Vault, Global or Input set, the Hook will take precedence

Referencing variables within a request

For setting variables during a test refer to Set