newman

newman

Postman命令行集合运行工具

Newman是Postman的命令行集合运行工具,可从命令行直接运行和测试Postman集合。它易于集成到CI服务器和构建系统中,支持多种报告格式,可作为CLI工具或Node.js模块使用,并提供丰富配置选项。Newman适用于自动化API测试和持续集成场景。

NewmanPostmanAPI测试命令行工具自动化测试Github开源项目

<a href="https://www.postman.com/"><img src="https://assets.getpostman.com/common-share/postman-logo-horizontal-320x132.png" /></a><br /> Manage all of your organization's APIs in Postman, with the industry's most complete API development environment.

newman <sub>the cli companion for postman</sub> Build Status codecov

Newman is a command-line collection runner for Postman. It allows you to effortlessly run and test a Postman collection directly from the command-line. It is built with extensibility in mind so that you can easily integrate it with your continuous integration servers and build systems.

Table of contents

  1. Getting Started
  2. Usage
    1. Using Newman CLI
    2. Using Newman as a Library
    3. Using Reporters with Newman
  3. Command Line Options
    1. newman-options
    2. newman-run
    3. SSL
    4. Configuring Proxy
  4. API Reference
    1. newman run
    2. Run summary object
    3. Events emitted during a collection run
  5. Reporters
    1. Configuring Reporters
    2. CLI Reporter
    3. JSON Reporter
    4. JUnit Reporter
    5. HTML Reporter
  6. External Reporters
    1. Using External Reporters
    2. Creating Your Own Reporter
  7. File Uploads
  8. Using Newman with the Postman API
  9. Using Newman in Docker
  10. Using Socks Proxy
  11. Migration Guide
  12. Compatibility
  13. Contributing
  14. Community Support
  15. License

Getting started

To run Newman, ensure that you have Node.js >= v16. Install Node.js via package manager.

Installation

The easiest way to install Newman is using NPM. If you have Node.js installed, it is most likely that you have NPM installed as well.

$ npm install -g newman

This installs Newman globally on your system allowing you to run it from anywhere. If you want to install it locally, Just remove the -g flag.

Using Homebrew

Install Newman globally on your system using Homebrew.

$ brew install newman

back to top

Usage

Using Newman CLI

The newman run command allows you to specify a collection to be run. You can easily export your Postman Collection as a json file from the Postman App and run it using Newman.

$ newman run examples/sample-collection.json

If your collection file is available as an URL (such as from our Cloud API service), Newman can fetch your file and run it as well.

$ newman run https://www.getpostman.com/collections/631643-f695cab7-6878-eb55-7943-ad88e1ccfd65-JsLv

For the complete list of options, refer the Command Line Options section below.

terminal-demo

Using Newman as a Library

Newman can be easily used within your JavaScript projects as a Node.js module. The entire set of Newman CLI functionality is available for programmatic use as well. The following example runs a collection by reading a JSON collection file stored on disk.

const newman = require('newman'); // require newman in your project // call newman.run to pass `options` object and wait for callback newman.run({ collection: require('./sample-collection.json'), reporters: 'cli' }, function (err) { if (err) { throw err; } console.log('collection run complete!'); });

For the complete list of options, refer the API Reference section below.

Using Reporters with Newman

Reporters provide information about the current collection run in a format that is easy to both: disseminate and assimilate. Reporters can be configured using the -r or --reporters options. Inbuilt reporters in newman are: cli, json, junit, progress and emojitrain.

CLI reporter is enabled by default when Newman is used as a CLI, you do not need to specifically provide the same as part of reporters option. However, enabling one or more of the other reporters will result in no CLI output. Explicitly enable the CLI option in such a scenario. Check the example given below using the CLI and JSON reporters:

$ newman run examples/sample-collection.json -r cli,json

For more details on Reporters and writing your own External Reporters refer to their corresponding sections below.

back to top

Command Line Options

newman [options]

  • -h, --help<br /> Show command line help, including a list of options, and sample use cases.

  • -v, --version<br /> Displays the current Newman version, taken from package.json

