Open In App

What is Postman Automation?

Last Updated : 06 Feb, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Postman is a cutting-edge Automation tool, which can be used for API testing, Automated Unit testing, and Integrated testing. The automation uses inherent functions provided inside Postman as well as allows usage of external JS library. Through Postman Runner functionality this feature can be used. This functionality allows us to create a Postman collection of any number of APIs which helps the Testing team to achieve faster and more efficient test results. The Postman Automation is pretty simple, due to the various inherent functionalities. Let’s see an example of simple automation.

In this demo request, the API is sent to the URL to generate an OTP, which resembles the basic login page of every modern web application.

Then the next API would be to validate the OTP, which goes like this

Here we are assuming the OTP to be 111111. Now, how to automate these, so that postman runs these 2 APIs in sequence and uses the right values. There are 2 Primary options available in Postman as Pre-Request Script and Tests. The major difference between those is that in the case Pre-Request Script the script is compiled before sending the request and in the case of Tests it is compiled after the response is received. For example, in this case for testing purposes, we can add a Pre-Request Script such that It will Create a new value for the “requesttime” field every time before running.

As we will further explore, we need to create a variable called request time/ (or any of your choice) which value will be populated by the Postman Script. These values will be stored in the environment variables collection available in the Postman application. Similarly, we can automate the user id field by using a random function provided by Postman such as:

Now, this function “$randomExampleEmail” will create random email ids every time the request is run. Hence making the process faster and more efficient than manually inputting data. Let us suppose the next API is meant to create a policy group such as:

As You can see in the response a policy is generated successfully, and now this value is now to be used in other APIs as variables or in the URL value of other APIs too such as:

Now for the {{Policygroupid}} variable to use the value generated in the previous API response we need to add a few lines of JS script. This can be done in many ways, for example:

Now, this snippet will search through the response API and look for the Id, after finding which it will store the same value in a variable called {{policygroupid}} (or any chosen name), making the whole process run with a single click.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads