Mehran Shafqat
Mehran Shafqat

Reputation: 520

Disable requests in postman collection run

I have 100 request in collection runner and there are some request that will execute only on some condition. Actually when we run the postman collection it will execute all request 1 by 1.

In my case there are 10 requests in collection runner and dont want to execute it in normal follow only trigger some request just on specific condition. Is there any why I can prevent these request not no execute in normal run but should available in collection runner will execute on just specific condition

Upvotes: 2

Views: 10472

Answers (2)

Alex Taylor
Alex Taylor

Reputation: 131

if you want to avoid hardcoding request names, you can hack a toggle eg

// pre-request script

isDisabled = true
if (isDisabled) return pm.request.url = 'https://example.com#disabled'

then to disable a test, start with

// test script

if (pm.request.url.hash == 'disabled') return console.log("test disabled")

This does result in the dummy GET being called, if that overhead acceptable.

Upvotes: 0

gregPi
gregPi

Reputation: 128

In my opinion you can achieve this already.

I will user some flag set in environment variables to check if it is your "normal" run or not

And next use this flag in test script to set next request to be called:

if (pm.environment.get("normal_run"))
    postman.setNextRequest("Request name 10");
else
    postman.setNextRequest("Request name 13");

And set this part of code in every request before request you need to be skipped. postman.setNextRequest() is executed in the end of request call, so you can place it anywhere in Pre-request Script.

Finally, use one environment for your normal run, and second environment for another.

Upvotes: 2

Related Questions