首先下載安裝node.js
官網(wǎng)地址:https://nodejs.org/en/download/
npm -v
驗(yàn)證node.js 是否安裝成功
newman及插件安裝
npm config set registry https://registry.npm.taobao.org
設(shè)置node包管理器(npm: Node Package Management)的服務(wù)器地址,改為國(guó)內(nèi)鏡像地址,https://registry.npm.taobao.org 是淘寶做的國(guó)內(nèi)npm鏡像地址
npm install -g newman
安裝newman
npm install -g newman-reporter-html
下載newman-reporter-html插件,newman-reporter-html用于newman運(yùn)行后生成html的測(cè)試報(bào)告
newman run --help
newman運(yùn)行前可以查看幫助,同時(shí)確認(rèn)是否安裝成功
使用
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參數(shù)文件.csv
-e 環(huán)境變量.json
-g 全局變量.json
-n 重復(fù)運(yùn)行次數(shù)
-k -r html --reporter-html-export 集合1測(cè)試報(bào)告.html
一次批量運(yùn)行多個(gè)集合腳本的命令執(zhí)行方式:注意每行最后需要空格^,但最后一行不需要;每行最前面&&newman,&&和newman之間不能有空格,第一行不需要。
newman run 集合腳本文件1.json -d 參數(shù)化文件1.csv ^
&&newman run 集合腳本文件2.json -d 參數(shù)化文件2.csv ^
&&newman run 集合腳本文件3.json -d 參數(shù)化文件3.csv
還可以采用命令行方式合并在同一個(gè)測(cè)試報(bào)告文件中
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代碼實(shí)現(xiàn)
import os
os.system("del *.html") #清空舊的無(wú)用html文件
script_file = "seafile_reg.postman_collection.json" # 腳本文件
csv_file = "library_list.csv" # csv文件
output_file = "seafile_reg.html" # 導(dǎo)出的html文件
cmd = f"newman run {script_file} -d {csv_file} -k -r html --reporter-html-export {output_file}"
os.system(cmd) #執(zhí)行操作系統(tǒng)中的命令行