Postman snippets

To assert

pm.test("text available", function () { 
pm.expect(pm.response.text()).to.include("text"); }); 

To set variable from json response

var jsonData = pm.response.json();
pm.variables.set("Authorization",jsonData.Authorization); 


 To check the status code
pm.test("Status code is 200", function () {
 pm.response.to.have.status(200); 
}); 

To check the response body

 pm.test("response must be valid and have a body", function () {
 pm.response.to.be.withBody; 
 pm.response.to.be.json; }); 

To check the response time

 pm.test("Response time is less than 200ms", function () { pm.expect(pm.response.responseTime).to.be.below(500); 
}); 

To check the status code string

pm.test("Status code name has string", function () 
{ pm.response.to.have.status("OK"); 

});

To check response body

pm.test("SUCCESS MESSAGE IN Response", function () { pm.expect(pm.response.text()).to.include("SUCCESS"); }); 

To parse jason response
const responseJson = pm.response.json(); 

Assertion Statement

 pm.test("checking status as success", () => {
 pm.expect(responseJson.status).to.eql("SUCCESS"); }) 
 pm.test("checking message as null", () => {
 pm.expect(responseJson.message).to.eql(null); }) 

 Parsing Json value 

bodyData = JSON.parse(responseBody); value = bodyData.responseData; console.log(value); pm.environment.set("bearer token", value.authorization);

Comments

Popular Posts