pytest-reporter-html1
pytest-reporter-html1 copied to clipboard
Include screenshot to the report where ever the test fails
Hi,
It would be great if we include the screenshot in the report upon step failure
Thanks
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
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?
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"),
},
]
Could you please provide detail setup to capture screenshot and attach it to report.
thanks in advance!!!
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