Reputation: 121
I get a postman collection contains request A,B,C. When I run with multiple iterations (e.g. 3 iterations), I should ensure the request A is executed only for the first iteration and the request B & C is executed for each iteration, like this:
iteration #0 - request A
iteration #0 - request B
iteration #0 - request C
iteration #1 - request B
iteration #1 - request C
iteration #2 - request B
iteration #2 - request C
I tried postman.setNextRequest() in pre-request of the request A but it cannot skip itself and it only takes effect to next request.
I believe this scenario is very common and a typical example is that Request A generate a long-life token code which will be used by following requests/iterations.
Does anyone have an idea? Appreciated!
Upvotes: 2
Views: 967
Reputation: 121
remove request A from collection
add this section in pre-request of request B
if (pm.info.iteration === 0) { pm.sendRequest({ url: 'https://url', method: 'POST', header: { 'Content-Type': 'application/json', }, body: { mode: 'raw', raw: JSON.stringify({ "a": "a_value" }) } }, function (err, res) { postman.setEnvironmentVariable("mytoken", res.json().token); }); }
Upvotes: 0
Reputation: 191
You can try the solution below to see if this solves your problem.
request_A_ran_already
. Let that code be in an if condition which checks the environment if the long life token is already created, if yes, that flow will be skipped. Remember to save that long life token in environment/global variables. You'll need to persist it if you want to do operations based on it later.Let me know if this works for you, comment if you have any doubt regarding this.
Upvotes: 2