-1

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 endpoints are not country-specific and need not have to run twice.

Is there a way I can avoid running certain endpoints only once in the runner based on iteration?

I tried this way by adding an Iteration Count column in my data.csv

if (pm.iterationData.get(“Iteration Count”) === 1) {
  postman.setNextRequest(‘request name1’);
} else {
  postman.setNextRequest(‘request name2’);
}

but it didn't help.

wscourge
  • 10,657
  • 14
  • 59
  • 80
Uthara
  • 1
  • 3
  • Please add collection structure , request , body screen shots and also explain how request for country1 and country2 differs . SetNextRequest executes only after the request in which it is defined even if it is set in prerequest . – PDHide Dec 11 '20 at 04:39

1 Answers1

0
pm.info.iteration

gives the current iteration number (starts as 0 )

if (pm.info.iteration === 0) {

postman.setNextRequest(‘request name1’);

} else {

postman.setNextRequest(‘request name2’);

}

Also in postman ,you can modify everything in postman through pm object

So you can change pm.request.url

pm.request.body

Etc

SetNextRequest doesn't skip current request , it will get executed after current request is completed.

So what you can do is add a preparation script and do

postman.setNextRequest(null) this will ensure there is no next request after executing the current execution , add this to the two main request

and in preparation request add

postman.setNextRequest("country1")

Else 

postman.setNextRequest("country2")

Please add the request structure and collection structure so that we can give more correct answer

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • This is now resolved with the below in Pre req. if(“value” == pm.iterationData.get(“fieldname”)) { postman.setNextRequest("Next request"); } Thank you. – Uthara Dec 11 '20 at 10:53
  • Sorry iteration starts from 0 , so first iteration is 0 and last iteration is n-1 – PDHide Dec 14 '20 at 15:35