Using postman.setNextRequest() within a pre-request script of a folder dosn't appear to do what I think it should do

I have a couple of requests in a folder, and I am using a CSV data file to run the folder multiple times; however, only the second request needs to be run on the 2nd and subsequent iterations (i.e. the first request is only run in the first iteration). To achieve this I tried the following code in a pre-request script of the folder, such that:

iterationCount = pm.info.iteration;
console.log(iterationCount);
if (iterationCount > 0){
    postman.setNextRequest("My_2nd_request");
}

I am aware that if the postman.setNextRequest function is placed in the pre-request script of a request, then this is still called AFTER the current request finishes (Building request workflows | Postman Learning Center). I had thought that as this was within the folder, then this will be action before ANY request is made. However, the first request is still called at the beginning of each iteration.

What am I missing?

Ok, I think I get it.

The pre-request script of the folder is simply something that will run before every request in the folder run, and the rules regarding the postman.setNextRequest function still apply - i.e. that it will run AFTER the current request finishes. This means that it looks like the first request MUST complete before the postman.setNextRequest function takes effect (so you cannot skip the first request at all).

I have just come across Iterating only a single request inside a collection with test data specified in a csv file - #6 by nishant.shah2, and in this topic, they used a dummy request as the first request. Iā€™m unsure if this is the best option, but it works.

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