Postman collections for API Testing
- kiruthika Sekar
- 26 minutes ago
- 4 min read
POSTMAN:
Postman is a popular tool for API development, testing, and debugging. It is an HTTP Client that tests HTTP requests. It allows us to verify API functionality, reliability, and performance. Postman can be used as an active desktop application or a web application.
A simple Analog:
Think of the Postman collection as a cookbook, each API request is a recipe. We follow the steps to cook, reuse them whenever needed, or share the cookbook with friends and family so they can cook(test).
Postman collections:
Postman collection is a group of saved API requests. Postman helps organize requests, collaborate with teams, and reuse variables. To create a new collection, go to the collection tab on the left side, and click +. We can name the collection for better understanding.

Features of Postman Collections:
Request Organization
API requests can be grouped together into collections. Collections can be exported, imported, or shared among other members. Using Folder we can further sub-group requests in collections. Postman lets us work on multiple requests in separate tabs, we can switch between requests and compare responses.

Variables
Variables are reusable values that can be used in API requests and scripts. Variables are defined using double curly braces {{VariablesName}}. Postman will replace it with the actual value.
Types of variables:
1. Environment variables
In Postman we can create a different environment, where we can create one or more variables for different works. On the top right corner, there is an eye icon, by clicking it we can create a new environment or select an already saved environment. Under the variable section, we can add variable name and value. The scope of environmental variables is to that particular environment. Store environment-specific variables like URL, and token.

2. Global Variables
Global variables can be used across all Workspace and Collections. It can be accessed by any request, collection, or environment across the entire collection. It is good practice to store the most commonly used variables in Global variables, like content type, static values, etc. To create a global variable, we have to go to the variable in the top right corner. Click edit and start adding variable names and values.

3. Collection variables
Collection variables can be used throughout particular collections. It is not affected by global or environmental variables. Collection variables can be shared without exposing global and environmental variables for security. We can add variables directly or we can add it through script. Below the example, I am extracting a token from the response and storing it in the collection variable.

Pre-request Scripts
In Postman, the pre-request tab will run before every request. These scripts can be added at the collection, folder, or individual requests level. They are commonly used for API chaining, where data from one request is used dynamically for another request. To add a Collection level pre-request script, go to your collection, select scripts then choose the pre-request tab.
Tests & Assertions
Postman allows us to write JavaScript-based test cases to validate API responses. These test scripts ensure API behaves the way it is expected. Postman uses the chai-assertion library. To write a test go to the test tab and in the post-response, we can write tests. The test script will run after the response is received for the request. The script validates the status code, content type, data type, and schema.

Data Files (CSV/JSON)
A data file is used to perform data-driven testing, Multiple sets of data can be used to test the same request. Postman supports two file types CSV (Comma-Separated Values) and JSON (JavaScript Object Notation). When using CSV, the first row should be a variable name and the other rows should be values. Whereas JSON is a key-value pair, the key is the variable name and the data is the value.

Version Control & Collaboration:
Version Control
Postman offers useful versioning features. Forking and Merging, Fork a collection to create a copy, make changes independently, and merge it into the original. When merging if there is a conflict, Postman shows a merge conflict viewer to help compare and resolve.
Collaboration
Postman helps teams collaborate effectively through team workspace. We can invite team members to a shared workspace, where we can view, edit, and run collections.
COLLECTION RUNNER
The Collection Runner in Postman allows us to run a set of API requests in a sequence, one after another automatically. After a change, if the API is not behaving the way we expect, we can re-run the collection thus great for regression testing and also saves time. We can also send data files to the collection runner.
Steps to use Collection Runner:
1. Select the three dots near the collection and choose Run.
2. We can choose to run manually, or runs can be scheduled.
3. Under Run Configuration, the number of times we want it to run can be chosen in Iteration.
4. Data files can be selected before running.

Start small and explore features step by step and you will be surprised to see how much postman can do.
Happy testing!