html报告错误,pytest失败截图加载到html报告内

conftest.py 里添加截图的逻辑

# coding:utf-8

import os

from selenium import webdriver

import pytest

from common.settings import PROXY_SERVER

driver = None

@pytest.mark.hookwrapper

def pytest_runtest_makereport(item):

"""

当测试失败的时候,自动截图,展示到html报告中

:param item:

"""

pytest_html = item.config.pluginmanager.getplugin('html')

outcome = yield

report = outcome.get_result()

extra = getattr(report, 'extra', [])

if report.when == 'call' or report.when == "setup":

xfail = hasattr(report, 'wasxfail')

if (report.skipped and xfail) or (report.failed and not xfail):

file_name = report.nodeid.replace("::", "_") + ".png"

screen_img = _capture_screenshot()

if file_name:

html = '

'οnclick="window.open(this.src)" align="right"/>

' % screen_img

extra.append(pytest_html.extras.html(html))

report.extra = extra

def _capture_screenshot():

'''

截图保存为base64,展示到html中

:return:

'''

return driver.get_screenshot_as_base64()

@pytest.fixture(scope='session', autouse=True)

def browser():

global driver

chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument('--proxy-server={}'.format(PROXY_SERVER))

if os.getenv("DOCKER") == "True":

chrome_options.add_argument("--headless")

chrome_options.add_argument("--disable-gpu")

chrome_options.add_argument("--no-sandbox")

chrome_options.add_argument("--ignore-certificate-errors")

driver = webdriver.Chrome(options=chrome_options)

driver.implicitly_wait(30)

yield driver

driver.quit()

case 级别调用时

from page_object.application.app_create import AppCreatePage

class TestCreateApp():

def 测试创建应用(self, browser):

create_page = AppCreatePage(browser)

create_page.open_create_app()

create_page.create_app()

这里吧driver当做一个参数传给类,方便于page object模式开发写UI自动化

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值