Testing
Set Env Variable

Set Environment Variable

From the Tests tab, you can set environment variables using the Set Env Variable dropdown.


Set Env Variable

Follow the steps below:

Step 1

Create an environment first from the Env tab (if it's not already created).

Step 2

In the Tests tab, select the Set Env Variable dropdown option (The action will automatically become setTo).

Step 3

Enter the appropriate source of the variable value in the left input box (see above image).

Source Types

Enter the appropriate source of the variable value in the left input box.

JSON Response

  • Enter json.propertyName where propertyName is the JSON key in the response body.

Text Response

  • Enter the text keyword. This sets the entire response body to the variable.

Header

  • To set header, enter header.headerName where headerName is the response header name.

Cookie

  • To set cookie, enter cookie.cookieName where cookieName is the response cookie name.

Custom Value

  • To set any custom value manually, Just type the text as required in the left input e.g processing.

Clear Value

  • To clear values use null keyword in the left input.

Delete Variable

  • To delete a variable completely use the delete keyword in left input.

Value Field

  • In the value input, enter a variable name in the format {{variableName}}.
    • When it matches a variable name in Env, it will turn green. If the variable doesn't exist, it will be created.
  • Now execute the request. You will see the variable value set in the Env tab.
    • If you don't see the change in the Env tab, close and re-open the tab to refresh it.

Set Env with Scope

The default location will be the Active Environment when you use {{variable}}. You can use a scope to explicitly control which environment variable to set.


Set Env Variable Scope
  • To set a variable in the local environment use {{variable, local}}.
  • To set a variable in the global environment use {{variable, global}}.

Set Variables in Scripting

  • For details on how to set environment variables using scripting, click here.