Dinesh Kumar
Dinesh Kumar

Reputation: 1742

Postman - Ignore test execution based on environment

In Postman, is there a way to ignore a specific test execution based upon environment at runtime? I have a collection which consists of around 30 tests and I don't want 4-5 tests to execute on production environment at runtime but because they are meant to be executed on staging only. I don't want to have multiple collections for different environments. Any way I can make use of pre-request scripts in this scenario?

Upvotes: 3

Views: 4562

Answers (2)

GargantuanTezMaximus
GargantuanTezMaximus

Reputation: 1118

I agree with @joroe that a simple way to conditionally add tests is with a variable and check that variable before each test that is conditional.

If you want to not have the test sent to the server at all you probably want to explore the collection runner and group your into collections according to the environment. For example you may group your requests into a collection called PROD Tests that runs requests 1-10. You can have a second collection called DEV Tests that contains requests 1-15 (the ten from PROD plus the five others you don't want to run in PROD). It's very easy to copy a request from one collection to another. You then in the test runner run the collection for the specific environment. You can even automate this using the Newman extension. I'm not super familiar but there is documentation at the link posted. I've included a screen capture of the collection runner interface and how I have some of my tests set up to run.

enter image description here

Upvotes: 3

joroe
joroe

Reputation: 11

Create a variable in each environment ("ENV") with name of the environment ("LOCAL").

if(environment.ENV === "LOCAL") tests["Run in local environment"] = true;

Upvotes: 1

Related Questions