[FEATURE] Add screenshot/video file to pytest-html report
See this existing html report where we can add attachments: https://github.com/pytest-dev/pytest-html
Relates https://github.com/microsoft/playwright-pytest/issues/105
I think this would be amazing feature tbh. Like, incredibly useful. I was just thinking of adding this myself in our project but it makes much more sense to do this as a part of this repo.
Is there any update on this feature?
This is already supported in pytest-html, using the report.extra,
In my conftest.py, I have the following, this is called for every test, so you need to have a global to makes sure you only add uncataloged screenshots, You also need to use unique filenames of screenshots:
screenshots_used = {}
@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
pytest_html = item.config.pluginmanager.getplugin('html')
global extras
outcome = yield
#print("extras:{}".format(extras))
report = outcome.get_result()
extra = getattr(report, "extra", [])
report.description = str(item.function.__doc__)
if args.webhost and os.path.isdir(args.webhost[0]):
screens = [s for s in os.listdir(args.webhost[0]) if s.endswith('.png')]
for s in screens:
if s not in screenshots_used:
log.info(f"screenshot:{s}")
extra.append(pytest_html.extras.png(f"{args.webhost[0]}/{s}"))
screenshots_used[s] = 1
report.extra = extra
And in your pytest tests you have the following: (for me webhost is our testenvironment fixture like --webhost=test1), but it is the directory you add screenshots to in your test.
page.screenshot(path=f"{webhost}/02contact.png", full_page=True)
Hi! Would you add reporter like Node.js to main QA language? https://playwright.dev/python/docs/test-reporters
pytest-playwright can automatically generate screenshots and video for each test. So it would be great if pytest-html could automatically include those. I tried the approche proposed by @fenchu. But it wasn't successful because the image and videos are generated after the pytest_runtest_makereport hook is called.