I'd like to trigger a new request automatically if a postman test fails. Currently, in each request I have about 30 tests running based on what I'm expecting in the request's response. Test Example:
pm.test("YES",() => {
var yes = pm.response.json().eligibility_results.filter(obj => {
return obj.benefit == "YES"
})
pm.expect(yes[0].result).to.eql("eligible")
});
Now, If anything else other than the string "eligible" results for this object, the test will fail. I'd like to write a script that tells postman if one of the 30 tests come back as a failure (not expected) a new request will automatically be initiated.
I've tried:
pm.test("Check for failures", () => {
if (pm.expect().not.eql("")) {
(pm.sendRequest("New Request"))
}
else {
pm.sendRequest(null)
}
})
Also tried:
pm.test("Check for failures", () => {
if (pm.expect(pm.response.result()).not.eql) {
(pm.sendRequest("New Request"))
}
else {
pm.sendRequest(null)
}
})
I seem to be missing something here. The tests are giving me a PASS in the Test Results but it isn't initiating a new separate request. Any options?
Maybe a Post-Request if there is such a thing...
Any help greatly appreciated.