1秒登錄
原文鏈接:Postman+Newman+Git+Jenkins實現接口自動化測試持續集成
接口測試腳本一般的執行流程
做接口測試的話,首先要考慮的是如何選擇一個合適的工具?在忽略工具是否好用,是否能滿足業務要求的前提下,需要考慮一下2點:
1、要考慮工具的學習成本
2、要考慮團隊的協作
接口測試腳本的執行流程:
團隊成員協作編寫接口用例->用例歸檔到git/svn->腳本集成jenkins,在環境更新后自動觸發執行或定時執行。
Postman工具常見的接口測試流程是怎樣的?
Windows系統Newman安裝
Centos系統Newman安裝
tar xvJf ***.tar.xzecho "export PATH=\"\$PATH:/root/tools/node-v14.8.0-linux-x64/bin\"" \ >> ~/.bash_profile &&source ~/.bash_profile
tar xvJf ***.tar.xz
echo "export PATH=\"\$PATH:/root/tools/node-v14.8.0-linux-x64/bin\"" \ >> ~/.bash_profile &&
source ~/.bash_profile
命令行執行Postman腳本生成測試報告
--reporter-html-export htmlReport.html
--reporter-htmlextra-export htmlExtraReport.html
--reporter-junit-export junitReport.html
--reporter-json-export jsonReport.html
npm config set registry https://registry.npm.taobao.org
4、通過newman-reporter-htmlextra插件生成的html報告,默認是不包含css樣式文件的,如果是發給別人訪問 ,在斷網的情況下查看報告,樣式是加載不了的。目前查了一下,好像沒有類似allure里面的那種參數,可以把報告所需的樣式和報告一起導出,不過這個插件支持自定義報告模板,可以自己手動將css樣式文件導出到某個位置,然后修改報告模板匯總引用的文件去解決這個問題。
Postman腳本持續集成
通過上面的描述 ,現在已經可以將postman腳本生成報告了,離集成jenkins只差最后的配置工作了:
1、在gitee上新建一個倉庫,將postman調試好的腳本導出成json文件,上傳到gitee上 (上傳到gitee倉庫的話,可以方便團隊不同成員之間可以更改和查看用例),后續有腳本變更的時候也可以直接更新到git上進行存儲,git上也可以按版本按分支存放你的測試腳本
2、搭建好jenkins環境,並配置好npm的環境以及安裝好newman執行環境
3、新建一個自由風格的job,配置從git上獲取腳本:
勾選構建環境下的清除工作空間目錄的配置,將之前的報告清除(如果執行命令生成報告時自己指定了報告名稱的話 ,也可以不清除工作空間的文件)
添加執行batch命令 / shell命令,命令內容如下:
# batch命令cd /d %WORKSPACE%newman run demo.postman_collection.json -r htmlextra --reporter-htmlextra-export ./report/htmlExtraReport.html 或者# shell 命令cd $WORKSPACEnewman run demo.postman_collection.json -r htmlextra --reporter-htmlextra-export ./report/htmlExtraReport.html newman run demo.postman_collection.json -r htmlextra --reporter-htmlextra-export ./report/htmlExtraReport.html
# batch命令
cd /d %WORKSPACE%
newman run demo.postman_collection.json -r htmlextra --reporter-htmlextra-export ./report/htmlExtraReport.html
或者
# shell 命令
cd $WORKSPACE
newman run demo.postman_collection.json -r htmlextra --reporter-htmlextra-export ./report/htmlExtraReport.html newman run demo.postman_collection.json -r htmlextra --reporter-htmlextra-export ./report/htmlExtraReport.html
然后再構建后操作那里 ,添加報告的展示:
需安裝HTML Publisher plugin插件
構建后 ,即可在jenkins上看到HTML報告:
發送釘釘通知
解決jenkins上無法展示HTML樣式的問題
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
-Dhudson.model.DirectoryBrowserSupport.CSP=
4、用tomcat部署的jenkins,可以直接改catalina.bat文件,找到tomcat/bin下的catalina.bat文件,用Notepad++打開,加上一行代碼
set JAVA_OPTS="-Dhudson.model.DirectoryBrowserSupport.CSP"
擴展學習
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。