Open In App

How to Add Test Validation in Postman and Performing Get Request?

Last Updated : 15 May, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Postman is one of the most widely used applications for API testing, which provides testing for various types of HTTP requests like GET, POST, PUT and DELETE. Also, the postman provides automation testing by performing tests in several iterations using Newman or collection runner.

Download and Install the Postman

Postman is an open-source application and it can be easily installed on any platform. Open this link and download the Postman according to your system architecture and operating system.

 

After the download is completed click on run and install. In the end, signup for the postman.

Creating Test validation for the GET Request

First we have to create a workspace. For creating a workspace click on the workspace tab and click on create a workspace.

 

Now give the name for the workspace and select the visibility.

 

After creating the workspace, now add the collection to that workspace. Click on the ‘+’ icon 

 

Now add the GET request to the collection.

 

For the GET requests use this URL https://reqres.in/api/users/2 this request will return the JSON data

 

Adding Test Validation

Go to the Tests tab on the request page.

 

Now write the tests for validating the GET request:

Let us consider an example for writing a test to this GET request, we have to check the response code is 200, and check the response body has the first name “Janet” present.

tests[“Validate Status Code”] =responseCode.code==200;
tests[“Validate First name”]=responseBody.has(“Janet”);

After the tests are written, run the collection to see the result.

 

Select the number of iterations to run the tests.

 

In the end, we get the output with the result of the test.

 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads