newman可以使用命令行執行postman腳本。
newman安裝:
1、安裝node.js
安裝成功後,dos命令窗口輸入node -v或node --version
2、安裝newman
dos命令窗口輸入npm install -g newman安裝;
安裝成功後輸入node -v或node --version
newman常用參數:
run:
運行集合;示例:newman run 集合名
-h/--help:
顯示命令行幫助;示例:newman --help/-h
-e,--environment:
指定環境文件路徑或者url,執行集合時需要指定環境變量,將postman的環境變量導出,用-e指定該環境變量文件
newman run 集合腳本文件.js -e 環境變量文件.js
-g,--globals:
指定全局變量的文件地址或url,同-e
-d,----iteration-data:
指定用於迭代的數據文件
-n,--iteration-count:
指定迭代次數(在指定迭代數據文件後使用-n指定迭代次數)
3、測試報告的格式
NeNewman提供的測試報告中,常用的包括cli、json和html三種格式,可以通過-r或者--reporter命令指定所用格式;
cli格式爲cmd客戶端呈現的報告模式,newman默認使用這種格式;
json格式:
示例:newman run 地址 -r json --reporter-json-export 保存的地址+保存的文件名稱.json
html格式(使用前需要安裝npm install -g newman-reporter-html):
示例:newman run 地址 -r html —reporter-html-export 保存的地址+保存的文件名稱.html