postman+newman+jenkins 持續集成搭建及使用,實現接口自動化


postman是谷歌的一款非常好用的工具,可以用來做手工的接口測試,也能實現簡單的接口自動化持續集成,如果大家覺得postman已經能滿足自己的需要,也不想去學習Python+requests,那么postman這個工具一定要好好掌握。

安裝好node.js  

下載地址:https://nodejs.org/zh-cn/

cmd中輸入指令: node -v 查看node的版本,出現node版本說明我們安裝成功,環境變量也配置ok 
這里寫圖片描述

二、安裝newman和html (生產html測試報告)

1. 命令行輸入指令 npm install newman –global 
安裝完成后,輸入指令 newman -v 查看版本,檢測是否安裝成功,這里注意,newman的包被安裝在了npm工具的包下 
這里寫圖片描述 
出現了newman的版本,說明我們安裝ok

2. cmd輸入  npm install newman-reporter-html   安裝html  

執行以上生成html報告的命令時,若出現異常提示:
newman: "html" reporter could not be loaded.
run `npm install newman-reporter-html`

解決:需要執行命令 npm install -g newman-reporter-html  來全局安裝支持Newman生成html報告的組件然后,

再次執行命令生成測試報告   newman run E:\postman_json\data.json -g E:\postman_globals\globals.json -d E:\csv\csvdata.csv --reporters html --reporter-html-export E:\report\html02.html

三、postman導出collection、環境變量

postman界面的左側邊欄,選擇collections,找到自己需要導出的集合,選擇更多按鍵,點擊Export 

è¿éåå¾çæè¿°

如果有環境變量或者全局變量也需要導出,點擊設置按鈕,選擇要下載的環境變量,下載

把下載的collection和環境變量文件,requests需要用到的數據文件(我的數據文件data.json)放到一個文件夾

四、執行

運行:newman run postman 測試.postman_collection.json -e test.postman_environment.json


執行命令生成測試報告   newman run postman 測試.postman_collection.json -e test.postman_environment.json --reporters html --reporter-html-export E:\report\html02.html

 

5. 結合Jenkins

作用: 
    1.持續、自動地構建/測試軟件項目。 
    2.監控一些定時執行的任務。

Jenkins下載地址 https://jenkins.io/download/ 
步驟一:在Jenkins 機器上安裝Newman 
步驟二:搭建Jenkins環境,並新建個自由風格的Job 
步驟三:進入http://localhost:8080 
步驟四:構建選擇Execute Windows batch command,並輸入newman 運行命令

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM