Make Selenium Easy

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

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

1 thought on “Postman Tutorial Part 38 – Mostly Used Assertion Code Snippets in Postman to Achieve API Automation

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.

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

by Amod Mahajan time to read: 3 min
1
%d bloggers like this: