Environments enables you to create robust requests that you can reuse. For more information about using variables and environments, see Variables. You also can use environments in the Collection Runner.
Let’s look at an example collection with one POST request that uses environment variables in its URL, body, and test script.
To begin, download the sample collection.
To import the sample in Postman, click the Import button in the header bar. In the IMPORT modal, select the sample JSON file to upload it.
The sample file displays in Postman as
postman-echo.com/ in the sidebar.
The test expects the value of
foo in the response body to be equal to
bar. Let us also assume that after some computation, we’re resetting the value of this variable to
To run this collection correctly in the Collection Runner, you must supply the corresponding environment.
Download the sample environment JSON file.
In the Collection Runner, select the test environment from the environment dropdown on the left and run the collection. You’ll see the tests pass.
If you switch back to the main Postman app window and check the value of the variable
foo, you’ll see that it is now
By default, any variable changes in the environment (or globals) in the Collection Runner shows in the main Postman app window because
Persist Variables is checked in the options. If you run the collection once again, you’ll see that it now fails, since we changed the value of the variable
Persist Variables is checked the first time you open the Collection Runner. If you do not want variables to be updated during the run, deselect the
Persist Variables checkbox.
In this case, think of it as the Collection Runner saving the initial state of the environment (and globals), and restoring it after the run is complete. This action is useful when you reuse the same variables in your requests and want to run the same collection multiple times. It ensures the environment (and globals) state is not affected by a collection run.
For more information about collection runs, see: