Postman

Setting Variable

Are store place where values are initialized or set for a later computation or as we are doing the computation to perform different kinds of activities. There are different types of variables.

  • Collection : – Variables at the collection level will be set giving the name as well as the value.

Steps to add collection variable

  • Tap on Collection
  • Select on Variable on the right side.
  • Type the name of the collection variable and its value.

Figure 1.6 – Creating Collection Variable

There is another way to set a collection variable through script. The script to create and initialize a collection variable is as follow

Example : – pm.collectionVariables.set(“varibale_name”, “value”); 

  • Environment : – This is another kind of Variable, that is used to be accessed at the environment level. The declaration can be used in the same manner setting name as well as the value.

Steps to add environment variable

  • Click on New button 
  • Click on Environment
  • Opens the environment variable window, and Set the name of variable, and values.

Figure 1.7 – Environment Variable

There is another way to set a environment variable through script. The script to create and initialize a environment variable is as follow

Example : – pm.environment.set(“varibale_name”,”value”); 

  • Global : – It is variable that is serving and accessible at the global level. These could let us to access the variables across different workspace.

Steps to add global variable

  • Click on Eye button 
  • Click on Add button.
  • Opens global variable window, and set the name, variable, and values for global variable.

Figure 1.8 -Global Variable

There is another way to set a global variable through script. The script to create and initialize a global variable is as follow

Example : – pm.global.set(“varibale_name”,”value”); 

Getting Variable

In order to access those variable that are declared and set with value. There are two major accessing technics

  •  Using double curly braces to access the varibale in the parameter or URL
  • Using a get method to access the variable in test script.

Getting Variable – Using Curly Brace

This is a method that could let us to access variables in the URL, Parameter. The access application can be made as follow in the attached screenshot

Figure 1.9 –Variable in URL or Parameter

Getting Variable – Inside the Test script

The access of the variables in the script. for working and performing any computation. in order to do that, there is a get method, and the application is as following

  • pm.collectionVaribales.get(“varibale_name”);
  • pm.global.get(“variable_name”);
  • pm.environment.get(“varibale_name)
  • pm.variable.get(“variable_name”);

Figure 1.10 –Using Variable Inside a Script

Test Script

Test script is section in a call where the response of the calls is validated against the expected results. To do that, test scripts can be written down by the testers. Some of the tests that we perform are assertion of entire Jsona specific [key,values] check, and many more as per the nature of scenario that is supposed to be checked.

Assertion Entire Json

Figure 2.0 – Comparing Entire Json

Pre-request

This is a part that is available in the request as well as in the collection. The purpose is to set any preparation like generate a token – for authenticating the call, declaration of variablesvaluesfunctions, and any other inputs to be used in the call. Th pre-request executes anything before making the actual call.

The Pre-request exists on three major places

  • Collection Level
  • Folder/Sub-Folder Level
  • Request Level

Figure 2.1 – Pre-Request

User defined Functions

Are set of instructions which are used to do a certain action. Possible to introduce function for common and major operations so that everyone in the development able to use it without modifying or creating the same kind of code more than one time.

Figure 2.2 – User Defined function At Request Level

Global Functions

This is a function that is going to be used across the folder of the collection. This means that the function can be used in all different types of calls and does the expected function as it is defined.