Skipping a test at the parent level

I have the following test defined at the parent level which runs for all tests.

pm.test('Parent response status code should be 200', function () {
    pm.response.to.have.status(200);
});

I temporarily have a page which gives a 404 and which I want to skip but not delete. Ideally I would be able to disable it but can’t see how to do that. So I tried the following pre-release script but it doesn’t work and still runs the test, which makes my monitor fail every day.

var testID = pm.info.requestName;
console.log(testID);
if(testID == "Calendar") {
    postman.setNextRequest(null);
};

Is there a way I can either disable/skip my test until such a time as it will work and I can reenable it?

You could edit the parent test like this and it will skip if the status code is 404:

let skipTest = pm.response.code === 404;

(skipTest ? pm.test.skip : pm.test)("Parent response status code should be 200", () => {
    pm.response.to.have.status(200);
});

2 Likes

That would work, only problem is I want to know if the other tests give a 404. This particular one is because there is no data. I suppose I could set an extra response variable in some way to distinguish it?

Yeah this has a downside of skipping a request that you don’t want, like someone changing the route of a certain other endpoint and you wouldn’t capture that issue here as it would be skipped.

You could pair it with the requestName ?

let skipTest = pm.response.code === 404;

(skipTest && pm.info.requestName === "Calendar" ? pm.test.skip : pm.test)("Parent response status code should be 200", () => {
    pm.response.to.have.status(200);
});

So that will legit fail if the other requests give a 404 response as the name wouldn’t match and fail the condition.

You could even change the assertion slightly to also tell you the request name in the failed assertion:

let skipTest = pm.response.code === 404;

(skipTest && pm.info.requestName === "Calendar" ? pm.test.skip : pm.test)("Parent response status code should be 200", () => {
    pm.expect(pm.response.code, `Request Name: ${pm.info.requestName}`).to.equal(200);
});

Cool, yeah that works. When the endpoint is working again I’ll just have to remember to turn the test back on.

1 Like