定制化後的allure測試報告效果展示
如何定制化輸出錦上添花的allure測試報告
使用前,先導入allure子產品。
import allure
使用前,先熟悉運作測試用例的有關allure的指令行參數
--allure-severities=SEVERITIES_SET
--allure-epics=EPICS_SET
--allure-features=FEATURES_SET
--allure-stories=STORIES_SET
--allure-ids=IDS_SET Comma-separated list of IDs.
--allure-link-pattern=LINK_TYPE:LINK_PATTERN
--alluredir=DIR Generate Allure report in the specified directory (may
--clean-alluredir Clean alluredir folder if it exists
--allure-no-capture Do not attach pytest captured logging/stdout/stderr to Allure Report
1、feature——測試用例特性(主要功能子產品):一般是在類上
使用方法: @allure.feature()
可以根據feature特性過濾出測試用例執行:
pytest test_allure.py --allure-features="登入子產品" -vs
2、story——feature功能子產品下的分支功能:一般是在方法上
使用方法: @allure.story()
可以根據story特性過濾出測試用例執行:
pytest test_allure.py --allure-stories="登入失敗" -vs
如果希望執行多個story或者feature,多個story名或feature名中間加","即可:
pytest test_allure.py --allure-stories="登入失敗","登出失敗" -vs
【注意】
①–allure-features和–allure-stories同時使用時,如果–allure-features中的用例包括了–allure-stories的用例,則隻執行–allure-features的用例;如果不包含,則同時執行–allure-features和–allure-stories的用例。
②雖然通過 pytest -m 指令行參數運作測試用例同樣可以達到分組運作測試用例的目的;但是使用allure特性來實作分組運作測試用例同樣可以在allure報告中展示,使allure特性更直覺。
3、severity——測試用例的嚴重級别
場景:通常測試有冒煙測試、驗證上線測試等場景,按照重要性級别來分别執行。比如上線前要把主流程和重要子產品都跑一遍。
解決:通過在方法、函數和類上添加allure.severity來附加标記。
執行: pytest 檔案名 --allure-severities=normal -vs
Allure中對嚴重級别的定義:
- blocker級别:中斷缺陷(用戶端程式無響應,無法執行下一步操作)
- critical級别:臨界缺陷( 功能點缺失)
- normal級别:普通缺陷(數值計算錯誤)
- minor級别:次要缺陷(界面錯誤與UI需求不符)
- trivial級别:輕微缺陷(必輸項無提示,或者提示不規範)
使用方法: @allure.severity(allure.severity_level.CRITICAL) 或者 @allure.severity('critical')
4、step——測試用例的步驟
使用方法:
① @allure.step() 隻能以裝飾器的形式放在類或者方法上面
② with allure.step() : 可以放在測試用例方法裡面,但測試步驟的代碼需要被該語句包含
5、attach——用于向測試報告中輸入一些附加的資訊,通常是一些測試資料資訊
使用方法: allure.attach(body, name, attachment_type, extension)
參數:
-
- 要寫入檔案的原始内容body
-
- 包含檔案名的字元串name
-
- 其中一個attachment_type
值allure.attachment_type
-
- 提供的将用作建立檔案的擴充名extension
6、link/issue/testcase——連結
使用方法:
- @allure.link()
- @allure.issue()
- @allure.testcase()
7、description——用例描述
使用方法:
- @allure.description() 提供描述字元串的裝飾器
- @allure.description_html() 提供一些HTML在測試用例的描述部分