Open LennonRuangjaroon opened 7 years ago
There's not currently an easy way to do that, but I like the idea. I could add something like an abort()
function that would skip any remaining tests and stop the collection.
Great request. I've been thinking of adding this as a feature request myself.
Have had to face down this problem and have found the following hack:
1) Create a do-nothing script (Say simply GET google) that executes before all others with the following in pre-request: pm.environment.set("post_exec_script", "MyPostExecScript");
2) Create another do-nothing script that is the last file in your collection/folder
3) In your test, have the following function at the top:
function testWrapping(message, testFunc) { var testPassing = false;
pm.test(message, function () {
var innerTestRes;
try
{
innerTestRes = testFunc();
testPassing = typeof(innerTestRes) === "undefined" ? true : innerTestRes;
}
catch(ex)
{
throw ex;
}
return innerTestRes;
});
if(!testPassing)
postman.setNextRequest(pm.environment.get("post_exec_script"))
return testPassing;
}
4) Call it like this and it will drop out of execution of any more tests & subsequent requests:
if(!testWrapping("response is ok", function () { pm.response.to.have.status(200); }) ) return;
FYI - If you pass null
to the postman.setNextRequest()
function, it will automatically terminate the collection run. So there's no need to create a do-nothing request just to pass to setNextRequest()
Yup, a null is probably better if you want to just fail a whole collection. I only need it the fail on folder scope and to attempt the next group of requests though so included this approach :)
When some test failed.I would like to terminate the script. Can I terminate next test?
` eval(globals.postmanBDD);
describe('Get customer info', () => {
}); `