newman run <collection-file-source> [options]

  • -e <source>, --environment <source><br /> Specify an environment file path or URL. Environments provide a set of variables that one can use within collections. Read More

  • -g <source>, --globals <source><br /> Specify the file path or URL for global variables. Global variables are similar to environment variables but have a lower precedence and can be overridden by environment variables having the same name.

  • -d <source>, --iteration-data <source><br /> Specify a data source file (JSON or CSV) to be used for iteration as a path to a file or as a URL. Read More

  • -n <number>, --iteration-count <number><br /> Specifies the number of times the collection has to be run when used in conjunction with iteration data file.

  • --folder <name><br /> Run requests within a particular folder/folders or specific requests in a collection. Multiple folders or requests can be specified by using --folder multiple times, like so: --folder f1 --folder f2 --folder r1 --folder r2.

  • --working-dir <path><br /> Set the path of the working directory to use while reading files with relative paths. Default to current directory.

  • --no-insecure-file-read<br /> Prevents reading of files situated outside of the working directory.

  • --export-environment <path><br /> The path to the file where Newman will output the final environment variables file before completing a run.

  • --export-globals <path><br /> The path to the file where Newman will output the final global variables file before completing a run.

  • --export-collection <path><br /> The path to the file where Newman will output the final collection file before completing a run.

  • --timeout <ms><br /> Specify the time (in milliseconds) to wait for the entire collection run to complete execution.

  • --timeout-request <ms><br /> Specify the time (in milliseconds) to wait for requests to return a response.

  • --timeout-script <ms><br /> Specify the time (in milliseconds) to wait for scripts to complete execution.

  • -k, --insecure<br /> Disables SSL verification checks and allows self-signed SSL certificates.

  • --ignore-redirects<br /> Prevents newman from automatically following 3XX redirect responses.

  • --delay-request<br /> Specify the extent of delay between requests (milliseconds).

  • --cookie-jar <path><br /> Specify the file path for a JSON Cookie Jar. Uses tough-cookie to deserialize the file.

  • --export-cookie-jar <path><br /> The path to the file where Newman will output the final cookie jar file before completing a run. Uses tough-cookie's serialize method.

  • --bail [optional modifiers]<br /> Specify whether or not to stop a collection run on encountering the first test script error.<br /> Can optionally accept modifiers, currently include folder and failure.<br /> folder allows you to skip the entire collection run in case an invalid folder was specified using the --folder option or an error was encountered in general.<br /> On the failure of a test, failure would gracefully stop a collection run after completing the current test script.

  • -x, --suppress-exit-code<br /> Specify whether or not to override the default exit code for the current run.

  • --color <value><br /> Enable or Disable colored CLI output. The color value can be any of the three: on, off or auto(default).<br/> With auto, Newman attempts to automatically turn color on or off based on the color support in the terminal. This behaviour can be modified by using the on or off value accordingly.

  • --disable-unicode<br /> Specify whether or not to force the unicode disable option. When supplied, all symbols in the output will be replaced by their plain text equivalents.

  • --global-var "<global-variable-name>=<global-variable-value>"<br /> Allows the specification of global variables via the command line, in a key=value format. Multiple CLI global variables can be added by using --global-var multiple times, like so: --global-var "foo=bar" --global-var "alpha=beta".

  • --env-var "<environment-variable-name>=<environment-variable-value>"<br /> Allows the specification of environment variables via the command line, in a key=value format. Multiple CLI environment variables can be added by using --env-var multiple times, like so: --env-var "foo=bar" --env-var "alpha=beta".

  • --verbose<br /> Show detailed information of collection run and each request sent.

SSL

Client Certificates

Client certificates are an alternative to traditional authentication mechanisms. These allow their users to make authenticated requests to a server, using a public certificate, and an optional private key that verifies certificate ownership. In some cases, the private key may also be protected by a secret passphrase, providing an additional layer of authentication security.

Newman supports SSL client certificates, via the following CLI options:

Using a single SSL client certificate

  • --ssl-client-cert<br/> The path to the public client certificate file.

  • --ssl-client-key<br/> The path to the private client key (optional).

  • --ssl-client-passphrase<br/> The secret passphrase used to protect the private client key (optional).

Using SSL client certificates configuration file (supports multiple certificates per run)

This option allows setting different SSL client certificate according to URL or hostname. This option takes precedence over --ssl-client-cert, --ssl-client-key and --ssl-client-passphrase options. If there is no match for the URL in the list, these options are used as fallback.

Trusted CA

When it is not wanted to use the --insecure option, additionally trusted CA certificates can be provided like this:

  • --ssl-extra-ca-certs<br/> The path to the file, that holds one or more trusted CA certificates in PEM format

Configuring Proxy

Newman can also be configured to work with proxy settings via the following environment variables:

  • HTTP_PROXY / http_proxy
  • HTTPS_PROXY / https_proxy
  • NO_PROXY / no_proxy

For more details on using these variables, refer here.

back to top

API Reference

newman.run(options: object , callback: function) => run: EventEmitter

