postman.setNextRequest is not executed

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?

Updated with several pictures

The request test:

The collection runner view:

The result:

Hey @bjoho

Welcome to the community!!

Can you share an image of the full view including the tabs and the name of the next request that you’re going too after this one.

The image and explaination is a very limited piece of information and would need expanding on more to know what’s going on here.

I have added some more pictures. The behaviour is “as if” the request where run the postman application.

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.

1 Like

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.

Was starting to fear that. Would need something like waitForResponse() to force synchronism i guess? Thx

Nope, just as simple as this to go from REQ 1 -> REQ 3 -> REQ 5 -> End execution

  • REQ 1
    In Tests Tab:
    postman.setNextRequest("REQ 3")

  • REQ 3
    In Tests Tab:
    postman.setNextRequest("REQ 5")

  • REQ 5
    In Tests Tab:
    postman.setNextRequest(null)

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

1 Like

Glad you have it working. :trophy:

Feel free to submit a feature request over on our issue tracker:

Things tend to get lost in here and it’s not really the official way to submit enhancements. :grin:

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)