Я использую бесплатную модель Jenkins для запуска тестовых примеров, но в отчете Jenkins изображения выглядят поврежденными, даже если в локальном отчете они отображаются правильно.
Это результат отчета Jenkins «Разбитое изображение в отчете Jenkins»

и это тот же результат в локальном отчете "видимые изображения в локальном отчете":

мои скриншоты находятся в MainFolder>Отчеты>скриншоты
и код, обрабатывающий снимок экрана, находится в MainFolder>Main>conftest
и это мой код
Код: Выделить всё
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item):
"""
Extends the PyTest Plugin to take and embed screenshots in the HTML report and JUnit XML,
whenever a test fails.
"""
pytest_html = item.config.pluginmanager.getplugin('html')
junit_xml = item.config.pluginmanager.getplugin('junitxml')
outcome = yield
report = outcome.get_result()
extra = getattr(report, 'extra', [])
if report.when in ['call', 'setup']:
xfail = hasattr(report, 'wasxfail')
if (report.skipped and xfail) or (report.failed and not xfail):
screenshots_folder = ensure_screenshot_folder()
screenshot_path = screenshots_folder / f"{report.nodeid.replace('::', '_')}.png"
try:
# Capture and save the screenshot
_capture_screenshot(screenshot_path)
if screenshot_path.exists():
# Embed screenshot in HTML report
if pytest_html:
html = (
f'
[img]{screenshot_path}[/img]
f'style="width:304px;height:228px;" '
f'onclick="window.open(this.src)" align="right"/>'
)
extra.append(pytest_html.extras.html(html))
# Embed screenshot in JUnit XML report
if junit_xml:
report.longrepr = str(report.longrepr) + (
f'\n'
)
except Exception as e:
# Log or handle screenshot failure
report.longrepr += f"\n[Warning] Failed to capture screenshot: {e}"
report.extras = extra
def ensure_screenshot_folder():
"""
Ensure the screenshots folder exists.
"""
project_root = Path(__file__).resolve().parent.parent # Adjust to your project structure
screenshots_folder = project_root / "Reports" / "screenshots"
screenshots_folder.mkdir(parents=True, exist_ok=True)
return screenshots_folder
def _capture_screenshot(screenshot_path):
"""
Capture a screenshot and save it to the specified path.
"""
if isinstance(driver, WebDriver):
driver.get_screenshot_as_file(str(screenshot_path))
else:
raise ValueError("WebDriver instance not available for capturing screenshots.")
Обратите внимание, что я использовал пост-действие в качестве артефактов сборки, и это работает правильно.
Подробнее здесь: https://stackoverflow.com/questions/792 ... ins-report
Мобильная версия