Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman Tests: Assert several possible response statuses

When testing in Postman, you can use pm.response.to.have.status(200) to assert that the response status should be 200.

Is there any simple way to assert multiple statuses? I tried pm.response.to.have.status(200||404) and it didn't work.

I'm looking at the Postman Sandbox API Reference and there doesn't seem to be a straightforward solution for this, although maybe something can be worked out.

Since it's rather bizarre, I'll explain why I want this: it's a DELETE request that will standardize the database for later requests and I don't care which is returned as long as it's either 200 or 404.

like image 687
JoseHdez_2 Avatar asked Dec 23 '22 12:12

JoseHdez_2


1 Answers

(It's OK to Ask and Answer Your Own Questions)

Found an example in the test examples:

pm.test("Successful POST request", function () {
    pm.expect(pm.response.code).to.be.oneOf([201,202]);
});

in my case, it would be something like

pm.test("Previous DELETE request", function () {
    pm.expect(pm.response.code).to.be.oneOf([200,404]);
});
like image 53
JoseHdez_2 Avatar answered Jan 14 '23 00:01

JoseHdez_2