Reputation: 159
I'm designing a fairly simple collection, with two services in the collection:
I've managed to get the token from service #1 and set it into a variable, and use said token in Request #2. I then use a csv file in Runner to call service #2 using different arguments.
What I'm trying to achieve is to run service #1 only once, instead of running as many times as the number of lines on the CSV. Is it possible?
Upvotes: 0
Views: 452
Reputation: 651
setNextRequest() aka 'goto' should never be used in any structured language. That is putting control level functionality into individual tests and will lead on day 1 to spaghetti code. Some basics on collections and variables in Postman and Newman that I find make things easier:
Yes, this means running multiple collections, but that's ok because you'll eventually have multiple .csv files for multiple kinds of tests anyway.
I put all my shared functions (today(). todayPlus1Week(), etc) with my Auth so all the global vars that get used later eg. {{today}}, {{tomorrow}}, {{todayPlus1Week}} get set exactly once, but also can be refreshed will a simple call by any request if for example you have a huuuge data set and it will take a long time to run.
For examples of this, google "postman utils examples" or start here: How to Write Global Functions in Postman
Upvotes: -1
Reputation: 3434
You can use postman.setNextRequest("request #2");
in the Tests script of request #2 to skip the execution of request #1 after the first run.
But you also need to add a condition to only do that while pm.info.iteration is smaller than your amount of required executions to avoid an endless loop.
Upvotes: -1