UI自動化測試之allure結合pytest生成測試報告
1、在控制檯生成測試報告
1.1Allure生成測試報告
Allure可以和Pytest測試框架結合生成很漂亮的測試報告。
allure的下載地址:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
1.1.1前置準備
(1)Allure可以和Pytest測試框架結合生成測試報告,首先需要安裝pytest和allure-pytest這兩個庫,我們直接在控制檯進行安裝即可。
安裝的命令為:pip install pytest、pip install allure-pytest
(2)下載allure並解壓,這裡我下載的是2.17.3的版本,如圖:
(3)配置環境變數:將allure的bin目錄放在path環境變數中。
(4)驗證環境配置成功:在控制檯輸入allure --version檢視allure的版本。
1.1.2生成測試報告
生成測試報告步驟:
(1)開啟控制檯,進入本地儲存的某個測試專案的所在的目錄下,如進入UiFrame專案中:
(2)輸入命令:pytest test/ --alluredir=report/my_allure_results執行該專案中test資料夾中的測試報告,並在report資料夾裡建立一個my_allure_results資料夾,在該資料夾中生成測試報告的json檔案。
report資料夾下的json檔案:
json檔案中的內容:
(3)然後通過命令:allure generate report/my_allure_results/ -o report/html --clean解析my_allure_results下的json檔案,然後在report中生成html資料夾,並在資料夾中生成html的測試報告。
report資料夾下的html中的內容:然後我們通過瀏覽器就可以改開該測試報告。
測試報告如下圖所示:
(3)或者直接在控制檯輸入命令:allure serve report/my_allure_results,生成測試報告後直接開啟,相當於在allure中搭載一個服務,令其解析完json檔案後生成測試報告並直接開啟測試報告,這裡是通過本地的預設瀏覽器開啟測試測試報告的。