What is Postman Sandbox?

PostmanREST APISOAP API

Answer − Postman Sandbox is an Environment provided to execute JavaScript written as a part of the Pre-Request and Tests scripts for a request. This can be available for both Postman and Newman. Thus every script developed under the Tests or Pre-Request Scripts tab can be executed within this Sandbox.

Libraries and Utilities used in Postman Sandbox −

  • Lodash - a utility in the JavaScript library.
  • cheerio.
  • BackboneJS.
  • SugarJS.
  • CryptoJS.

Environment, Global, Dynamic variables & Cookies

To set an Environment variable, we have to add the below script −

postman.setEnvironmentVariable(name of variable, value of variable)

To set a Global variable, we have to add the below script −

postman.setGlobalVariable(name of variable, value of variable)

To get an Environment variable, we have to add the below script −

postman.getEnvironmentVariable(name of variable)

To get a Global variable, we have to add the below script −

postman.getGlobalVariable(name of variable)

To clear an Environment variable, we have to add the below script −

postman.clearEnvironmentVariable(name of variable)

To clear a Global variable, we have to add the below script −

postman.clearGlobalVariable(name of variable)

To clear all Global variables, we have to add the below script −

postman.clearGlobalVariables()

To access/read a particular Environment variable say e1 we have to add the below script −

Environment["e1"]

To access/read a particular Global variable say G1 we have to add the below script −

globals["g1"]

To get all cookies for a domain, we have to add the below script −

responseCookies {array}

To obtain response cookie with name say c, we have to add the below script −

postman.getResponseCookie(c)

A dynamic variable cannot be used directly in the Sandbox. We can use them in a request endpoint, body or header in the format − {{<variable name>}}.

To add a timestamp, we have to add the below script −

{{$timestamp}}

To add a random integer from 0 to 5, we have to add the below script −

{{$randomInt}}

Test-only - This object can only be used for the scripts developed under the Tests. If we try to utilize it for the Pre-Request Scripts, we shall encounter errors.

raja
Published on 25-Jun-2021 12:40:45
Advertisements