前言
allure是一個report框架,支持java的Junit/testng等框架,當然也可以支持python的pytest框架,也可以集成到Jenkins上展示高大上的報告界面。
環境准備
- 1.python3.6
- 2.windows環境
- 3.pycharm
- 4.pytest-allure-adaptor
- 5.allure2.7.0
- 6.java1.8
** 作者:上海-悠悠 QQ交流群:588402570**
pytest-allure-adaptor下載
pip安裝pytest-allure-adaptor,github地址https://github.com/allure-framework/allure-pytest
pip3 install pytest-allure-adaptor
生成xml報告
pytest -s -q --alluredir report
如果不指定路徑,默認在當前目錄下新建一個report目錄,當然也可以指定路徑
pytest -s -q --alluredir 指定report路徑
執行完之后打開report文件夾,會自動生成xml格式的報告
安裝 Command Tool
allure的版本目前有2個,從github上看,allure1不再被支持,請考慮使用allure2 https://github.com/allure-framework/allure2替代
allure-commandline releases版本https://github.com/allure-framework/allure2/releases
下載最新的Download allure2.7.0版本
[下載Download allure2.7.0 地址:https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.7.0/allure-2.7.0.zip]
(https://dl.bintray.com/qameta/generic/io/qameta/allure/allure/2.7.0/allure-2.7.0.zip)
下載好之后,解壓到運行pytest的目錄下
打開\allure-2.7.0\bin文件夾,會看到allure.bat文件,講此路徑設置為系統環境變量path下,這樣cmd任意目錄都能執行了
比如我的路徑:D:\YOYO\case\allure-2.7.0\bin
運行allure2
前面pytest -s -q --alluredir 這一步已經生產了xml格式的報告,放到了report目錄下,接着執行以下命令格式
allure generate directory-with-results/ -o directory-with-report
directory-with-results是alluredir生成的xml目錄,directory-with-report是最終生成html的目錄
allure.bat已經加到環境變量了,所以可以用相對路徑去生成html報告
allure generate report/ -o report/html
執行完之后目錄結構如下:
打開報告
直接找到report/html打開index.html會顯示一個空的報告,這里用pycharm去打開
打開后報告展示
依賴java環境
之前用的jdk1.7版本,執行allure時候報錯:Unsupported major.minor VERSION 51.0
由於allure2是java開發的,需要依賴java環境,解決辦法:jdk版本用1.8就可以了
---------------------------------pytest結合selenium自動化完整版-------------------------
全書購買地址 https://yuedu.baidu.com/ebook/902224ab27fff705cc1755270722192e4536582b
作者:上海-悠悠 QQ交流群:874033608
也可以關注下我的個人公眾號:yoyoketang