I have studied previous related solutions without solving my problem.
In the collection runner i have one request selected. In the test code of that request i have a setNextRequest as shown in the picture. The console messages are written, but the setNextRequest is not executed. No error or anything. Any advice?
It looks like you have unsaved changes in the tab so anything that you have recently added, will not be reflected in the new collection run, until these are saved.
In your test code you have multiple setNextRequest statements, this would only execute the last one, you will need to add in an if statement if you wanted certain ones to run if a condition is meet.
Also, in other to use that setNextRequest option, the next request needs to be checked in the run list or it will only run the one that you have selected.
Sorry for the edit mark. I selected the other requests involved and the “Delete Company” request was executed twice. So it seems that the last setNextRequest is indeed executed. My intent is to execute a list of requests from a script. Isn’t that possible?
Not like that within a single script, you would need to add those other setNextRequest statements in the other requests, in order to chain them together.
I’ve tried it with success. For me it would be great to be able to compose different flows (scenarios) reusing from a set of basic requests. Thx again
Hi Bjoho,
There’s a number different ways you could implement what you need now, (although they may be a little clunky). But it’s possible, and you can get as complicated as you like using scripts in the collection.
A relatively easy one would be use a data input file that contains an array of the request names in the order you wish to execute them, and then to write a collection level script that fetches the next request name from the array and uses it in the call to postman.setNextRequest(…).
I think there might even be some examples documented on the postman community, just have a hunt around. (reply if you get stuck)