0

I am inserting data in postman. I want to apply validation from post method in test script. I am new to postman, I am not able to understand.

Here is the JSON.

{
  "firstname": "pradeep",
  "lastname": "tiwari",
  "mobile_no": 9911844349,
  "email": "pradeep@gmail.com",
  "user_type": 4,
  "password": "pradeep1",
  "confirmPassword":"pradeep1",
  "dob":"nanana",
  "u_org":25,
  "isfoundingpartner":"undifine",
  "gender":1
}
Divyang Desai
  • 7,483
  • 13
  • 50
  • 76
pradeep
  • 3
  • 5

2 Answers2

0

You can use built in snippets for starters to validate your basic response messages. https://learning.getpostman.com/docs/postman/scripts/test_examples/

Arslan Ahmed
  • 52
  • 1
  • 6
  • thanks for reply I am getting a response: { "result": { "code": 200, "status": true, "message": "User successfully registered" } } I want to show response “Message” in “Test Results” how i do that – pradeep Aug 23 '19 at 09:49
  • pm.test("Body matches string", function () { pm.expect(pm.response.text()).to.include("string_you_want_to_search"); }); Just use this and print whatever result you want to print in Test. – Arslan Ahmed Aug 23 '19 at 13:15
  • let result = pm.response.json().result; if(result.status === false){ pm.test(result.message) } else{ pm.test(result.message) } thanks for helping @Arslan i use this and i got what i want – pradeep Aug 23 '19 at 13:38
0

In order to carry out validation on your responses, you will first need to parse the data into a JavaScript object using below

var jsonData = pm.response.json();  

You can use the below code to check for particular values in the response body

 pm.test("Verify Json values", function () { 
  pm.expect(jsonData.firstname).is.to.equal("pradeep"); 
  pm.expect(jsonData.lastname).is.to.equal("tiwari"); 
    pm.expect(jsonData.gender).is.to.equal(1); `
});




 
Vega
  • 27,856
  • 27
  • 95
  • 103
Tahera Firdose
  • 161
  • 1
  • 3