Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add screenshot/video file to pytest-html report #121

Open
mxschmitt opened this issue Jul 6, 2022 · 5 comments
Open

[FEATURE] Add screenshot/video file to pytest-html report #121

mxschmitt opened this issue Jul 6, 2022 · 5 comments

Comments

@mxschmitt
Copy link
Member

mxschmitt commented Jul 6, 2022

See this existing html report where we can add attachments: https://github.com/pytest-dev/pytest-html

Relates #105

@mxschmitt mxschmitt changed the title Add screenshot/video file to pytest-html report [FEATURE] Add screenshot/video file to pytest-html report Jul 6, 2022
@lubosjerabek
Copy link

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.

@sudip1990pudasaini
Copy link

Is there any update on this feature?

@fenchu
Copy link

fenchu commented Aug 15, 2023

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)

screenshot-enclosed

@smolkin895
Copy link

Hi! Would you add reporter like Node.js to main QA language?
https://playwright.dev/python/docs/test-reporters

@smojon
Copy link

smojon commented Mar 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants