Essential tool: Postman Newman explained in detail

Table of contents

What is Postman Newman?

Postman Newman's role

How to use Postman Newman?

Step 1: Install Node.js

Step 2: Install Newman globally

Step 3: Export collections or environment variables to JSON format

Step 4: Run the test using Newman

Step 5: Export the report

How to obtain information


What is Postman Newman?

Postman Newman is a CLI (command line interface) tool that can be used to run Collections and Environments in Postman for automated testing. It is Postman's command line Collection Runner, capable of running Postman collections directly from the command line. Newman can be used to test the functionality, performance, reliability and security of APIs, and the test results can be output into reports in multiple formats, such as HTML, JSON , JUnit, etc., to facilitate problem location and analysis by developers.

Postman Newman's role

Through automated testing with Postman Newman, developers can quickly get feedback on API performance after code changes and ensure code stability. Newman can be integrated with CI (Continuous Integration), if any changes are pushed, CI will run the Postman collection together with Newman to ensure the stability of the environment. Newman can also be used to test various aspects of the API, such as functionality, performance, reliability, and security, helping developers find and solve problems.

How to use Postman Newman?

Here are the steps for testing with Postman Newman:

Step 1: Install Node.js

Newman is built on Node.js, so you need to install Node.js before using Newman. Please make sure Node.js is installed, Node.js v4 or higher is recommended.

Step 2: Install Newman globally

Use npm to install Newman globally. You can install it with the following command:

npm install -g newman

Step 3: Export collections or environment variables to JSON format

Use Postman to export Collection or environment variables into JSON format files, which are required when using Newman. You can export the file by following these steps:

  • Collection: Select the Collection to be exported, click the "Export" button in the upper right corner, select "Collection v2.1", and save it as a JSON file.
  • Environment variables: Select the environment variables you want to export, click the "Export" button in the upper right corner, select "Environment", and save it as a JSON file.

 

Step 4: Run the test using Newman

To run the test collection using Newman, use the following command:

newman run <collection.json> -e <environment.json> -r <reporter> --reporter-<option> <value>

where collection.json is the path to the collection file, environment.json is the path to the environment variable file, reporter is the report format, and --reporter-[option] [value] is the report options and values.

Step 5: Export the report

Newman provides three formats of reports, including CLI, JSON and HTML formats, which can be  -r specified through parameters:

  • CLI format: basic format, default report format displayed in cmd;

 

  • JSON format: To  -r json export the corresponding file by specifying, you need to  --reporter-json-export specify the storage path of the exported file. The file content is similar to the export result content in Postman Runner and is not recommended.
  • HTML format: To  -r html export the corresponding file using specified, you need to  --reporter-html-export specify the storage path of the exported file. It needs to be installed before use ( npm -g install newman-reporter-html), it is recommended to use.

For example, you can run  sample-collection.json the test cases in the collection and generate an  report.html HTML report called. The following commands can be used:

newman run sample-collection.json -e environment.json -r html --reporter-html-export report.html

This will generate an HTML report file named  report.html.

The above are the basic steps for testing using Postman Newman. If you need more advanced testing, you can check out Newman's documentation and examples for additional features and options.


How to obtain information

【Message 777】

Friends who want to get the source code and other tutorial materials, please like + comment + collect , three times in a row!

After three consecutive rounds , I will send you private messages one by one in the comment area~

Guess you like

Origin blog.csdn.net/GDYY3721/article/details/132259729