Distinguish collection run from individual request in test

Goal
I would like to distinguish between a collection runner request and an individual request using “Send” from within the test scripts.

Use case
For tests run with the collection runner, I pull data into the pre-request script from a predefined environmental variable, manipulate it, and then make an assertion on that data in the test script. When I run an individual request, I don’t want that data to be set in the pre-request script or for these tests to run.

One idea that I had was to see if I could differentiate these requests by checking if setNextRequest was defined in the collection runner and undefined in the individual request. I found that by console logging postman.setNextRequest() in the test script returned undefined in both cases.

I got this idea from the documentation: postman.setNextRequest() is intended for use when running a collection using the Collection Runner, the Postman CLI, or Newman. It has no effect when you run a request using Send .

Do you have a link to the documentation for the postman object itself, and/or an idea about how my goal to distinguish between them can be achieved?

Determining if a test was run from a Collection or Send - :person_raising_hand: Help - Postman Community

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.