postman test json items code example

Example 1: responce json snippet check postman

pm.test("Status code name has string", () => {
  pm.response.to.have.status("Created");
});

Example 2: what to test in response body

Basicall we are checking response body
to verify if request matches with response.
In the response we are verifying
(body, status code, header, response time,
 test structure of json against the given jsonSchema)
 
 
If file not under resources: 
File schemaFile = new File("src/test/resources/postSuccessResponseSchema.json");

     given()
        .spec(adminReqSpec)
        .contentType(ContentType.JSON)
        .body(abcUtil.getRandomHeroPOJO_Payload()).
     when()
        .post("/HEROS").
     then()
        .body(matchesJsonSchema( schemaFile )  ) 
        
        
If schema file under resources:
  given()
      .spec(adminReqSpec)
      .queryParam("nameContains","a")
      .queryParam("gender","Female").
  when()
      .get("/abc/search").
 then()
 	  .time( lessThan(2000L));	
      .body(matchesJsonSchemaInClasspath("searchSpartanSchema.json") )

Tags:

Misc Example