Allure自动化测试生成
Allure是一款轻量级并且非常灵活的开源测试报告框架。 它支持绝大多数测试框架, 例如TestNG、Pytest、JUint等。它简单易用,易于集成。
allure配置与安装(Windows)
1. 下载allure, 并配置环境变量,Windows下载zip包
下载地址:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/
解压下载的安装包,并配置环境变量
2. 安装allure 库, pip install allure-pytest
3. 查看环境变量时候配置成功,打开cmd,输入allure --version
生成报告
1. 将测试数据保存在./result目录下
pytest --alluredir=./result
2. 展示allure 测试报告
a. allure serve ./result 启用server, 打开测试报告
b. allure generate ./result/ -o ./report/ --clean 将./result 目录下的测试数据生成html报告到./report下
实例
代码
from time import sleep import allure from selenium import webdriver from selenium.webdriver.common.by import By @allure.feature('百度搜索') class TestDemo: @allure.story('百度搜索python') @allure.title('搜索成功案例') def test_case1(self): with allure.step('打开百度网页'): self.driver = webdriver.Chrome() self.driver.get('https://www.baidu.com') self.driver.maximize_window() self.driver.implicitly_wait(5) with allure.step('输入搜索词:python'): self.driver.find_element(By.ID, 'kw').send_keys('python') sleep(2) self.driver.find_element(By.ID, 'su').click() sleep(2) with allure.step('保存图片'): allure.attach(self.driver.get_screenshot_as_png(), '搜索python', allure.attachment_type.PNG) with allure.step('关闭浏览器'): self.driver.quit()
结果展示