是postman测试集合运行的插件工具,运行的对象是测试集合。
1、安装
安装nodejs,是newman的基础环境。
cmd--->npm -v
安装newman工具:
cmd ---> npm install -g newman@5.2.4
cmd -->newman -v
如果安装过程很慢,我们更新为国内淘宝的服务器:
npm config set registry http://registry.npm.taobao.org
2、newman的使用
第一步:导出测试集合、导出环境变量
新建collection集合,创建request,并调试通过,选中集合,选中export-->v2,点击导出。
导出environment环境,导出环境的json文件。
导出全局globals环境:
第二步:运行测试集合文件
cmd-->newman run 测试集合文件的全路径
newman run e:\aaa.collection.json
newman run e:\aaa.collection.json -e e:\envirement.json -g e:\globals.json
3、newman的常见参数
-e: 后面是指定environment环境文件全路径的参数
newman run e:\aaa.collection.json -e e:\envirement.json
-g:后面是指定globals环境文件全路径的参数
newman run e:\aaa.collection.json -e e:\envirement.json -g e:\globals.json
-n:后面跟一个数字,表示测试集合执行的迭代次数(就是循环执行的次数)
newman run e:\aaa.collection.json -e e:\envirement.json -n 2
-d: 后面跟的是参数化文件,json、csv文件数据
newman run e:\aaa.collection.json -e e:\environment.json -d e:\postmanCsv.csv
newman run e:\aaa.collection.json -e e:\environment.json -d e:\postmanJson.json
4、newman导出的报告类型
cli格式报告:就是cmd下运行生成的文件。
newman run e:\aaa.collection.json -e e:\environment.json -d e:\postmanJson.json > e:\result.txt
json格式的报告:postman的runner运行器中执行也会输出json格式报告。
newman run e:\aaa.collection.json -e e:\environment.json -d e:\postmanJson.json -r json --reporter-json-export e:\result.json
newman run e:\aaa.collection.json -e e:\environment.json -d e:\postmanJson.json -r json --reporter-json-export e:\data\result0325.json
html格式的可视化报告:
newman run e:\aaa.collection.json -e e:\environment.json -d e:\postmanJson.json -r html --reporter-html-export e:\data\result0325.html
5、打包批处理命令
为什么做批处理?安装Jenkins,使用jenkins来部署运行run.bat文件。
实现无人执行的运行脚本。
步骤1:新建一个txt文件,重名为run.bat文件,使用notepad++打开。
步骤2:将上面的newman命令,复制到改文件中,转码为utf-8
步骤3:双击run.bat文件。