Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check response header's value in Postman tests

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; }); 
like image 297
Lluís Suñol Avatar asked Mar 13 '18 09:03

Lluís Suñol


1 Answers

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"); }); 
like image 74
Lluís Suñol Avatar answered Oct 03 '22 22:10

Lluís Suñol