Variables

Variables in Testfully allows you to store and reuse values across your API requests and scripts. This capability simplifies the process of managing dynamic data and enables the creation of flexible and maintainable API tests.

What are Variables?

A variable is a symbolic representation of a data value. Instead of hardcoding a value directly into your requests, you can store it in a variable and reference the variable. This abstraction not only makes your requests more readable and maintainable but also allows you to update the value in one place and have the change propagate throughout your tests.

For example, you can store the base URL of your API in a variable named base_url and use {{base_url}} in your request URLs. If the base URL changes, you only need to update the variable's value.

In Testfully, variables are structured as key-value pairs. When you reference the variable name, you can access its associated value.

Types of Variables

Testfully supports several types of variables based on their scope and usage:

  1. Global Variables: Accessible across all folders and requests in your workspace, suitable for values that are widely used and need to be consistent across your tests.
  2. Environment Variables: Scoped to a specific environment (e.g., Development, Staging, Production). Useful for managing different configurations such as development, staging, and production settings.
  3. Folder Variables: Specific to a folder, allowing for localized variable management within a subset of requests.

Where a Variable Can Be Used

Currently, you can reference a variable (global, environment, collection, folder) in the URL, query param values, authorization settings,  request header values, request body and response body & header validation by adding {{global_value_name}} to any of the supported fields (e.g., {{base_url}}/endpoint).

Variable Precedence

If a variable with the same name is declared in multiple scopes, the value stored in the variable with the narrowest scope will be used. For example, if there is a global variable named username and a folder variable named username, the folder value will be used when the request runs.

Adding a New Global Variable

  1. Navigate to Environments
    • In the left sidebar, click on Environments to expand the section.
    • Click on Globals to open the global variables panel.
  2. Add a New Variable
    • In the Globals panel, you will see fields where you can enter a variable name and value directly.
  3. Enter Variable Details
    • Variable Name: Click on the Name field and enter a name for your variable (e.g., base_url).
    • Variable Value: Click on the Value field and enter the value for your variable (e.g., https://httpbin.org).
  4. Save the Variable
    • Click on the Save button in the top right corner to add the new variable to the list.

Global variables in Testfully

Using Variables in Requests

  1. Open a Request: Navigate to the Requests section in the left sidebar and select the request you want to edit.
  2. Insert Variable Reference: Pick the field where you want to use the variable (e.g., URL, headers, body). For example, if you have a global variable named base_url, you can reference it in the URL field as {{base_url}}/get.
  3. Save the Request: After adding the variable reference, make sure to Save the request to apply the changes.

Using variables in requests in Testfully

Environment Variables

Environment variables are scoped to a specific environment and are useful for managing different configurations across various deployment stages. For instance, you might have different base URLs, API keys, or other configuration settings for development, staging, and production environments.

Creating Environment Variables

  1. Navigate to Environments:
    • In the left sidebar, click on Environments to expand the section.
    • Select the environment you want to configure (e.g., httpbin).
  2. Add a New Variable:
    • In the environment panel, click on the Variables tab if it's not already selected.
    • Click on the Name field and enter the name for your variable (e.g., base_url).
    • Click on the Value field and enter the value for your variable (e.g., https://httpbin.org).
  3. Save the Variable:
    • Click on the Save button in the top right corner to save the new variable to the environment.

Environment variables in Testfully

Using environment variables

An environment variable will only be used if you have selected the environment when sending a request; otherwise, the value will not be used.

Folder Variables

Folder variables are scoped to a specific folder and are useful for managing values that are used across multiple requests within the same folder. This can help organize and maintain values that are only relevant to a particular subset of your API tests.

Creating Folder Variables

  1. Navigate to the Folder:
    • In the left sidebar, click on Requests to expand the section.
    • Select the folder you want to configure (e.g., httpbin).
  2. Open the Folder Settings:
    • Click on the three dots (ellipsis) next to the folder name to open the context menu.
    • Select Variables from the dropdown menu to open the folder variables panel.
  3. Add a New Variable:
    • In the folder variables panel, click on the Name field and enter the name for your variable (e.g., base_url).
    • Click on the Value field and enter the value for your variable (e.g., https://httpbin.org).
  4. Save the Variable:
    • Click on the Save button in the top right corner to save the new variable to the folder.

Folder variables in Testfully