This article is an extension of Postman unboxed - part 1 (https://www.numpyninja.com/post/postman-unboxed-variables-tests-environments-and-chaining-explained-part-1) and we’ll grow our existing collection to
Include workspaces, Visualize json response, create flowcharts and utilize mockservers.
Collection Runner
Postman’s Collection Runner simplifies the test process by allowing user to verify multiple requests sequentially in different environments. For this we have to configure and run a collection of requests using the built in collection runner.
We can choose an existing collection and streamline by customizing the execution order to verify the test results as per real time usage and to quickly identify the errors.
Newman
Collections can also be run via installing Newman using npm (node package manager) that runs our collection via command line to generate and verify the request execution and test results
Install Newman: npm install -g newman
Export collection as a JSON file and Run Newman with the command:
newman run actualpath/collection.json
if your collection uses environment variables, make sure to provide the corresponding environment file using the -e option.
If your collection includes data-driven tests, you can use the -d option to specify a data file for multiple iterations.
-r option specifies reporters for generating different types of reports.
After running Newman, it will display detailed information about the run, including the number of requests, assertions, and response times.
Postman monitors:
For more advanced automation and scheduling, Postman Monitors come into play. They enable users to run collections at scheduled intervals and verify test results automatically. Monitors are perfect for continuous testing and monitoring the health of your APIs over time.
We can configure the monitor settings by providing the name for the monitor, choosing the environment we want to use and custom schedule. Also additional settings such as delaying the start of the monitor, stopping on the first failure, or running iterations in random order is available.
What are workspaces and how to use them
Workspaces help you to organize your Postman work and collaborate with teammates. You can group your projects together, with workspace acting as the single source for related API’s.
Personal workspaces are visible only to the user. With a Postman account users can create unlimited workspaces. With team workspaces, users can invite team members , share changes in real time and manage access to project components with collaborators.
To collaborate directly to the collection but not make any changes in the collection we can create forks in the same workspace and integrate back to the original collection by creating pull request or merging the changes based on the permission provided
Creating a fork | Creating pull request |
Visualize json response
In some cases when there is too much data it is difficult to find a particular data. In postman we have the option to visualize the data which will help to view the data in a graphical format.
Scenario:
As a user I want to visualize the data in tabular format.
//create a variable template to render a table
var template = `
<table bgcolor="#FFFFFF">
<tr>
<th>Name</th>
<th>Email</th>
<th>Type</th>
<th>Available</th>
</tr>
{{#each response}}
<tr>
<td>{{id}}</td>
<td>{{name}}</td>
<td>{{type}}</td>
<td>{{available}}</td>
</tr>
{{/each}}
</table>
`;
//set visualizer
pm.visualizer.set(template, {
// Pass the response body parsed as JSON as `data`
response: pm.response.json()
});
Flowcharts
Postman flows is a visual tool for creating API workflows. You can use flows to chain requests, handle data and create real-world workflows in your postman workspace
The start block is the first block found in every Flow. We can then call our requests with each block selecting from the existing collections and upon success we can call another request thus creating a Flow. Users can also extract data from a request to feed to another request. So when we ‘Run’ our flow, Postman kicks off the start block and will process the following requests sequentially as per the flow. You can also log the results to the console. This is useful for debugging Flows and ensuring your Flow is running with the expected information.
Mockservers
Mockservers allows us to create/simulate fake API endpoints .
Mock servers imitate to be the real API providing us with some responses to our request but it will not process anything in the backend. Mock servers are commonly used in the earliest part of the design cycle. This helps the developers and testers start work in parallel, working against the expected response of the API
User can create a new collection and add an initial request and response and then save url as an environment variable to be used in mockserver
Users can also select an existing collection and save requests as ‘Save as Example’ and Postman uses these items to decide which responses the mock server returns. In the below image we have included date in 'save as example' and received as response when executed with mock server URL
Postman Limitations
These robust features simplify the entire process of building and sharing APIs for developers. When it comes to API testing, especially automation testing
Postman has considerable limitations nonetheless:
Limited testing area. While Postman is ideal for RESTful API tests, it is not well designed for SOAP APIs and other APIs.
Low script reusability. Postman users are unable to reuse their pre-written scripts or add more requests. This means testers have to create new test scripts over and over for each project.
Constrained integration. While APIs enable the Agile process, the tool itself does not support much in integration capabilities. It becomes an obstacle in connecting Postman with the existing systems and collaborating within the team.