#Tutorial 4 : Response Validation
Status Code
Headers
Cookies
Response Time
Response Body
JSON Schema
Assertation – validation
PM : It is a Postman in-built library function Which is available in postman itself and which is
providing set a number of function to add validation points and those function are developed by
using JavaScript.
Chai Assertion Library :
[Link](“Test name”, Function ()
{
//Assertion
}
);
[Link](“Test Name” ,() =>
{
//Assertion
}
);
1. Testing status codes
Test for the response status code:
pm. test("Status code is 200", () =>{
pm. response. to. have. status (200);
});
If We want to test for the status code being one of a set, include them all in an array and use
one of
pm. Test ("Successful POST request", ()=> pm. expect(pm. response. code).[Link].
oneOf([201,202]);
});
Check the status code text:
pm. test("Status code name has string", () =>
pm. response. to. have. status("Created");
});
2. Testing headers
Check that a response header is present: // Content Type
pm. test("Content-Type header is present", () => {
pm. response. to. have. header("Content-Type");
});
Test for a response header having a particular value: // Content-type Value
pm. test("Content-Type header is application/json", () =>
{ [Link]([Link]('Content-Type')).[Link]('application/json; charset=utf-
8');
});
3. Testing cookies
Test if a cookie is present in the response:
pm. test("Cookie 'language' is present", () => { pm. expect(pm. cookies. has('language')).to. be.
true; });
Test for a particular cookie value:
pm. test("Cookie language has value 1", () => { pm. expect(pm. cookies. get('language')).to.
eql('en-gb');
});
4. Testing response times
Test for the response time to be within a specified range:
pm. test("Response time is less than 200ms", () => { pm. expect(pm. response. responseTime).
to . be. below (200);
});