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

Hi @vaibhav.sh.05 ,
Basically, the logic here is to find out a way such that you can compare a flag and on the basis of its value jump to a specific request (fifth request in our case) OR in other words on the basis of the value of the flag skip the execution of first four request…

First thought that comes to our mind is to have this flag comparision in the Pre-request script of the very first request, e.g.
Request1 → Pre-request Script :- Do something like this:
if (iterationCount > 1){
postman.setNextRequest(“NameOfYourFifthRequest”);
}

But, unfortunately, setNextRequest is not supported in the Pre-request Script of a request. You can do that only in the Test tab. However, doing this in the Test tab of your first request wont solve our purpose…Right?

So, the solution here is to use a dummy request as your first request. Add this comparision logic in the test tab of this dummy request instead of the First Request.

Where to find this dummy request ??
Postman has several echo endpoints which are dummy requests. You can use one of those GET echo endpoint as your first request.
I remember of having Postman Echo collection by default when I launched postman for the first time. If you dont find it in your case then you can easily find it online in postman docs… https://learning.postman.com/docs/developer/echo-api/
So, the sequence of request in your collection will look like :-

  • Postman GET Echo
  • Req1
  • Req 2
  • Req 3
    …
    …

In the Test tab of Postman GET Echo :-
if (iterationCount > 1){
postman.setNextRequest(“NameOfYourFifthRequest”);
}

Also, now you dont need to create a Collection Variable to maintain the count of iteration. Postman has an inbuilt counter for iterations :slight_smile:
It can be accessed by :- pm.info.iteration

I hope the solution is clear now.

2 Likes