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 [options]
-e , --environment
环境变量,在postman中定义的局部环境变量的值导出的文件路径。
-g , --globals
全局环境变量,在postman中定义的全局环境变量的值导出的文件路径。
-d , --iteration-data
数据文件,存放数据参数的csv文件路径。
-n , --iteration-count
迭代运行测试,类似在postman runner中设置的执行的次数。
--folder
执行目录,如果在postman的cellection中创建的有folder,执行的folder名字。
生成报告:
-r , --reporters
生成测试报告的数据格式。
后面支持的参数: 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的使用讲解,大家都掌握了吗?更多精彩内容尽在博学谷资讯,欢迎大家继续关注~