DEV Community

Hassan BOLAJRAF
Hassan BOLAJRAF

Posted on

2

Azure DevOps | Running a Postman Collection using Newman Docker Image

Note
You can check other posts on my personal website: https://hbolajraf.net

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:

docker pull postman/newman
Enter fullscreen mode Exit fullscreen mode

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:

docker run -t postman/newman run <path-to-collection-file.json> --env-var VAR1=Value1 --env-var VAR2=Value2
Enter fullscreen mode Exit fullscreen mode
  • <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:

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
Enter fullscreen mode Exit fullscreen mode

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.

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay