zoukankan      html  css  js  c++  java
  • pytest-html报告中添加报错截图

    写在conftest.py文件中,参考链接:https://blog.csdn.net/xiao_feng77/article/details/103902230

    #coding:utf-8
    
    from selenium import webdriver
    import pytest
    driver = None
    
    
    @pytest.mark.hookwrapper
    def pytest_runtest_makereport(item):
        """
        Extends the PyTest Plugin to take and embed screenshot in html report, whenever test fails.
        :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"
                _capture_screenshot(file_name)
                if file_name:
                    html = '<div><img src="%s" alt="screenshot" style="304px;height:228px;" ' 
                           'οnclick="window.open(this.src)" align="right"/></div>' % file_name
                    extra.append(pytest_html.extras.html(html))
            report.extra = extra
    
    
    def _capture_screenshot(name):
        driver.get_screenshot_as_file(name)
    
    
    @pytest.fixture(scope='session', autouse=True)
    def browser():
        global driver
        if driver is None:
            driver = webdriver.Chrome()
        return driver
  • 相关阅读:
    联合查询
    单表查询
    表和表之间的关系
    mysql完整性约束
    mysql 数据类型
    DRBD 数据镜像软件
    Memcached
    Redis
    SVN版本控制服务
    大数据hadoop分布式系统
  • 原文地址:https://www.cnblogs.com/yrxns/p/12760311.html
Copyright © 2011-2022 走看看