pytest-reporter-html1 icon indicating copy to clipboard operation
pytest-reporter-html1 copied to clipboard

Include screenshot to the report where ever the test fails

Open rpagadala20 opened this issue 3 years ago • 5 comments

Hi,

It would be great if we include the screenshot in the report upon step failure

Thanks

rpagadala20 avatar Mar 22 '21 06:03 rpagadala20

Got close to this. In my selenium driver class, I incorporated a screenshot function that names the screenshot with the seconds from the epoch in the file name. Then in the hook pytest_runtest_makereport, I include all screenshots in the test that occured between the call.start and call.stop for each test phase (setup, call, teardown), this means, any screenshots taken over the course of the test are saved in the test report under the correct test

eoinmarron avatar Nov 05 '21 09:11 eoinmarron

I'm also interested in this, I can easily name the screenshots/videos based on the exact test name but I'm not sure exactly how to add them to the report, any hints?

Nicfar avatar Nov 25 '21 02:11 Nicfar

Figured it out, I am naming my screenshots and videos (in playwright) exactly as the test name is with all marks and adding them to extras in

@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item: Any) -> Generator[None, Any, None]:
    if rep.when == 'call' and rep.failed is True:
        rep.extra = [
            {
                "name": "Screenshot",
                "format": "image",
                "content": os.path.join(os.getcwd(), "reports", slugify(rep.nodeid), f"{item.name}.png"),
            },
            {
                "name": "Recording",
                "format": "video",
                "content": os.path.join(os.getcwd(), "reports", slugify(rep.nodeid), f"{item.name}.webm"),
            },
        ]

Nicfar avatar Nov 25 '21 15:11 Nicfar

Could you please provide detail setup to capture screenshot and attach it to report.

thanks in advance!!!

Sathish787 avatar May 13 '23 16:05 Sathish787

Hi @Sathish787 , have you managed to attach it to your report? I would like to do the same but not sure how. Hoping you could help us @christiansandberg / @Nicfar , thank you

sayurionishi avatar Sep 11 '23 00:09 sayurionishi