Response Validations in Postman
Response Validations in Postman
Response Validations
Adding Tests
Status Code
Headers
Cookies
Response Time
Response Body
Body:
{
"id": 1,
"name": "John",
"location": "India",
"phone": "1234567890",
"courses": [
"Java",
"Selenium"
]
}
Tests:
//Testing Status Codes
pm.test("Status code is 200", () =>
{pm.response.to.have.status(200)});
//Testing Headers
pm.test("'Content-Type' header is present", ()=>
{pm.response.to.have.header("Content-Type");});
//Testing Cookies
pm.test("Cookie 'language' is present", ()=>
{pm.expect(pm.cookies.has('language')).to.be.true;});
1
Postman Tool
2
Postman Tool
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"location": {
"type": "string"
},
"phone": {
"type": "string"
},
"courses": {
"type": "array",
"items": [
{
"type": "string"
},
{
"type": "string"
}
]
}
},
"required": [
"id",
"name",
"location",
"phone",
"courses"
]
}
//JSON Schema validation
pm.test("JSON Schema is Valid", ()=>
{pm.expect(tv4.validate(jsonData,Schema)).to.be.true;});
3
Postman Tool