Reading https://learning.postman.com/docs/collections/running-collections/building-workflows/ it states that setNextRequest can be used in pre-request or test scripts. I have included a call to it in a function defined in the pre-request script for the collection but called in the Tests script, butit doesn’t seem to have an effect. Is this the expected behaviour?
In the pre-request script for the collection I have
and then in the Test for each request I call the method. IT is executed but when it executes the setNextRequest(null) it continues to execute requests.
The abbreviated example is within the pre-request script of the collection to make it common reusable code. I call the function testResponseSpecifyResponseCode from the Tests script in each request. However, the call to postman.setNextRequest(null) doesn’t stop the remaining request in the collection being executed. However if I add postman.setNextRequest(null) into the Tests script it does.
From what I can see and the little local version of your code I had running, you need to also pass in the postman arg into the function. Just like you have with the pm arg.