Introduction
allure
- Lightweight, flexible, multi-language test report tool
- Multi-platform, luxurious reporting framework
- Can provide detailed test reports, test steps, and logs for development and testing
- Provide high-level statistical reports for management
- Use Java development, support pytest, JavaScript, PHP, Ruby, etc.
- Can be integrated into Jenkins
official website:
official document:
Install
Windows / Mac / Linux general installation method:
Download the allure.zip installation package, and configure the environment variables after decompression:
Configuration path: allure-2.13.8\bin
allure official installation package download:
allure installation package download
Baidu network disk download:
Mac command line installation:
brew install allure
conjunction with pytest, and the python plug-in needs to be installed:
pip install allure-pytest
run
- Collect results during test execution:
pytes [测试文件] -s -q --alluredir ./result/ # --alluredir 这个选项用于指定存储测试结果的路径
View the test report:
- After the test is completed, view the actual report and view the report online. The default browser will be directly opened to display the current report:
allure serve ./result/
Generate a report from the results, this is a service to start tomcat, including two steps:
- Generate report:
allure generate ./result/ -o ./report/ --clean # 覆盖路径需要添加 --clean
- Open report (can be opened remotely)
allure open -h host -p port ./report/
Common features
Use scenario: see the test function, sub-function or scenario, test steps in the report, including additional test information
How to use: use decorator
- @allure.feature("feature name")
@allure.feature("测试采购合同模块") # 通常对测试类进行装饰
class TestPurchaseContract:
- @allure.story("Sub-function/single use case name")
@allure.story("测试同步标识灯功能") # 通常对单个用例进行装饰
def test_synchronize(self):
"""
测试 同步标识灯 功能
:return:
"""
r = self.pending_request.synchronize()
assert r["msg"] == "同步更新申购单红、绿、蓝灯状态成功"
assert r["success"] is True
- @allure.step("Step Details")
with allure.step("步骤细节"):
# 具体测试步骤代码
- @allure.attach("Additional information/log-can be data, text, pictures, etc.")
only runs the use case of the specified feature:
pytest test.py --allure-features="功能名称"
Only run the use cases of the specified story:
pytst test.py --allure-stories="子功能/单个用例名称"
combined use:
pytest test.py --allure-features="功能名称" --allure-stories="子功能/单个用例名称"
allure feature-testcase
Associated test case: directly give the link address of the test case
test_case_link = "测试用例链接"
@allure.testcase(test_case_link, "描述说明")
def test_with_testcase_link():
pass
Local static data generation of test report
allure generate ./result -o ./report --clean
# -o:指定报告生成的文件夹
# --clean:先清空测试报告目录,在生成新的测试报告
The generated static data can be opened in the web service built by tomcat
Divide test cases by importance level
usage scenario:
Usually tests include PO, smoke test, verification on-line test, and regression test, which are executed according to the importance level; for example, the main process and important modules should be run through the online test.
Use case level:
- BLOCKER: Blocking defect (the function is not implemented, the next step is not possible)
- CRITICAL: serious defect (missing function points)
- NORMAL: General defect (boundary case, format error)
- MINOR: Minor defect (interface error does not match ui requirements)
- TRIVIAL: Minor defect (must have no prompt or prompt irregularity)
use
# 在方法、函数、类上装饰
@allure.severity(allure.severity_level.TRIVIAL)
def test_with_trivial_severity():
pass
@allure.severity(allure.severity_level.NORMAL)
def test_with_normal_severity():
pass
# 执行
pytest -s -v 文件名 --allure-severities normal, critical
pytest -s -v 文件名 --allure-severities=normal, critical
UI automation test-screenshot
usage scenarios: UI automation tests often need to attach pictures/html, take screenshots at appropriate locations
use
allure.attach(body, name, attachment_type, extension)
# body:要显示的内容(附件)
# name:附件名字
# attachment_type:附件类型,是 allure.attachment_type 里面的其中一种
# extension:附件的扩展名(比较少用)
allure.attach.file(source, name, attachment_type, extension)
# source:文件路径,相当于传一个文件
# attachment_type提供的附件类型
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。