Perform validations and execute tests in a workflow

Welcome you all to the brand new ‘API Testing’ blog series! In the previous blog, we had studied how to execute POST requests in Postman. We also studied how to chain GET and POST requests. In this tutorial, we will learn how to perform some validations. We will also learn how to execute all the tests in a single workflow!! So let us begin!!! 

1. What you will Learn in this blog?

  • Perform ‘status code 200’ validation
  • Perform string validation
  • Execute all the tests in a collection as a single workflow

2. Perform ‘status code 200’ validation

Let us open the ‘POSTwithParams’ request from our collection

Hit ‘Send’ and notice below that 200 status code is generated

Let us see how to validate this status code.

Go to the ‘Tests’ section of this Post request

On the right hand side, under snippets, look for

Status code: Code is 200

Click this snippet.

Notice below, a function is generated to validate the status 200

Click ‘Send’

Go to the ‘Test Results’ section as shown below. We would see that our Test is ‘PASS’ 

We can also rename our ‘Test’ as shown below

Click ‘Send’.

Notice below the ‘Test’ is PASS and the new test name is displayed viz ‘Validate Status code’

Let us intentionally change status code 200 to 201 in our code snippet as shown below

Click ‘Send’

Notice below that this time our ‘Test’ got failed and we get an assertion error. The assertion error simply means that we are expecting status code of 201 but the actual status code that we received from the server is 200. Hence our validation faied this time

3. Perform string validation

Let us now see how to perform string validation. If we go to the ‘Body’ of this Post request (see below), we can see some string values in the body (“country”: “India”)

How do we validate these strings?

To validate strings, we have a snippet

Response body: Contains string

Click this snippet and notice below that one more function gets generated

Let us replace “string_you_want_to_search” with “India”

Click Send.

Notice below that the validation ‘Body matches string’ is PASS

4. Execute all the tests in a collection as a single workflow

Currently, we have 4 requests in our collection

Let us see how to execute all of these 4 requests as a single workflow. 

But before we do that, let us add ‘200 status’ validations in the 2 GET requests

Save all the requests by clicking Save button

Close all the requests in the Workspace

Click collection

On the right hand side, we will see ‘View more actions’ represented by 3 dots.

Click these 3 dots, we will see the ‘Run’ option

Click Run.

See below. We can select/de-select the checkboxes for the requests we want to run

Leave all the options as default and click ‘Run APIRequestsCollectionHttp…’

The below window comes up showing 3 Passed and 1 Failed Test

As expected, below 3 Tests Passed

As expected, the below Test failed

Click ‘View Summary’

Notice below that we get a run summary which is self-explanatory

So this is how we perform validations and execute the tests as workflows.

In the next article, we will see how to handle cookies in postman.

Thank you for reading!


Tags


You may also like

API Basics and Architecture

API Basics and Architecture
Leave a Reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}