How to change the environment in Tests script of last request of the collection

Viewed 339

Some set of the requests are to run under few environments , so i want to make few iterations in collection runner and in a test script of last request to change environment , to make next iteration run on next environment - Need your help to change environment through script if it is possible

1 Answers

This is not possible at the moment, but there is a workaround (copied from the Postman Community):

You should be able to accomplish by making use of pm.sendRequest and the Postman API. So you'd use pm.sendRequest to fetch the relevant Environment and save it to a local variable in your script and use it accordingly.

More information here:

https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#sending-requests-from-scripts

https://learning.postman.com/docs/sending-requests/variables/#defining-local-variables

There's a feature request in the Postman github repository for it: Change environment scope in pre-request or test scripts #9061

Related