Postman is very powerful tool for developers to test and automate Web API tests for multiple environments simultaneously. This is a multi-part tutorial on how can we use Postman more efficiently and effectively. In previous post we have seen that how to use basic features of postman and setup tests automation against our collections.
Today we will see that how to use Environments and variables in postman for API test automation.
Environments, Variables :
As we know, in our collection we have set of API calls and each call have URL , headers , parameters etc. To execute those API calls for different Environments we are need to update URL, Headers ( for different versions ) etc. for each API call and to accomplish that we can use Environment feature of Postman where we can create separate Environment for D, Q , S etc. and in each environment we need to define "baseUrl" , "header" etc which we can used as variables in our APIs. Lets see how we can create step by step.
1- First click on setting icon at top right corner of Postman and go to Manage Environments
2- Click on Add button and Name your environment e.g. Demo
3- Add your properties as key pair values in grid below environment Name. Lets add baseUrl property and click Add.
4- Now we have environment created with baseUrl ( can also add headers can see in below screenshot ). Click on dropdown in top right corner and select your environment.
In this way we can manage our Environments and use variables instead of changing url or header for each api call.
Now we need to create API tests once and can just manage our Environments and our API postman tests are automated and ready to run on click.