nifepo
(NIFEPO)
1
I have this simple test at collection level
tests["Status code is 200"] = responseCode.code === 200;
It will work perfectly for every request on the collection except for negative tests (400/403/404 http code response).
So ideally, at request Get Acommodation Type - 403 level I would like to write following test:
pm.SkipCollectionTest
tests["Status code is 200"] = responseCode.code === 403;
Is this somehow possible? Thank you
Hey @nifepo
Welcome to the Postman community!
This kinda sounds like a question that’s been asked before - Would this solution help you to get closer to what you need:
nifepo
(NIFEPO)
3
Hello, it helped but didn’t solve it. I couldn’t find a direct way of skilling a collection level test.
However, it made me think that I can do an if statement to expect 200 to every request that:
- Has Prefer header with code=400
Can you help me to write this test?
pm.test(“Prefer header is present”, function () {
pm.request.to.have.header("Prefer")
});
pm.request.to.have.header(“Prefer”) -------------> It correctly validate the header exists, but I also need to validate the REQUEST header VALUE.
Any idea how to write it correctly?
Thanks
nifepo
(NIFEPO)
4
Solved.
I will add below code as an IF statement at collection level.
pm.test(“Prefer header is present”, function () {
pm.request.to.have.header("Prefer", "code=400")
});