1 Star 0 Fork 0

xianting/ui_automater_selenium_test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
conftest.py 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
xianting 提交于 2020-11-30 10:27 . conftest中增加时间等待
# -*- coding: utf-8 -*-
# Author: xiantingDeng
# File: conftest.py
# Time: 17:23
import os
import pytest
import allure
from selenium import webdriver
from common.utils.log_util import logger
from common.utils.config import driver_config as config
from common.utils.file_util import get_img_file_path
# 屏幕截图专用driver
screenshot_driver = None
@pytest.fixture(scope="session")
def log():
#生成全局log日志工具
global log
log = logger()
return log
@pytest.hookimpl(tryfirst=True,hookwrapper=True)
def pytest_runtest_makereport(item,call):
outcome = yield
rep = outcome.get_result()
# we only look at actual failing test calls, not setup/teardown
if rep.when == "call" and rep.failed:
# mode = "a" if os.path.exists("failures") else "w"
# with open("failures", mode) as f:
# # let's also access a fixture for the fun of it
# if "tmpdir" in item.fixturenames:
# extra = " (%s)" % item.funcargs["tmpdir"]
# else:
# extra = ""
# f.write(rep.nodeid + extra + "\n")
img_name = get_img_file_path("用例失败截图")
screenshot_driver.save_screenshot(img_name)
with open(img_name, mode="rb") as f:
file = f.read()
allure.attach(file, "失败截图", allure.attachment_type.PNG)
# 调用截图函数
@pytest.fixture(scope="session")
def driver(log):
log.debug("读取配置信息:{}".format(config))
try:
log.debug("正在启动driver")
driver = webdriver.Chrome()
driver.implicitly_wait(10)
global screenshot_driver
screenshot_driver = driver
log.debug("当前运行的环境是:{}".format(config.get("environment")))
driver.implicitly_wait(10)
log.debug("打开:{}".format(config.get("url")))
driver.get(config.get("url"))
return driver
except Exception as e:
log.error("driver启动失败,失败原因:{}".format(e))
raise
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/d_xianting/ui_automater_selenium_test.git
git@gitee.com:d_xianting/ui_automater_selenium_test.git
d_xianting
ui_automater_selenium_test
ui_automater_selenium_test
master

搜索帮助