httprunner 整合了 pytest,所以 httprunner v3.x 可以使用 pytest 的所有外掛程式,包括測試報告外掛程式,例如pytest-html
和alluer-pytest
。
httprunner 安裝之後自帶pytest-html
外掛程式,當你想生成 html 測試報告時,可以新增命令引數--html
。
$ hrun /path/to/testcase --html=report.html
通過--html=report.html
中的report.html
是測試報告的存放路徑,沒有帶資料夾的時候會存放在命令執行的資料夾。
--html
生成的 html 報告包含了多個資料夾,如果你要建立乙個單獨的 html 檔案,可以天劍另乙個命令引數--self-contained-html
。
$ hrun /path/to/testcase --html=report.html --self-contained-html
你可以參考pytest-html,獲取更多關於 pytest-html 測試報告的資訊。
pytest 支援大名鼎鼎的 allure 測試報告,httprunner 整合了 pytest,也天然支援 allure。
不過 httprunner 預設並未安裝 allure,你需要另外安裝。
安裝有兩種方式:
$ pip3 install "allure-pytest"
pip3 install "httprunner[allure]"
一旦 allure-pytest 準備好,以下引數就可以與 hrun/pytest 命令一起使用:
--alluredir=dir
: 生成 allure 報告到指定目錄
--clean-alluredir
: 如果指定目錄已存在則清理該資料夾
--allure-no-capture
:不要將 pytest 捕獲的日誌記錄(logging)、標準輸出(stdout)、標準錯誤(stderr)附加到報告中
要使 allure 偵聽器能夠在測試執行期間收集結果,只需新增--alluredir
選項,並提供指向儲存結果的資料夾路徑。如:
$ hrun /path/to/testcase --alluredir=/tmp/my_allure_results
/tmp/my_allure_results 只會儲存收集的測試結果(你將會看到一堆莫名其妙的檔案,這些都是收集的測試結果),並非完成的報告,還需要通過命令生成。要在測試完成後檢視實際報告,您需要使用allure命令列實用程式從結果中生成報告。
$ allure serve /tmp/my_allure_results
此命令將在預設瀏覽器中顯示你生成的報告。
同時你也可以在 jenkins 中安裝 allure 報告外掛程式,將結果與 jenkins 整合。
你可以在 allure-pytest 檢視關於 allure 報告的更多資訊。
httprunner自動化例項(二)
第一篇實現了乙個單介面的測試,第二篇我們來實現串介面的測試。首先我們需要搭建乙個可測試的系統,可以直接在github上找乙個 系統,或者直接在公司系統測試環境進行測試。我們知道 單介面 的測試非常好完成,可以通過各種介面請求工具比如postman,python request包等去發起post,ge...
HttpRunner 介面自動化簡單實踐
httprunner是一款介面測試開源框架,簡潔優雅,是做介面自動化測試很不錯的選擇 宣告 完整的使用手冊請轉到 專案原始碼 1.1 命令列pip直接安裝就好 1.2 驗證安裝 命令列輸入hrun v,返回專案版本資訊則表明安裝成功 這裡我用直接通過框架的腳手架工具命令生成目錄結構 如 hrun s...
介面自動化
推薦一款適合開發的開源 該公司產品從資料庫,持續整合 ci 伺服器,問題和專案跟蹤工具,到介面自動化工具都應有盡有。是我見過比較系統的開發 這裡我們以介面自動化為主講解 pycharm frommenu 2.安裝python解析器 version 3或者version2隨便哪乙個都可以,本人自用ve...