Apidog

All-in-one Collaborative API Development Platform

API Design

API Documentation

API Debugging

API Mock

API Automated Testing

Sign up for free
Home / Tutorials / How to Install Newman and Run Postman Collections in Newman

How to Install Newman and Run Postman Collections in Newman

By following this guide, you will learn how to install Newman and execute Postman collections, enabling you to automate your API testing process. A recommend Apidog as a powerful alternative.

As an API developer, you are likely familiar with Postman, a popular tool for testing and automating API requests. Postman Newman has been a go-to tool for many developers for years, but it's not without its limitations.

In this guide, we will cover the installation and usage of Newman, a command-line tool designed to run Postman collections. By following this guide, you will learn how to install Newman and execute Postman collections, enabling you to automate your API testing process. A recommend Apidog as a powerful alternative.

What is Newman in Postman

Newman Postman is a command-line tool that allows developers to run Postman collections and environments in a continuous integration (CI) environment. Postman is a popular API development tool that allows developers to design, test, and document APIs. Newman, on the other hand, is a tool that allows developers to automate API tests using Postman collections and environments.

With Newman Postman, developers can easily automate API tests and ensure that their APIs are working as expected. Newman supports a range of integrations and plugins, making it a versatile tool for API development. However, there are some limitations to Newman Postman that developers should be aware of, such as its complexity to set up and configure slow test execution, and cost for large-scale use.

What is the Difference Between Newman and Postman

Postman and Newman are both API development tools, but they serve different purposes. Postman is a desktop application that allows developers to test APIs with a graphical user interface (GUI). Newman, on the other hand, is a command-line tool that allows developers to run Postman collections and environments in a continuous integration (CI) environment, making it easier to automate API tests.

Another difference between Postman and Newman is their cost. Postman has a free version but also offers paid plans with additional features. Newman, on the other hand, is an open-source tool that is free to use.

How to Run Postman Collection in Newman?

Installing Newman

Newman is built on Node.js. To run Newman, make sure you have Node.js installed. And Node.js >= v10. You can install Node.js with the package manager: https://nodejs.org/en/download/package-manager

Using NPM is  a common and easy way to install Newman. Input the following command in the terminal.

$ npm install -g newman

By using the "-g" flag, Newman will be installed globally on your system, enabling you to run it from any location.

Running Newman

You can use the "newman run" command to indicate which collection to run. It's simple to export your Postman Collection as a JSON file from the Postman App, and then execute it using Newman.

$ newman run mycollection.json

Recommended to Read:

How to Fix Postman Collection Limits for Free
There are several methods to fix Postman Collection Runner restrictions. However, creating your collection with Apidog has no limits and is free.

Bonus Tips of Postman Newman

Using Newman with CI/CD

Newman exits with a status code of 0 by default if everything runs smoothly without any exceptions. To ensure that your continuous integration (CI) tools respond to Newman's exit codes and pass or fail a build accordingly, you can configure them accordingly.

Additionally, you can use the "--bail" flag to make Newman stop the run if it encounters a test case error with a status code of 1. This error can then be picked up by your CI tool or build system and acted upon accordingly.

Using Newman as a Node.js library

Newman can also be used as a Node.js library, allowing developers to integrate API testing into their Node.js applications. By using Newman as a library, developers can programmatically run collections, access test results, and integrate testing into their build process.

const newman = require('newman'); // Import Newman module

async function runCollection() {
  try {
    await newman.run({
      collection: require('./sample-collection.json'),
      reporters: 'cli'
    });
    console.log('Collection run complete!');
  } catch (err) {
    console.error(err);
  }
}

runCollection();

This example code uses async/await syntax to make running Newman more concise and readable. It imports the Newman module and defines an asynchronous function named runCollection to run the collection. Within the function, it uses the await keyword to wait for Newman to finish running, and then prints a message indicating that the collection has been run. If an error occurs, it catches and prints the error. Finally, it calls the runCollection() function to run the entire program.

Postman Newman Alternative: Apidog

Apidog provides support for exporting test cases to Apidog CLI, Postman, and JMeter formats, making it easy to integrate API testing into your continuous integration process.

Apidog - An integrated platform for API design, debugging, development, mock, and testing
Download the Apidog API management tool here. Perfectly compatible with macOS, Windows, and Linux. Web version is also available.

The Apidog CLI is designed specifically for running Apidog test cases in the command line, providing a streamlined way to execute tests and automate the testing process. By exporting test cases to Apidog CLI, developers can easily integrate API testing into their build processes and ensure that APIs are tested thoroughly and consistently.

In addition to Apidog CLI, Apidog also supports exporting test cases to Postman and JMeter formats, providing developers with greater flexibility in their testing approach. With these export options, developers can choose the testing tool that best suits their needs and integrate API testing seamlessly into their development workflow.

How to Install Apidog CLI

Use the command below to install:

$ npm install -g apidog-cli

Running with Real-time Data

Go to the "testing"> "Test Scenario", open your desired API, click on Add New button on CI/CD page.

Then, Copy the generated command, and run it in the command line.

apidog run http://xxx/api/v1/api-test/ci-config/xxxx/detail?token=xxxx -r html,cli 

Running the Test cases

$ apidog run examples/sample.apidog-cli.json -r cli,html,json

The test report will be saved to the apidog-reports directory.

If you want to customize the report, you can use the result in a JSON file to customize the report as needed.

Conclusion

By following the steps outlined in this guide, you should now have a good understanding of how to install and run Newman to execute Postman collections. Newman provides a command-line interface that allows for automated API testing, making it a valuable tool for developers working in a continuous integration environment.

However, if you are looking for an alternative to Newman that offers a more robust CI/CD solution, I would highly recommend considering Apidog. In addition to its user-friendly interface for API testing and documentation, Apidog also provides powerful CI/CD functionality. With features like test case exporting, collaboration tools, automatic API documentation generation, and seamless integration with CI/CD pipelines, Apidog provides a comprehensive solution for API development and testing needs.

Whether you choose to continue using Newman or explore Apidog as an alternative, both tools can greatly enhance your API testing process. However, if you are looking for a more comprehensive solution with strong CI/CD functionality, Apidog is definitely worth considering.

Join Apidog's Newsletter

Subscribe to stay updated and receive the latest viewpoints anytime.

Please enter a valid email
Network error, please try again later
Thank you for subscribing!