Post

Azure DevOps | Running a Postman Collection using Newman Docker Image

Running a Postman Collection using Newman Docker Image

Newman is a command-line collection runner for Postman that allows you to automate and test your APIs. You can use the Newman Docker image to run Postman collections in a containerized environment.

Prerequisites

Before you begin, make sure you have Docker installed on your system.

Step 1: Pull the Newman Docker Image

Open your terminal and pull the Newman Docker image from Docker Hub using the following command:

1
docker pull postman/newman

Step 2: Create a Postman Collection

Create a Postman collection that includes the API requests you want to run. You can use the Postman app to create and export collections.

Step 3: Export Your Postman Collection

Export your Postman collection as a JSON file. You can do this by opening the collection in Postman, clicking the “Export” button, and selecting “Collection v2” or “Collection v2.1” as the export format.

Step 4: Run the Postman Collection using Newman

Use the Newman Docker image to run your Postman collection as follows:

1
docker run -t postman/newman run <path-to-collection-file.json> --env-var VAR1=Value1 --env-var VAR2=Value2
  • <path-to-collection-file.json>: Replace this with the path to the Postman collection JSON file you exported in step 3.

  • --env-var VAR1=Value1 and --env-var VAR2=Value2: If your collection relies on environment variables, you can set them using the --env-var flag.

Example

Here’s an example command to run a Postman collection named “my-api-tests.json” with environment variables:

1
docker run -t postman/newman run my-api-tests.json --env-var API_URL=https://api.example.com --env-var API_KEY=your-api-key

Additional Options

You can customize the Newman run using various Newman CLI options. For example, you can specify reporters, specify a folder for reports, and more.

What Next?

Using the Newman Docker image, you can easily automate the testing of your APIs by running Postman collections within a containerized environment. This is particularly useful for continuous integration and automated testing pipelines.

This post is licensed under CC BY 4.0 by the author.