Simple steps to use Postman tool for automating API testing using the collection and dynamic data in file

Rohan Hemnani
Tech x Talent
Published in
4 min readAug 14, 2021

--

Postman is a standalone software testing API platform to build, test, design, modify, and document APIs. It is a simple Graphic User Interface for sending and viewing HTTP requests and responses.

We will be using the Postman tool to automate multiple test cases for one of the AWS REST API that we built earlier which returns language code based on the input text passed.

We have one AWS language detection API that leverages AWS Comprehend Services and returns language code with x-api-key as authentication header as shown below:

For a detailed description of AWS REST API with x-api-key and usage plan that returns language code, follow my previous post: https://medium.com/geekculture/api-key-and-usage-plan-integration-with-aws-api-gateway-2d07bbb9a2a4

So, here in REST API, we have the below dynamic fields that will be required to execute API successfully:

  1. API
  2. Headers (x-api-key value will be dynamic as it could get change based on different deployments)
  3. request

Below fields will be required to test the execution of the API:

  1. response
  2. response status code

Here we will create one CSV file, and add all these fields as columns and their respective values to test multiple API cases and their required responses.

So, the CSV file will look something like this:

Now, we will create a Postman Collection step by step to use this CSV file and generate a test case report.

Note: Please use the latest Postman tool version as the older version does not support or fully utilize testing capabilities.

STEP 1: Create a New request in Postman and use curly braces to define the fields that have been used in the CSV file as shown below:

Step 2: Save the API request by creating the new collection as shown below:

Step 3: Create variables in Collection by clicking on the edit button in Collection with all the fields mentioned in the CSV file as shown below:

Step 4: Now we have to write the test cases for API in the Tests tab in the Postman console. Postman uses the pm library and Javascript to run and test the code written in the Tests tab.

You can check the postman learning page where the test scripts are explained very nicely in detail: https://learning.postman.com/docs/writing-scripts/script-references/test-examples/

Here, we have used two simple test cases:

  1. To test if the API response status code is equal to our API response status code in CSV file.
  2. To test if the API response body data is equal to the one in CSV file.

Step 5: Now final step will be to run the Postman Collection and pass the CSV file as a parameter to the collection from the console.

As we have used 7 iterations of data in a CSV file, so postman will run all the requests one by one and will check the test cases that we have written.

Click on the Run method which will open the new tab:

As shown below, click the select file button and attach the CSV file, then click on the Run Language Detection button and wait for all the test cases to be executed.

It will look something like this when the execution will be in progress:

So, after the execution will complete you can see the detailed report of test cases that failed and passed in the console. Also, you can print and check the console logs for the API request/response.

This is the best and easiest way to utilize the Postman tool to automate multiple test cases for API.

You can also use Pre-request Script to set the environment or collection variable before API execution according to the requirement.

I have uploaded this postman collection and CSV file for reference in GitHub https://github.com/Rohan009/PostmanTestAutomation. You can change the data in a CSV file and can execute it.

I hope this article in some way was useful to you :)

--

--

Rohan Hemnani
Tech x Talent

Full Stack Developer | Programmer | AWS | Enthusiast learner