I have this GET and POST in same collection and even in the same folder.
At the end of GET tests I call the POST using this postman.setNextRequest(“EmailNotifier”);
but nothing happen, it doesn’t run the POST for sure (just to make clear, when I manually run it is working fine).
Unfortunately, without the rest of the code that you have, that line alone is a bit meaningless.
Could you provide the rest of the script and details of the rest of the collection please. The raw code would be better than a picture of it.
Before doing that, could you confirm that that you have no unsaved changes in the requests that you have open for that collection? The collection Runner won’t know about changes to the request unless you save it before the run.
In addition to what @danny-dainton said, if you’re just running the request out of the app, setNextRequest isn’t going to do anything.
postman.setNextRequest is going to tell the collection runner what the next request is to execute. If you’re not running a collection, it will do nothing.
Also, make sure that the value you have as the argument in setNextRequest is the name of the request you want to run.
No there isn’t. You could possibly call another request via the javascript in the tests section, but I don’t think that’s a very good workaround because the collection runner does this for you already.
But to check if it’s working I need to run the Runner instead of clicking the button.
And anyhow, I added single line postman.setNextRequest(“EmailNotifier”); in the first request “Tests” and I ran the Runner but still nothing happened, it did not run the second request “EmailNotifier”
Are you able to show us an image of what that flow looks like, what those requests look like, the names of the requests and what is the saved state of each one.
By not showing people what you have in front of you - saying “I doesn’t work” is not going to help
Worth reading this doc from our learning center and the points at the bottom as some might be relevant to what you’re seeing here.
Your conditional statement is evaluated to true in the first request (because it’s basically checking that you have a response body) and then it’s going to the Common request.
Correct but I want Req_2 also execute followed by common.then req_3 followed by common and then req_4 followed by common.
this is working on only Req_1
Inshort after running collection, I want 8 request should execute
Req_1
Common
Req_2
Common
Req_3
Common
Req_4
Common
Do you need to do it that way or would having an async call using pm.sendRequest() to that Common request, from the Tests tab work here?
Basically, it’s all example code at the moment and I have no idea what those requests are actually doing and why you need to keep hitting that Common request each time.
I’ve removed your same comment/question on the other topic, that was last active 3 years ago and you created this one for the same thing. Your question should have ideally been it’s own topic and not piggybacking on something that’s not exactly related.
Put the four requests in a folder or collection, and then add the common request into the tests tab of the folder or collection using sendRequest(). It’s more code, but isn’t that the essence of why you have a tests tab/pre-request scripts at the collection, folder and request level.
No setNextRequest involved. This will run after every request in the folder.
Option 2 would be to track the next request to be run after the common request in the tests tab of each of the requests.
So in Req-1, you would save an collection variable with the value of the Req_2 name and then use setNextRequest in Req-1 to call the common request.
In Req-2, you would update the value to show the Req-3 name.
In the tests tab of the common request, you would retrieve the previously saved variable and use that to drive the setNextRequest().
For request 4, you would set the value of this variable to “null” to end the flow.
Personally, I would recommend an update to setNextRequest() or a new feature that allows you to set the next two requests. Or a flag, that if set will allow you to call another request once and then continue running the tests in the current folder or collection. The first option would probably be easier to implement but the second would be more user friendly.
The idea here is that re-usable code or requests is a key factor for a lot of automated testing frameworks. If you have dozens of collections that use the same request\feature. You only need to update it in one place. Its one thing that Postman is missing as a concept.