前期準備
1.需要安裝的工具(postman,newman,node.js,jenkins)
具體安裝步驟不累述贸桶,可自行查閱相關文檔
安裝postman?
現(xiàn)在postman是單獨的應用具壮,可以獨立安裝吓懈。
如果需要錄制屏幕 必須下載Postman Interceptor插件虽填,這樣在chrome瀏覽器上訪問的信息都會在postman的app端同步顯示臭杰。安裝好后Postman Interceptor會在瀏覽器的右邊顯示
安裝newman
官方幫助文檔地址:https://www.npmjs.com/package/newman
1.需要安裝nodejs,并配置好環(huán)境變量
2.控制臺輸入鲤遥,sudo nom install -g newman
3.安裝成功后輸入沐寺,newman -version確認是否安裝成功
newman執(zhí)行腳本
newman run <collection-file-source>?[options]?
Run后面跟上執(zhí)行的json文件或者url(json和url都postaman導出生成),再后面可跟一些參數(shù):環(huán)境變量盖奈,測試報告混坞,接口請求超時等,
例子1運行test1.json文件钢坦,生成多種報告(json,junit-xml,html)
newman run c:\test1.json--reporterscli,html,json,junit --reporter-json-exportjsonOut.json --reporter-junit-exportxmlOut.xml --reporter-html-exporthtmlOut.html
jenkins結(jié)合
1.在jenkins部署的機器上安裝newman
2.構(gòu)建選擇Execute Windows batch command究孕,輸入newman命令
因為上面命令中構(gòu)建會生成junit的xml報告,所以可以在構(gòu)建后用Publish JUnit test result report插件來生成測試報告