admin管理员组文章数量:1277910
I'm having several collections of REST queries and tests in postman, and for each collection I've created a set of environment variables. I wish to make sure the right environment is selected before running the tests. Is there a way to automatically switch between environments in pre-request script section?
I'm having several collections of REST queries and tests in postman, and for each collection I've created a set of environment variables. I wish to make sure the right environment is selected before running the tests. Is there a way to automatically switch between environments in pre-request script section?
Share Improve this question asked Nov 4, 2019 at 9:42 RoeyRoey 1031 silver badge6 bronze badges 1- You set variables for Collections, so the best course of action, would be to have one collection with one set of variables for -dev, same for -stage and -production. – Anuga Commented Nov 4, 2019 at 9:48
2 Answers
Reset to default 10You can't switch environments from the pre-request script section.
That being said you can still check the name of the current environment with pm.environment.name;
and stop the execution if it's not the one you expect, for example:
if(pm.environment.name !== "dev") {
postman.setNextRequest(null);
}
You can set variables names by environment and specially the url of your REST API.
本文标签: javascriptHow to change Postman environment in prerequest scriptStack Overflow
版权声明:本文标题:javascript - How to change Postman environment in pre-request script? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741234183a2362675.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论