allure测试报告如何使用
-
安装插件 pip install allure-pytest
-
安装将allure测试报告从json格式转换成html格式
- 下载地址:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
- allure-commandline-2.13.8.zip
- 将文件进行解压
- 解压完之后找到bin目录,我的目录如下:H:\allure-html\allure-2.13.8\bin
- 将目录进行配置在path环境变量中
-
在pytest.ini配置文件中
# 添加 --allure report # 具体如下 [pytest] addopts = -s --allure report testpaths = ./test01 pythonfiles = Test_* pythonclasses = Test* pythonfunction = test_*
-
配置完以上两项后,即可在命令行执行测试操作
-
这样会生成一个json格式的测试报告
-
将json格式的测试报告进行转换。如下
# 命令如下 allure generate report/ -o report/html --clean # 参数解析 report/ json格式测试报告的目录 report/html 在report目录下生成一个html目录文件,这个目录文件包含着html测试报告
allure测试报告的附加功能
-
展现测试报告步骤
-
在操作层中的方法上添加一个装饰器,@allure.step(title=“标题”)
# page/login_page.py class LoginHandle(BaseHandle): def __init__(self): self.login_page = LoginPage() @allure.step(title="输入手机号") def input_mobile(self, mobile): self.input_text(self.login_page.find_mobile(), mobile) @allure.step(title="输入验证码") def input_code(self, code): self.input_text(self.login_page.find_code(), code) @allure.step(title="点击登录按钮") def click_login_btn(self): self.login_page.find_login_btn().click()
-
-
截图
-
当需要截取测试中的结果时使用
allure.attach(driver.get_screenshot_as_png(), "截图", allure.attachment_type.PNG) # 具体事例 # script/test_login.py @pytest.mark.parametrize("mobile,code,username", build_data()) def test_login(self, mobile, code, username): logging.info("mobile={} code={} username={}".format(mobile, code, username)) # 登录 self.login_proxy.login(mobile, code) # 截图 allure.attach(self.driver.get_screenshot_as_png(), "截图", allure.attachment_type.P NG) # 断言 is_exist = utils.exist_text(DriverUtil.get_mp_driver(), username) assert is_exist
-
-
优先级
-
在测试报告中可以更加客观的看出测试结果数据优先级的情况
-
具体使用如下:
@allure.severity(allure.severity_level.BLOCKER) # 具体事例 # script/test_login.py @allure.severity(allure.severity_level.BLOCKER) @pytest.mark.parametrize("mobile,code,username", build_data()) def test_login(self, mobile, code, username): logging.info("mobile={} code={} username={}".format(mobile, code, username)) # 登录 self.login_proxy.login(mobile, code) # 截图 allure.attach(self.driver.get_screenshot_as_png(), "截图", allure.attachment_type.P NG) # 断言 is_exist = utils.exist_text(DriverUtil.get_mp_driver(), username) assert is_exist
-