(1)安装nodejs
wget https://npm.taobao.org/mirrors/node/v16.9.0/node-v16.9.0-linux-x64.tar.xz
- 解压安装
tar -xvf node-v16.9.0-linux-x64.tar.xz
mv node-v16.9.0-linux-x64 node-v16.9.0
- 配置环境变量
vim /etc/profile
export PATH=$PATH:/home/sdb/soft/node-v16.9.0/bin
- 验证
node -v
- cnpm安装
npm install -g cnpm --registry=https://registry.npm.taobao.org
- 安装newman
cnpm install newman --global
- 验证
newman -v
- 安装html报告的组件
cnpm install newman-reporter-html
- 测试
输出报告时使用的命令:
-r html,json,junit 指定生成html,json,xml形式的测试报告
--reporter-json-export jsonReport.json 生成json格式的测试报告
--reporter-junit-export xmlReport.xml 生成xml格式的测试报告
--reporter-html-export htmlReport.html 生成html格式的测试报告
默认生成的测试报告保存在当前目录下,如果文件名前加上路径,则保存在指定的目录下
指定生成html报告
newman run echo-tester.postman_collection.json -k -r html,cli --reporter-html-export result.html
指定数据文件和html报告
newman run echo-tester.postman_collection.json -k -d data.json -r html,cli --reporter-html-export result.html
- newman run -h
Usage: newman run <collection> [options]
Initiate a Postman Collection run from a given URL or path
Options:
-e, --environment <path> 通过json文件指定环境(环境模块导出的)
-g, --globals <path> 通过文件指定postman全局变量(全局变量设置模块导出的)
-r, --reporters [reporters] 指定用于此运行的报告类型(默认值:cli,也就是控制台输出)
-n, --iteration-count <n> 指定要迭代运行的次数
-d, --iteration-data <path> 指定要使用json或csv的数据文件
--folder <path> 指定要从集合运行的文件夹。可以多次指定以运行多个文件夹(默认值:[])
--global-var <value> 允许通过命令行以key=value格式指定全局变量(默认值:[])
--env-var <value> 允许通过命令行以key=value格式指定环境变量(默认值:[])
--export-environment <path> 完成运行后,将最终环境导出到文件
--export-globals <path> 完成运行后,将最终全局文件导出到文件
--export-collection <path> 完成运行后,将执行的集合导出到文件
--postman-api-key <apiKey> API Key used to load the resources from the Postman API
--bail [modifiers] 指定是否在遇到错误时正常停止集合运行,以及是否基于可选修饰符以错误结束运行
--ignore-redirects 防止Newman自动跟踪3XX重定向响应
-x , --suppress-exit-code 指定是否覆盖当前运行的默认退出代码
--silent 防止Newman向CLI显示输出
--disable-unicode 强制将符合Unicode的符号替换为其纯文本等效项
--color <value> 启用/禁用彩色输出(自动打开/关闭)(默认值:“自动”)
--delay-request [n] 指定请求之间的延迟范围(毫秒)(默认值:0)
--timeout [n] 指定集合运行的超时(毫秒)(默认值:0)
--timeout-request [n] 指定请求的超时(毫秒)(默认值:0)
--timeout-script [n] 指定脚本的超时(毫秒)(默认值:0)
--working-dir <path> 指定工作目录的路径
--no-insecure-file-read 防止读取位于工作目录之外的文件
-k, --insecure 禁用SSL验证
--ssl-client-cert-list <path> 指定客户端证书配置(JSON)的路径
--ssl-client-cert <path> 指定客户端证书(PEM)的路径
--ssl-client-key <path> 指定客户端证书私钥的路径
--ssl-client-passphrase <passphrase> 指定客户端证书密码短语(用于受保护密钥)
--ssl-extra-ca-certs <path> 指定其他受信任的CA证书(PEM)
--cookie-jar <path> 指定自定义 cookie jar的路径 (serialized tough-cookie JSON)
--export-cookie-jar <path> 完成运行后将cookie jar导出到文件
--verbose 显示收集运行和发送的每个请求的详细信息
-h, --help display help for command