Testing multiple cases for a request

You can create a loop by setting a collection variable with your test data and then using a pre-request script and the JavaScript array.shift() method to get the first record from the array. (The shift method also deletes that record from the array).

You can then retrieve the various elements from the current record and set them as collection variables to be used in the actual request.

You also need to re-save the updated array over the top of the existing collection variable (which should now have one less record).

In the tests tab. You retrieve the array again which will be used in an IF statement in conjunction with pm.setNextRequest() to keep running the same request while the length of the array is more than zero.

Please note that setNextRequest() still requires the collection runner to work. You can’t get this to loop without the collection runner. Both the CSV method and the setNextRequest() method require the collection runner.

Here are a few topics that are utilizing this method.

Simulating 100 users using Pre-Request and Tests - :person_raising_hand: Help - Postman Community

Loop through values from GET to next PUT request - :person_raising_hand: Help - Postman Community