I have to run my collection on two different Country levels so I have my iteration set up as one iteration for one country, but some of the end points are not country specific and need not have to run twice.
Is there a way I can avoid running certain end points only once in the runner based on iteration.
You can use postman.setNextRequest(<request name>) to skip over requests in the collection runner. As long as you know what data triggers a different workflow you can skip over requests that way.
I’m happy to provide you an example if you provide some more details on what your flow is and what data would cause you to skip over some requests.
So I have about 40 requests in my runner but out of which about 15 are generic ones and not country specific. I cannot group them together as they are spread across in specific order and need to be in that way.
The iteration is based on country level so for example one iteration is for UK and the second one is for US.
So using postman.setNextRequest() as it is doesnt help , I will need to make it specific for iteration count if possible. Like run this request if the iteration count is 1 or something like that.
Given the criteria you mentioned, and @allenheltondev’s recommendation, what you can do is create an iteration counter in your pre-request script (or test script if thats better), and store that count as a Postman Variable (global or environment).
Then, you can check for the iteration count variable in your test script, and depending on that count, you can execute the pm.setNextRequest(<request name or request ID>) to execute the request that should follow.
Can you try using the request ID instead of the request name? I have had better luck there. You can get the request ID by exporting the collection, and searching for the request ID in the collection json file.
Also, try a “==” instead of a “===”. If my memory serves me correctly, === implies object equality, but not value equality.
You can also get access to the current iterations data by using the special “data” variable.
The data variable will have a JSON representation of the current line in your CSV.
So you can target the Test_ID column using…
if (data.Test_ID === 1) {
// do something
}
Are you sure you want to use sendRequest and not setNextRequest()??
setNextRequest just sets the next request that will run after all of the code in pre-request scripts, the current request, and the code in the various tests tab have run. It won’t just run test case 1 or 4. The current request will still run. sendRequest is something completely different.
To avoid any confusion, I would therefore recommend providing more details on the flow you are trying to achieve. (By raising your own issue with all of the details in). If you paste code, please use the preformatted text option in the editor to stop all of the code aligning to the left.