Python+selenium自动化测试框架生成allure测试报告
1、 官网下载allure https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/

2、解压安装包,allure的bin路径添加至环境变量

3、cmd,确认allure版本号: allure --version

4、pyCharm安装allure-pytest插件:pip install allure-pytest
5、在项目根目录运行pytest用例生成allure报告

pytest.ini 源码:
[pytest]
addopts =-vs --alluredir ./temp --clean-alluredir
testpaths = ./testcase
python_files = test_*.py
python_functions = test_*
python_classes = Test*
6、执行测试
import os
if __name__ == '__main__':
# 第一步:生成json格式临时文件
pytest.main(['-vs',r'D:\Python\project\xxx_auto\testcase','--alluredir','./temp','--clean-alluredir'])
# 第二步:根据json格式临时文件生成allure报告
os.system("allure generate ./temp -o ./report --clean")
7、生成测试报告,打开index.html即可


过程中遇到的问题:
1、pyCharm运行,控制台输出乱码
设置Settings--Editor---File Encodings如下:

2、报错:‘allure’ 不是内部或外部命令,也不是可运行的程序或批处理文件。
1)allure的版本和allure-pytest插件版本号尽量保持一致,例如:allure:2.8.1
allure-pytest: 2.8.1
- 配置完allure的环境变量后,重启pyCharm,如果打开了多个窗口,都需要关闭
网友评论