Postman Tutorial Part 38 – Mostly Used Assertion Code Snippets in Postman to Achieve API Automation

When we hit any request in Postman, we should verify response code, response time , value of an attribute in response etc. These assertion helps to test the expected behavior of API. In this post, we will see some mostly used code snippets in Postman scripts to validate response.

Code snippet to assert status code of API:-

Code snippet to assert name of status code of API:-

Code snippet to assert if status code is from a list of expected status code:

Code snippet to assert by ignoring case:-

Code snippet to assert response time is below a value:-

Code snippet to assert response time is above a value:-

Code snippet to assert response time is between a range:-

Code snippet to assert response size is not zero:-

Code snippet to assert presence of a string anywhere in response:-

Code snippet to assert presence of a header in response:-

Code snippet to assert value of a response header:-

Code snippet to assert presence of a cookie:-

Code snippet to assert value of a cookie:-

Code snippet to assert response body is a JSON Object or JSON array:-

Code snippet to assert exact response body:-

Note:- JavaScript does not support multiline string. So you must need to use concatenation as shown above.

#ThanksForReading

Have you tested your Selenium knowledge ? Try below Selenium Quiz:-

Learn Selenium with Quiz

Be master in Selenium-WebDriver

API Testing – Basics

API Testing – Postman

API Testing – Rest Assured

Learn Protractor Step by Step

Frequently Asked Java Programs in Interview

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.
%d bloggers like this: