How to stop all request in Collection Runner on any error?

In Pre-request Script tab I set a few variables, based on the REST API answers (pm.sendRequest()).
For some situation the error is returned, so I cannot continue next iterations.
How can I stop all future steps, whole Collection Runner? On Tests tab I’ve tried set postman.setNextRequest(null) but it does not work. Can I do this from Pre-request Script?
This How to stop Collection Runner on error? does not work for me.

Kind regards

@dracorp without your code as an example, it is hard to say why it did not work.

But notice in the example from the post you reference, the steps are contained within the same pm.test node. The node will perform everything in sequence, and it will only set the postman.setNextRequest(); after a successful 200 status. If 200 status fails, then the next request is still null and it stops.

Based on what you mention, does your ( pm.sendRequest() ) node contain the setting of the variables after success? or are those contained in a separate request node?

(It is also possible that this requires a certain version if postman?? I am on version 7.32.0

pm.test(“Status code is 200”, function () {
//convert to json format
var RespData = xml2Json(responseBody);
//set environment level variable
pm.environment.set(“PolicyNumber”, RespData[‘OnlineData.autoSaveDataRs’][’$’][‘policyNumber’]);
//return policy number in test tab

1 Like

Hi @dracorp,

To stop the execution, you can throw an error in your pre-request script.

throw new Error('halt');

That should stop execution of the request and the collection run.



1 Like

Hi @kclausing and @kevin.swiber
It, throw new Error, stops Pre-request Script but not the whole collection. Tests are omitted.
This is good but not enough.

Not great, not terrible