这期内容当中小编将会给大家带来有关如何使用Newman,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

Newman是postman命令行集成工具,使用Newman可以在命令行中运行postman的脚本,方便与Jenkins等CI&CD工具集成使用,今天我们来看看Newman的使用讲解,主要内容包括Newman的安装、基本使用、常用运行参数、生成报告等等。

Newman的安装:

postman是由nodejs开发的,命令行newman为node.js的第三库,所以要安装newman,首先要安装node.js环境。

下载安装node.js https://nodejs.org/en/

命令行验证node版本

$ node -v

v12.13.0

安装newman

https://www.npmjs.com/package/newman

在命令行中输入

npm install newman -g

<备注:> 安装比较慢 设置下载地址

npm config set registry=https://registry.npm.taobao.org

如果脚本运行过程中出现问题 安装 4.0.0 版本

npm install -g newman@4.0.0

基本使用:

运行基本脚本

$ newman run examples/sample-collection.json

常用运行参数:

-h, --help

查看版本信息

-v, --version

显示当前版本

运行时参数:

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

-e <source>, --environment <source>

环境变量,在postman中定义的局部环境变量的值导出的文件路径。

-g <source>, --globals <source>

全局环境变量,在postman中定义的全局环境变量的值导出的文件路径。

-d <source>, --iteration-data <source>

数据文件,存放数据参数的csv文件路径。

-n <number>, --iteration-count <number>

迭代运行测试,类似在postman runner中设置的执行的次数。

--folder <name>

执行目录,如果在postman的cellection中创建的有folder,执行的folder名字。

生成报告:

-r <reporter-name>, --reporters <reporter-name>

生成测试报告的数据格式。

后面支持的参数: cli, json, junit, progress and emojitrain.

可以跟多个测试报告格式。

✅ -r cli,json,junit

❌ -r cli , json,junit

JSON Reporter:

JUNIT/XML Reporter:

HTML Reporter:

借助第三方库可以生成html格式的报告,首先在命令行中进行安装。

$ npm install -g newman-reporter-html

安装成功后 使用

--reporters html

上述就是小编为大家分享的如何使用Newman了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。