Different types of Asserts in Postman


There are different types of Asserts in Postman. We can add Assertions on different sections of the Response received. Some of the Assert types are listed below −

  • Assert on Response Code

pm.test["Status Code is 200"], function(){
   pm.response.to.have.status(200)
})

The above assertion passes if the Response code is 200.

pm.test["Status is OK"], function(){
   pm.response.to.have.property('status', ' OK')
})

The above assertion is applied on the Response property – status with value as OK.

  • Assert on Response time

pm.test("Response time below 600 milliseconds", function () {
   pm.expect(pm.response.responseTime).to.be.below(600)
})

The above assertion passes if the Response time is below 600ms.

  • Assert on Response Format

pm.test("Response is of JSON type ", function(){
   pm.response.to.be.json;
})

The above assertion passes if the Response is of JSON type.

  • Assert on Response Header

pm.test("Header Of Response", function () {
   pm.response.to.have.header("Content-Encoding")
})

The above assertion passes if the Response has a Content-Encoding Header.

  • Assert on Response Text

pm.test("Response", function () {
   pm.expect(pm.response.text()).to.include("Postman")
})

The above assertion passes if the Response includes the text Postman.

Updated on: 03-Aug-2021

250 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements