Postman Tutorial Part 26 – Using Environment in Collection Runner

We have seen about Collection Runner in last post.

In this post we will see how can we select environment in a Collection Runner.

When we are not using Collection Runner, we select desired environment in drop down at right top corner. Collection runner also provides you a drop down to select environment.

This dropdown will list all the available environments.

Note:- You can select only one environment at a time in Collection runner which is same in normal run as well.

You will see a checkbox for option “Keep variable values” as shown below:

This is very important to understand as people mess up their variable/environment file unknowingly.

If you check above checkbox, it will write the value of variables at end of the run to its current value in the session. It means if any line of code in any request of collection, adds/updates/delete value of a variable of environment, it will be saved.

We will see it with an example:-

Import below COllection JSON:-

https://www.getpostman.com/collections/aa9795dc59992cc5ffff

And create a environment file as below:-

Environment “Auth Data” looks as of now:-

In “Get New Booking Details” request of above collection, I am updating an environment variable and adding “bookingid” variable in “Create Booking” request.

Let’s run above collection without selecting “Keep variable values” checkbox. Once it is run, go and check the environment “Auth Data”. You will not see any change in “Auth Data”.

Now rerun the collection by checking “Keep variable values” checkbox. Once it is run, go and check the environment “Auth Data”. You will see some change in “Auth Data”.

You will see two changes:-

  1. “bookingid” variable got added which we are adding in “Create Booking” request.

2. New Value of “name” is updated as “Current Value” in environment.

Hopefully, you understand the logic behind the checkbox “Keep variable values” . Use it carefully as it may affect next run of requests. If you do not want to have any changes in variables through scripts, uncheck the checkbox.

There is another twist here. There is another option which impact the updation of variable. That is called “Automatically persist variable values”. It is available as a toggle in setting.

Navigate to File -> Setting.

If you toggle ON “Automatically persist variable values” , it will persist the current value of variables to the initial value at the end of every request execution. Now you can understand that in above run, we see “Current value” of “name” variable updated but not “Initial value”. It happened because “Automatically persist variable values” toggle was off.

Now check “Keep variable values” checkbox and toggle ON “Automatically persist variable values” and run the collection again and check “Auth Data”.

You can see “Current Value” and “Initial Value” both are same for variable “name” and “bookingid”.

You can follow below flowchart given at Postman official document:-

More about API Testing in upcoming posts. Stay tuned.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyApiTesting

2 thoughts on “Postman Tutorial Part 26 – Using Environment in Collection Runner

  1. toggle ON “Automatically persist variable values” – this option is not available anymore in the latest postman versions

Leave a Reply

Your email address will not be published. Required fields are marked *