Iterating only a single request inside a collection with test data specified in a csv file

I have a requirement where in there are 5 requests inside the collection.
I have a csv file where list of 100 test data rows are stored.
I want the first 4 request in the collection to be executed only once.
Whereas want the 5th request to be iterated 100 times as per the test data csv file…

I tried following but did not work…
I thought of keeping a collection level counter and then in the pre-request script of the first request…I tried putting a condition that if the counter is 0 then execute this request else set the postman.setNextRequest(“Fifth Request”)…
But, this did not work as setNextRequest is not allowed in the Pre-request script as per my understanding…

I cant think of any other solution…Any help will be really appreciated.
Thanks in advance,
Nishant Shah

You are on the right track. I would try it the opposite way you are suggesting.

Implement the counter in your collection variables like you said, but in the tests section of your fourth request, check the counter and use pm.setNextRequest('First Request') for your first 4 iterations.

You’re also going to need to set a flag to make sure your first 4 requests don’t run again on subsequent iterations. So here is what I would do:

  1. Add a bootstrapCollection variable in your collection
  2. Add a new request at the very beginning of your collection, to the postman echo endpoint
  3. In the tests of the postman echo request, check to see if the bootstrapCollection is true/false.
    a. If it is true, don’t do anything
    b. If it is false, use pm.setNextRequest('Fifth Request') so you skip over all the setup requests.
  4. Make sure you set bootstrapCollection to false in the last request of your setup requests

That should do what you want. Let me know if you need any clarification.

Cool, thanks @allen.helton for the quick answer.
In fact, few minutes back I ended up doing the exact same solution you suggested :slight_smile:
At the time of implementing this solution I was feeling a bit guilty as it felt a hacky solution to me…as had to introduce the postman test request at the top…
But, now that you also suggest the same solution, I am feeling a bit better :slight_smile:

I use those tests everywhere in my collections. Postman echo is great for resolving dynamic variables that you want to use in multiple requests.

I’ll hit the echo to resolve variables and story them off
Then I’ll post to add a new resource
Then I will get the added resource in another request and verify the contents against the variables from step 1

1 Like