The run function executes a collection and returns the run result to a callback function provided as parameter. The return of the newman.run function is a run instance, which emits run events that can be listened to.

ParameterDescription
optionsThis is a required argument and it contains all information pertaining to running a collection.<br /><br />Required<br />Type: object
options.collectionThe collection is a required property of the options argument. It accepts an object representation of a Postman Collection which should resemble the schema mentioned at https://schema.getpostman.com/. The value of this property could also be an instance of Collection Object from the Postman Collection SDK.<br /><br />As string, one can provide a URL where the Collection JSON can be found (e.g. Postman Cloud API service) or path to a local JSON file.<br /><br />Required<br />Type: object|string PostmanCollection
options.environmentOne can optionally pass an environment file path or URL as string to this property and that will be used to read Postman Environment Variables from. This property also accepts environment variables as an object. Environment files exported from Postman App can be directly used here.<br /><br />Optional<br />Type: object|string
options.envVarOne can optionally pass environment variables as an array of key-value string object pairs. It will be used to read Postman Environment Variables as well as overwrite environment variables from options.environments. <br /><br />Optional<br />Type: array|object
options.globalsPostman Global Variables can be optionally passed on to a collection run in form of path to a file or URL. It also accepts variables as an object.<br /><br />Optional<br />Type: object|string
options.globalVarOne can optionally pass global environment variables as an array of key-value string object pairs. It will be used to read Postman Global Environment Variables as well as overwrite global environment variables from options.globals. <br /><br />Optional<br />Type: array|object
options.iterationCountSpecify the number of iterations to run on the collection. This is usually accompanied by providing a data file reference as options.iterationData.<br /><br />Optional<br />Type: number, Default value: 1
options.iterationDataPath to the JSON or CSV file or URL to be used as data source when running multiple iterations on a collection.<br /><br />Optional<br />Type: string
options.folderThe name or ID of the folder/folders (ItemGroup) in the collection which would be run instead of the entire collection.<br /><br />Optional<br />Type: string|array
options.workingDirThe path of the directory to be used as working directory.<br /><br />Optional<br />Type: string, Default value: Current Directory
options.insecureFileReadAllow reading files outside of working directory.<br /><br />Optional<br />Type: boolean, Default value: true
options.timeoutSpecify the time (in milliseconds) to wait for the entire collection run to complete execution.<br /><br />Optional<br />Type: number, Default value: Infinity
options.timeoutRequestSpecify the time (in milliseconds) to wait for requests to return a response.<br /><br />Optional<br />Type: number, Default value: Infinity
options.timeoutScriptSpecify the time (in milliseconds) to wait for scripts to return a response.<br /><br />Optional<br />Type: number, Default value: Infinity
options.delayRequestSpecify the time (in milliseconds) to wait for between subsequent requests.<br /><br />Optional<br

编辑推荐精选

即梦AI

即梦AI

一站式AI创作平台

提供 AI 驱动的图片、视频生成及数字人等功能,助力创意创作

扣子-AI办公

扣子-AI办公

AI办公助手,复杂任务高效处理

AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!

Keevx

Keevx

AI数字人视频创作平台

Keevx 一款开箱即用的AI数字人视频创作平台,广泛适用于电商广告、企业培训与社媒宣传,让全球企业与个人创作者无需拍摄剪辑,就能快速生成多语言、高质量的专业视频。

TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
蛙蛙写作

蛙蛙写作

AI小说写作助手,一站式润色、改写、扩写

蛙蛙写作—国内先进的AI写作平台,涵盖小说、学术、社交媒体等多场景。提供续写、改写、润色等功能,助力创作者高效优化写作流程。界面简洁,功能全面,适合各类写作者提升内容品质和工作效率。

AI辅助写作AI工具蛙蛙写作AI写作工具学术助手办公助手营销助手AI助手
问小白

问小白

全能AI智能助手,随时解答生活与工作的多样问题

问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。

热门AI助手AI对话AI工具聊天机器人
Transly

Transly

实时语音翻译/同声传译工具

Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。

讯飞智文

讯飞智文

一键生成PPT和Word,让学习生活更轻松

讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。

AI办公办公工具AI工具讯飞智文AI在线生成PPTAI撰写助手多语种文档生成AI自动配图热门
讯飞星火

讯飞星火

深度推理能力全新升级,全面对标OpenAI o1

科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。

热门AI开发模型训练AI工具讯飞星火大模型智能问答内容创作多语种支持智慧生活
Spark-TTS

Spark-TTS

一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型

Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。

下拉加载更多