美文网首页
newman基础使用

newman基础使用

作者: E术家 | 来源:发表于2023-07-03 17:12 被阅读0次
首先下载安装node.js

官网地址:https://nodejs.org/en/download/

npm -v

验证node.js 是否安装成功

newman及插件安装
npm config set registry https://registry.npm.taobao.org

设置node包管理器(npm: Node Package Management)的服务器地址,改为国内镜像地址,https://registry.npm.taobao.org 是淘宝做的国内npm镜像地址

npm install -g newman

安装newman

npm install -g newman-reporter-html

下载newman-reporter-html插件,newman-reporter-html用于newman运行后生成html的测试报告

newman run --help

newman运行前可以查看帮助,同时确认是否安装成功

使用
D:\0704newman>newman run ecshop.postman_collection.json -e ecshop_develop.postman_environment.json -g postman_globals.json -d ecshop_users.csv -r html --reporter-html-export .\reports\report.html

newman run 集合脚本1.json
-d 集合1参数文件.csv
-e 环境变量.json
-g 全局变量.json
-n 重复运行次数
-k -r html --reporter-html-export 集合1测试报告.html

一次批量运行多个集合脚本的命令执行方式:注意每行最后需要空格^,但最后一行不需要;每行最前面&&newman,&&和newman之间不能有空格,第一行不需要。
newman run 集合脚本文件1.json -d 参数化文件1.csv ^
&&newman run 集合脚本文件2.json -d 参数化文件2.csv ^
&&newman run 集合脚本文件3.json -d 参数化文件3.csv

还可以采用命令行方式合并在同一个测试报告文件中
newman run seafile01.postman_collection.json -e seafileproduct.postman_environment.json -g mytest.postman_globals.json -d seafile01.csv >> reports/rpt_01.log ^
newman run student.postman_collection.json -d student.csv >> reports/rpt_01.log

python代码实现
import os
os.system("del *.html") #清空旧的无用html文件
script_file = "seafile_reg.postman_collection.json" # 脚本文件
csv_file = "library_list.csv" # csv文件
output_file = "seafile_reg.html" # 导出的html文件
cmd = f"newman run {script_file} -d {csv_file} -k -r html --reporter-html-export {output_file}"
os.system(cmd) #执行操作系统中的命令行

相关文章

网友评论

      本文标题:newman基础使用

      本文链接:https://www.haomeiwen.com/subject/eutcudtx.html