Allure
1劳翰、安裝allure
1.1.1. Linux
對(duì)于基于Debian的存儲(chǔ)庫(kù)肥荔,提供了PPA:
sudo apt-add-repository ppa:qameta/allure
sudo apt-get update
sudo apt-get install allure
1.1.2. Mac OS X
對(duì)于Mas OS睡雇,可通過(guò)Homebrew進(jìn)行自動(dòng)安裝
brew install allure
1.1.3. Windows
對(duì)于Windows寿酌,可從Scoop命令行安裝程序獲得Allure 。
要安裝Allure婚苹,請(qǐng)下載并安裝Scoop岸更,然后在Powershell中執(zhí)行:
scoop install allure
Scoop還能夠更新Allure發(fā)行版安裝。為此膊升,導(dǎo)航到Scoop安裝目錄并執(zhí)行
\bin\checkver.ps1 allure -u
這將檢查Allure的較新版本怎炊,并更新清單文件。然后執(zhí)行
scoop update allure
1.1.4.手動(dòng)安裝
- 從Maven Central下載最新版本的zip存檔。
- 將存檔解壓縮到allure-commandline目錄评肆。
- 導(dǎo)航到bin目錄债查。
- 使用allure.bat或用于Windows的誘惑力對(duì)其他Unix平臺(tái)。
- 為系統(tǒng)PATH增添環(huán)境變量瓜挽。
1.1.5.檢查安裝
allure --version
在控制臺(tái)中執(zhí)行以確表锿ⅲ現(xiàn)在可以使用魅力:
$ allure --version
2.0.1
2、Pytest 使用allure
2.1.1.安裝
可從PyPI安裝Pytest 久橙,因此建議使用pip進(jìn)行安裝俄占。要安裝最新版本,請(qǐng)從命令行執(zhí)行:
$ pip install allure-pytest
$ pip install allure-python-commons
這將安裝allure-pytest和allure-python-commons程序包淆衷,以生成與Allure 2兼容的報(bào)告數(shù)據(jù)缸榄。如果將早期版本的適配器用于 第一代Allure報(bào)告,則需要首先將其卸載吭敢。
2.1.2. 用法
要使Allure偵聽(tīng)器能夠在測(cè)試執(zhí)行期間收集結(jié)果碰凶,只需添加--alluredir
option并提供應(yīng)存儲(chǔ)結(jié)果的文件夾的路徑暮芭。例如:
$ pytest --alluredir=/tmp/my_allure_results
要在測(cè)試完成后查看實(shí)際報(bào)告鹿驼,您需要使用Allure命令行實(shí)用程序從結(jié)果中生成報(bào)告:直接打開(kāi)瀏覽器生成
$ allure serve /tmp/my_allure_results
生成文件,手動(dòng)打開(kāi)生成的報(bào)告
$ allure generate /tmp/my_allure_results -o /tmp_html/my_allure_results --clean #生成報(bào)告
$ allure open -h localhost -p 8883 /tmp/my_allure_results #打開(kāi)報(bào)告
2.1.3.常用特性
使用方法 | 參數(shù)值 | 參數(shù)說(shuō)明 |
---|---|---|
@allure.epic() | epic描述 | 敏捷里面的概念辕宏,定義史詩(shī)畜晰,往下是feature |
@allure.feature() | 模塊名稱 | 功能點(diǎn)的描述,往下是story |
@allure.story() | 子功能模塊名字 | 用戶故事瑞筐,往下是title |
@allure.title(用例的標(biāo)題) | 用例的標(biāo)題 | 重命名html報(bào)告名稱 |
@allure.testcase() | 測(cè)試用例的鏈接地址 | 對(duì)應(yīng)功能測(cè)試用例系統(tǒng)里面的case |
@allure.issue() | 缺陷 | 對(duì)應(yīng)缺陷管理系統(tǒng)里面的鏈接 |
@allure.description() | 用例描述 | 測(cè)試用例的描述 |
@allure.step() | 操作步驟 | 測(cè)試用例的步驟 |
@allure.severity() | 用例等級(jí) | blocker:阻塞凄鼻,critical:功能點(diǎn)缺失,normal:數(shù)值計(jì)算錯(cuò)誤聚假,<br />minor:缺陷块蚌,trivial:輕微缺陷 |
@allure.link() | 鏈接 | 定義一個(gè)鏈接,在測(cè)試報(bào)告展現(xiàn) |
@allure.attach() | 附加的信息 | 可以數(shù)據(jù)膘格、文本峭范、圖片、視頻瘪贱、網(wǎng)頁(yè) |
@allure.attachment() | 附件 | 報(bào)告添加附件 |
2.1.4.按照重要性的級(jí)別進(jìn)行一定范圍的測(cè)試
-
在方法和類上添加下面代碼:
@allure.severity(allure.severitiy_level.TRIVIAL)
-
執(zhí)行代碼
pytest -s -v 文件名 --allure-severites 等級(jí)1,等級(jí)2
2.1.5.添加文件纱控、文本
語(yǔ)法:allure.attach(body, name, attachment_type, extension)
參數(shù)解釋:
body:要寫(xiě)入附件的內(nèi)容;
name:附件名字菜秦;
attachment_type:附件類型甜害,是allure.attachment_type其中的一種;
extension:附件的擴(kuò)展名球昨;
allure.attach的用法二:
語(yǔ)法:allure.attach.file(source, name, attachment_type, extension)
參數(shù)解釋:
source:文件路徑尔店,相當(dāng)于傳一個(gè)文件;
name:附件名字;
attachment_type:附件類型嚣州,是allure.attachment_type其中的一種期犬;
extension:附件的擴(kuò)展名;
allure.attach("文本",attachment_type=allure.attachment_type.TEXT)
# 純文本 attachment_type: llure.attachment_type.HTML allure.attachment_type.TEXT 等
allure.attach.file("./untils/log/2021-04-20模塊名稱.log", attachment_type=allure.attachment_type.TEXT)
# 含有文件