Postman測試報告的生成方法
阿新 • • 發佈:2022-01-16
目錄
- 1.安裝node.
- 2.安裝newman
- 3.控制檯生成測試報告
- 4.生成HTML的測試報告
- 5.輸出htmlextra報告
我們使用工具newman就可以生成測試報告(自動化測試的結果)
Newman是一款基於nodejs開發的可以執行postman的工具,使用Newman,可以直接從命令執行和測試postman集合。
使用newman的前提是需要安裝node.js,通過node.js來安裝newman的工具
安裝newman的命令:
npm install -g newman --registry=https://registry.npm.taobao.org
1.安裝node.js
下載地址:https://nodejwww.cppcns.com
安裝:只需雙擊即可完成安裝,在這裡建議不要將路徑放到C盤,這是一種安裝軟體的共識。並且在安裝的過程中,安裝嚮導已經幫我們完成了環境變數的註冊,我們可以通過環境變數來檢視
驗證是否配置成功:控制檯輸入npm,如果顯示以下資料則表示安裝並且配置成功
C:\Users\特昂糖>npm npm <command> Usage: npm install install all the dependencies in your project npm install <foo> add the <foo> dependency to your project npm test PSENHrun this project's tests npm run <foo> run the script named <foo> npm <command> -h quick help on <command> npm -l display usage info for all commands npm help <term> search for help on <term> (in a browser) npm help npm more involved overview (in a browser) All commands: access,adduser,audit,bin,bugs,cache,ci,completion,config,dedupe,deprecate,diff,dist-tag,docs,doctor,edit,exec,explain,explore,find-dupes,fund,get,help,hook,init,install,install-ci-test,install-test,link,ll,login,logout,ls,org,outdated,owner,pack,ping,pkg,prefix,profile,prune,publish,rebuild,repo,restart,rohttp://www.cppcns.comot,run-script,search,set,set-script,shrinkwrap,star,stars,start,stop,team,test,token,uninstall,unpublish,unstar,update,version,view,whoami Specify configs in the ini-formatted file: C:\Users\特昂糖\.npmrc or on the command line via: npm <command> --key=value More configuration info: npm help config Configuration fields: npm help 7 config [email protected] D:\Ruanjian\node_modules\npm #這裡顯示的是軟體所在本地磁碟路徑
2.安裝newman
node.js配置成功後我們就可以安裝newman了,安裝newman的命令為:npm install -g newman --registry=https://www.cppcns.comregistry.npm.taobao.org
C:\Users\特昂糖>npm install -g newman --registry=https://registry.npm.taobao.org npm WARN deprecated [email protected]: this library is no longer supported npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances,which is known to be problematic. See https://v8.dev/blog/math-random for details. npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances,which is known to be problematic. See https://v8.dev/blog/math-random for details. added 128 packages in 13s npm notice npm notice New minor version of npm available! 8.1.2 -> 8.3.0 npm notice Changelog: https://.com/npm/cli/releases/tag/v8.3.0 npm notice Run npm install -g [email protected] to update! npm notice
驗證是否安裝成功:
C:\特昂糖>newman Usage: newman [options] [command] Options: -v,--version output the version number -h,--help display help for command Commands: run [options] <collection> Initiate a Postman Collection run from a given URL or path To get available options for a command: newman <command> -h
3.控制檯生成測試報告
首先在postman中匯出測試資料
這裡以我的為例,下載地址:http://xiazai.jb51.net/202201/yuanma/postman_collection_jb51.rar
控制檯進入匯出檔案所在本地磁碟路徑
生成測試報告
newman run +匯出的測試資料檔名稱
4.生成HTML的測試報告
安裝HTML套件 newman 支援四種格式報告檔案:cli,json,html,junit 生成 html 報告時需要安裝html套件,命令列中執行: npm install -g 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格式的測試報告 預設生成的測試報告儲存在當前目錄下,如果檔名前加上路徑,則儲存在指定的目錄下 例:輸出json和html檔案報告
生成html測試報告
輸出命令: newman run 風暴平臺.postman_collection.json -r html
5.輸出htmlextra報告
安裝htmlextra套件
npm install -g newman-reporter-htmlextra
執行htmlextra套件
newman run 風暴平臺.postman_collection.json -r htmlextra
結果展示
到此這篇關於Postman測試報告的生成的文章就介紹到這了,更多相關Postman測試報告內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!