def pytest_runtest_makereport(item, call): """Replace common screenshot from html-report by full size screenshot.""" # pylint: disable=too-many-locals outcome = yield report = outcome.get_result() summary = [] extra = getattr(report, "extra", []) driver = getattr(item, "_driver", None) xfail = hasattr(report, "wasxfail") failure = (report.skipped and xfail) or (report.failed and not xfail) when = item.config.getini("selenium_capture_debug").lower() capture_debug = when == "always" or (when == "failure" and failure) pytest_html = item.config.pluginmanager.getplugin("html") if driver is not None and capture_debug and pytest_html is not None: exclude = item.config.getini("selenium_exclude_debug").lower() if "screenshot" not in exclude: try: screenshot = get_full_screenshot_as_base64(driver) for ex in extra: if ex["name"] == "Screenshot": extra.remove(ex) # add screenshot to the html report extra.append(pytest_html.extras.image(screenshot, "Screenshot")) except Exception as e: summary.append( "WARNING: Failed to gather screenshot: {0}".format(e)) if summary: report.sections.append(("pytest-selenium", "\n".join(summary))) report.extra = extra
def pytest_runtest_makereport(item, call): """Replace common screenshot from html-report by full size screenshot.""" # pylint: disable=too-many-locals outcome = yield report = outcome.get_result() summary = [] extra = getattr(report, "extra", []) driver = getattr(item, "_driver", None) xfail = hasattr(report, "wasxfail") failure = (report.skipped and xfail) or (report.failed and not xfail) when = item.config.getini("selenium_capture_debug").lower() capture_debug = when == "always" or (when == "failure" and failure) pytest_html = item.config.pluginmanager.getplugin("html") if driver is not None and capture_debug and pytest_html is not None: exclude = item.config.getini("selenium_exclude_debug").lower() if "screenshot" not in exclude: try: screenshot = get_full_screenshot_as_base64(driver) for ex in extra: if ex["name"] == "Screenshot": extra.remove(ex) # add screenshot to the html report extra.append(pytest_html.extras.image(screenshot, "Screenshot")) except Exception as e: summary.append("WARNING: Failed to gather screenshot: {0}".format(e)) if summary: report.sections.append(("pytest-selenium", "\n".join(summary))) report.extra = extra
def gather_screenshot(item, report, driver, summary, extra): """Add link to the screenshot of the full page to HTML report""" try: # Only below line is changed screenshot = get_full_screenshot_as_base64(driver) except Exception as e: summary.append('WARNING: Failed to gather screenshot: {0}'.format(e)) return pytest_html = item.config.pluginmanager.getplugin('html') if pytest_html is not None: extra.append(pytest_html.extras.image(screenshot, 'Screenshot'))