距离上次更新已经过去 180 天了,文章内容可能已经过时。若内容或图片失效,请留言反馈(部分素材来自网络)。
记录配置 allure 的过程和简单的使用
检查是否有 java 的运行环境
- win+r 输入 cmd 回车,打开终端窗口
- 输入 Java 回车
- 如果没有显示就代表你的电脑没有安装 Java 运行环境,可以参考我的其中的一个教程,那里有关于 Java 的安装过程 JMeter 和 java8 安装
下载 allure
如果下载慢可以使用以下链接,不过它更新速度比较慢,不过也够用了。
配置 allure
- 把下载好的 allure 压缩包放到你需要解压的文件夹下。
- 进入到
allure文件夹下,找到bin目录。
- 找到
allure.exe,cd到此目录下运行allure.exe脚本。
- 运行结果如下
配置 allure 环境变量
- 复制
allure的bin目录路径,打开环境变量并找到path点击编辑
- 粘贴刚才复制的路径到
path下
- 点击确定后检查是否配置成功,
win+r输入cmd回车运行终端,输入allure回车(也可以用 allure –version 检查版本号)
allure-pytest 搭建
- 安装
allure-pytest和pytest
pytest 是组织和运行用例,并得到结果
- py 测试文件必须以
test_开头(或者以_test结尾)- 测试类必须以
Test开头,并且不能有init方法- 测试方法必须以
test_开头- 断言必须使用
assert
python
1 | pip install allure-pytest |
- 输入以下命令,执行
pytest生成allure的json结果文件
python
1 | pytest test_cals.py --alluredir ./report # ./report 也可以是文件夹的名称 |
使用指令太过于麻烦,可以使用
pytest.ini文件来运行(里面是不能出现中文的,注释可以删除)注:如果使用报错是因为 `ini` 文件不支持 `UTF-8` 格式文件,这里需要更改为 `ANSI` 码来执行文件ini
1
2
3
4
5
6
7
8
9 [pytest]
# 命令行参数
addopts = --alluredir ./temp -s
# 搜索文件名
python_files = class_datadriven.py
# 搜索的类名
python_classes = Test_*
# 搜索的函数名
python_function = test_*这里用了
os来执行指令,可以直接生成html文件
os.system('allure generate ./temp -o ./report --clean')使用解释
参数 解释 allure generate 命令,固定的 ./temp 临时的 json格式报告的路径-o 输出 output ./report 生成的 allure报告的路径–clean 清空./report 路径原来的报告
- 查看测试报告:
两种方式:
方式一:
输入
pytest test_py.py --alluredir ./temp(生成json文件,这里文件夹名称也可以是其它)测试完成后,查看实际报告,在线查看报告,会打开默认浏览器展示当前测试报告,在命令行输入:
allure serve ./report报告文件夹路径(生成 html)方法二:
allure generate ./temp -o ./report –clean(指定生成报告的路径)
allure open -h 127.0.0.1 -p 8888 ./report(启动本地服务生成链接查看报告)
附加
allure截图(在allure report中加入截图):python1
2
3
4
5
6
7
8
9
10from selenium.webdriver import Chrome
import allure
class BasePage:
def __init__(self,driver:Chrome):
self.driver = driver
def attach_screenshot(self,name="截图"):
file = self.driver.get_screenshot_as_png()
allure.attach(file,name=name,attachment_type=allure.attachment_type.PNG)
allure 图标自定义
由于看这个图标不好看,需要更改,这里需要会一点 css 基础。
找到里面的 static 文件夹,里面有 css 和 svg 文件,更改你需要的图标和大小。
然后在 allure 根目录下找到 congfig 文件夹,找到里面的 allure.yaml 文件
在下面加入 custom-logo-plugin 代码
评论
匿名评论隐私政策
✅ 你无需删除空行,直接评论以获取最佳展示效果








