Stop request from sending if pre-request test fails

Is there any way to prevent the request from sending due to a failed test in the pre-request script?

I’ve tried making the test a function and returning false, postman.setNextRequest(null) (which didn’t seem to even set the request to null anyway) and throwing an error. Nothing seemed to work.

Any ideas? Much appreciated. Iain

1 Like

@cocovan See Controlling the execution of current request in pre-request script

1 Like

@kunagpal - thanks. I’ve actually managed to get it to work - maybe not as gracefully as I wanted - by doing the following:

if (pm.variables.get("STR_ENTITY").toLowerCase() !== pm.variables.get("ENTITY").toLowerCase()) {
    console.error("Entity values do not match");
    throw new Error("Entity values do not match");
}

This throws an error for each iteration in the run so my users will need to go and look in the console to see what’s going on, but I’ve achieved the result I wanted.

@cocovan: this doesn’t work for me. My request is still sent even if the pre-request fails and throws the error. Anything else you did, to get it to work?

this doesn’t work for me also.
At postman UI - OK, with newman - NOK.