QA Interview Hub · Knowledge base · Quizzes · Українська

API › Runner, data-driven tests and Newman

Newman or Postman CLI: what to choose for CI

Newman runs only an exported v2.1 JSON and is no longer updated, while the Postman CLI is the recommended tool for running collections in CI. The CLI opens collections from the cloud and the v3 format, runs packages and has a built-in HTML report. An existing Newman step is migrated by checking flags and reporters (--folder becomes -i) and by not enabling -x, which hides failures.

A nightly collection run in CI has worked on Newman for years. Then the team moves to the Git-based collection format and adds shared packages to scripts, and the step fails: Newman understands neither the new format nor packages. This is not a breakage but the limit of a tool, so the choice between Newman and the Postman CLI is worth making deliberately.

What the Postman docs say. Newman is described as an open-source tool that no longer receives updates and fixes: the docs advise replacing it in scripts and CI with the Postman CLI, and that CLI is called the recommended tool for running collections locally and in CI/CD. So for a new pipeline the choice is usually clear, and the question arises with existing steps.

Comparison by substance.

  • Where the collection comes from. Newman runs an exported JSON in the v2.1 format (a file or a link with an API key). The Postman CLI runs a collection by ID from the cloud after sign-in or by a path to a local file; the v3 format from Local View, which the Git mode needs, cannot be run by Newman but can by the Postman CLI. The CLI shows the results of a local run in the terminal and sends them to Postman only when you are signed in and the collection is run by ID or linked to a cloud collection (Native Git);
  • Sign-in and key. Newman needs no account. For the CLI, sign-in is needed to run cloud collections and send results: postman login, the --postman-api-key option or the POSTMAN_API_KEY variable. In CI the key comes from secrets;
  • Packages. The contents of Package Library packages imported with pm.require do not run in Newman; the Postman CLI runs them in collection runs and monitors, but running a collection with packages requires a Solo, Team or Enterprise plan;
  • Reports. An HTML report in Newman needs a separate reporter package, in the CLI it is built in: -r html. The CLI has the cli, json, junit and html reporters, but for collections in the v3 format (YAML: HTTP, gRPC or GraphQL) and for collections with Kafka requests only cli is available, so a pipeline that needs JUnit still runs a v2.1 collection for now;
  • Capabilities. Newman only runs collections. The Postman CLI also supports monitors, mock servers and other Postman features, and publishes local changes to the cloud.

Migration: where it breaks. Most flags match: -e, -g, -d, --bail, -r. The differences people run into: --folder becomes -i, the CLI has no --export-environment, --export-globals and --export-collection options, and the HTML reporter no longer needs a separate package.

# before
- run: npm i -g newman newman-reporter-htmlextra
- run: newman run api.postman_collection.json -e stage.postman_environment.json --folder Smoke -r cli,htmlextra

# after
- run: npm install -g postman-cli
- run: postman login --with-api-key "${{ secrets.POSTMAN_API_KEY }}"
- run: postman collection run api.postman_collection.json -e stage.postman_environment.json -i Smoke -r cli,html

Exit code. Like Newman, the CLI exits with a non-zero code when a check fails, and the CI step turns red. The -x flag (suppress exit code) makes it exit with 0 even when tests fail: do not enable it in CI because it masks a failure. Both tools have -x, so it is easy to carry over with the rest during a migration.

How to choose.

  • A new pipeline, or a collection in the Git v3 format, packages, monitors: the Postman CLI;
  • An existing Newman pipeline with a v2.1 collection and no packages: it works, but the tool has no updates: plan the migration without waiting until it becomes urgent;
  • The collection lives in a cloud workspace and the current version is always needed: the CLI by ID without an export;
  • A run without an account, for example in a fork or an environment without secrets: a local file and Newman, or the CLI without signing in.

Common mistakes.

  • Carry the command over and not check the reporters: the JUnit or HTML report the pipeline waits for is missing;
  • Leave -x after debugging: the step is green while tests fail;
  • Run a collection with pm.require in Newman: imports do not work, and the failure looks like a script error;
  • Put the API key into the repository instead of CI secrets.

Check yourself

A collection with pm.require passes in the Postman app, but the nightly step with newman run fails. What to do?

Answer

The contents of packages do not run in Newman. Run the collection through the Postman CLI (mind the plan that allows packages); rewrite the scripts without packages only if the step has to stay on Newman.

After the migration to the Postman CLI CI turned green although some collection tests fail. Where to look for the cause?

Answer

Most likely -x (suppress exit code) got into the command, or a wrapper such as || true swallows the exit of the command. Without them a non-zero exit code fails the step.

In an interview. Junior: Newman and the Postman CLI run a collection from the command line and return a non-zero code when a test fails; the CLI is Newman's successor. Senior: for a new pipeline I take the Postman CLI because Newman gets no updates and does not handle the v3 format and packages; an existing Newman step I migrate by checking flags and reporters and not enabling -x.

More articles in this chapter