A Comprehensive Guide to Using Postman for API Testing and Automation for QA

Max Kombarov
4 min readOct 7, 2023

--

In the world of Quality Assurance (QA), efficient testing of APIs is crucial. Postman is a powerful tool that allows you to create, organize, and automate API testing. This guide will walk you through the process of using Postman for creating collections, exporting them, running tests with Newman, and generating reports, both manually and through CI/CD automation.

Section 1: Creating Collections in Postman

1.1 — Installing Postman:

1.2 — Creating a Collection:

  • Open Postman.
  • Click on the “New” button in the top left corner.
  • Give your collection a name and description.
  • Click “Create.”

1.3 — Adding Requests to Your Collection:

  • In your collection, click “Add Request.”
  • Fill in the request details, including the URL, request type, headers, and parameters.
  • Click “Save.”
  • It’s also crucial to learn and use Postman query params, path variables, variables specific for the environment and the collection, and the power of environments itself, and also to know what are pre-request scripts, tests, and collection runs. You can also learn more about Postman in their great Learning Centre.

Section 2: Exporting Collections

2.1 — Exporting Collections Manually:

In this tutorial, we will use exported collections to run with the free Postman terminal tool Newman, which is very handy with automatic test runs and reports generation in your everyday QA work. So,

  • To manually export a collection, click on the collection name.
  • In the top-right corner, click the ellipsis (…) and choose “Export.”
  • Select the format (e.g., JSON) and save the file.

Section 3: Running Tests with Newman

3.1 — Installing Newman:

  • If you haven’t already, install Newman globally by running npm install -g newman in your terminal.

3.2 — Running Collections with Newman:

  • Use the following command to run a collection:
newman run [collection file path]
  • Replace [collection file path] with the path to your exported collection.
  • You can also run the collection with iterations. For example, to check the percentage of successful test executions and failures for flaky tests detection. Run the Newman with the -n option and fill in the number of iterations you want to run your collection. But be careful with failed test runs. It is advised to debug your tests manually in Postman first and run tests, especially with iterations, only for finishing experiments to avoid overloading the Sentry code monitoring system with error and message logs, which can harden error detection for the developers team. Lol.
newman run [collection file path] -n 10
  • You can also run the collection in separate environments.
newman run [collection file path] -e [environment file path]

[environment file path]: The path to the environment file that you want to use for the collection run. This file should be in JSON format.

  • To run a specific folder in Newman, you can use the --folder flag followed by the folder name. Here's an example command:
newman run [collection file path] --folder [folder name]

Make sure to replace [collection file path] with the path to your collection file and [folder name] with the name of the specific folder you want to run.

For example, if your collection file is located at /path/to/collection.json and you want to run the folder named "Tests", the command would be:

newman run /path/to/collection.json --folder Tests

This will run only the requests within the “Tests” folder of your collection.

Section 4: Generating Reports

4.1 — Using Built-in Reporters:

  • Newman provides built-in reporters like CLI, HTML, and JSON. You can also use our favourite progress, and emojitrain. And, yes, tests also can smile😄 or cry 🥲 at their failures.
  • To generate a report in CLI, simply run the Newman command. It runs by default in the terminal.
  • For other formats, specify the reporter using the -r flag, e.g.,
newman run [collection] -r html.
  • You can also run a few reporters in order by using newman run [collection] --reporters cli,progress,htmlextra. Each terminal report will be displayed on the screen and each file report will be created after the Postman collection Newman run execution.

4.2 — Custom Reporters:

Section 5: Automation with CI/CD

5.1 — Integrating Postman and Newman into CI/CD:

  • You can incorporate Postman collections and Newman scripts into your CI/CD pipeline.
  • Use tools like Jenkins, Travis CI, GitLab, or GitHub Actions to automate testing.
  • The script for CI/CD collection execution in the pipeline can be exported and modified if required from Run >Run on CI/CD > Generate Postman CLI Configuration right away from Postman collection.

The follow up article API Testing Automation with Postman, Newman and CI/CD in Jenkins.

Conclusion

Mastering Postman and Newman for API testing and automation is a valuable skill for any QA engineer. This guide covers the basics of creating collections, exporting them, running tests with Newman, and generating reports, both manually and through CI/CD automation.

Happy testing! 😄

--

--