Check response header's value in Postman tests

Lluís Suñol picture Lluís Suñol · Mar 13, 2018 · Viewed 17.1k times · Source

I would like to check the value from a concrete response header ("Location") as Test Results in Postman. In the Postman's documentation I found examples of how to check the existance of headers with

pm.test("Content-Type is present", function () {
   pm.response.to.have.header("Content-Type");
});

But what I'm looking for is something like

pm.test("Location value is correct", function () {
   CODE HERE THAT CHECKS "Location" HEADER EQUALS TO SOMETHING;
});

Answer

Lluís Suñol picture Lluís Suñol · Mar 13, 2018

I finally found the solution:

pm.test("Redirect location is correct", function () {
   pm.response.to.have.header("Location");
   pm.response.to.be.header("Location", "http://example.com/expected-redirect-url");
});