pytest的allure测试报告

2022-03-12  本文已影响0人  失忆的蝴蝶

allure基础知识

1、执行测试用例需要增加参数

Jenkins集成allure测试报告需要在代码中增加对应的参数,还要在Jenkins中配置
'--clean-alluredir' 参数是为了每次获取测试报告前先清除json和text数据,不然多次运行会累积太多数据
--alluredir 是设置测试报告路径

pytest.main([
        '-s',
        '-v',
        '-m',
        'success',
        '--clean-alluredir',
        '--alluredir=allure-results'
)

2、Jenkins中的配置参考:

https://www.jianshu.com/p/c326844087ac

jenkins集成web自动化常见问题

注意事项
1. 如果出现不能识别python命令
需要设置python命令的系统环境变量(jenkins在windows是以服务的形式安装的)
2. 日志中报错 "cannot find Chrome binary",jenkins找不到谷歌浏览器的执行文件
需要将谷歌浏览器的可执行文件路径设置到系统环境变量
3. 如果jenkins是以服务的形式安装
那么执行web自动化的时候是看不到界面的
4. 以命令行的形式启动的jenkins运行web自动化的时候可以看见界面
5. 构建的时候如果以pytest命令去构建报找不到包的错误
不能能直接运行pytest命令,需要导入当前的路径,运行下面的命令
python -m pytest -s -v
python -m 可以帮助导入当前路径到环境变量
6. 以命令行的形式启动的jenkins运行web自动化的时候也需要不显示浏览器
这种情况,可以设置无头浏览器

selenium设置无头浏览器

在运行代码的时候,可以实现不打开浏览器界面

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
 # 无头参数
 chrome_options.add_argument('--headless')

 with webdriver.Chrome( options=chrome_options) as wd:
         # 最大化浏览器
          wd.maximize_window()
上一篇 下一篇

猜你喜欢

热点阅读