Postman+Newman生成HTML接口測試報告

NewMan 是官方提供的專門用於 posman 進行自動化的命令行工具

環境配置:

Node.js:Newman是基於Node.js,所以安裝NewMan之前需要保證本地有安裝Node.js
NewMan: npm i newman -g,安裝成功後輸入newman -v來檢查版本,顯示出版本即表示安裝成功
html格式報告的插件:npm install -g newman-reporter-html

重點記錄newman和報告的生成

1,在Postman中導出腳本和環境變量的.json文件

NewMan常用參數

-e, --environment
指定 environment 環境變量,這裏環境變量需要以 .json 的格式進行導出

-g, --globals
指定 global 環境變量,這裏環境變量需要 .json 的格式進行導出

-d, --iteration-data
指定運行 Collection 時使用的文件(注意是全路徑下的文件)

-n, --iteration-count
指定 Collection run 時的迭代次數 n

-r, --reporters [reporters]
指定運行完成後的結果報告類型,除默認命令行格式 cli 外,還支持 json、junit、progress 以及 emojitrain 幾種類型。

 

 在.json文件的目錄下,進入cmd環境,輸入指令

newman run API.postman_collection.json -e Env.postman_enviroment.json 

即根據postman中環境變量的值,執行API腳本。如果有其他需求,則根據上面的參數進行執行。執行完成後,會在cmd窗口中給出執行結果

 

2,生成HTML報告

--reporter html:在當前腳本所在路徑下生成 html 格式的測試報告
--reporter-html-export:在指定路徑下生成 html 格式的測試報告

newman run API.postman_collection.json -e Env.postman_environment.json --reporters html --reporter-html-export C:\Users\F1\Desktop\pmtest

即可在指定目錄下生成HTML報告,雙擊打開即可

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章