Screenshots
The page each test was looking at, beside the suite and the error it belongs to
No screenshot matches what you asked for.
No screenshots in this run
A test that fails holding a Selenium driver or a Playwright page is
photographed for you - no hook, no fixture, nothing to import. This run
was holding neither, and attached nothing of its own.
1Nothing to writeautomatic
The browser is already in the test’s own fixtures and the reporter is
already standing in its teardown, so the picture is taken there - the last
moment before the driver is quit. What makes something a browser is that it
can hand over a PNG, so Selenium, Playwright, appium, splinter and a wrapper
of your own all work, whatever the fixture is called.
def test_checkout(page): # or driver, or whatever you called it page.goto("/cart") assert page.locator("h1").inner_text() == "Cart" # fails, and is photographed
Failures only, by default. --report-screenshots=all photographs every
test, none turns the automatic capture off - and attach below
keeps working either way.
2Or take the picture yourself
attach takes the image rather than the browser, so anything that can
produce a PNG reaches the report - a page mid-test, a chart, a rendered PDF,
an image diff. A test that attaches its own picture is not photographed
again on the way out.
from pytest_html_reporter import attach attach(data=driver.get_screenshot_as_png()) # Selenium attach(data=page.screenshot()) # Playwright attach(data=await page.screenshot()) # Playwright, async API
3Async tests, and unittest
The automatic capture is synchronous, so an async Playwright page has
nowhere to await - attach from the body instead. A unittest suite that
quits its driver in tearDown has already closed the browser by the time
the capture would run, so it attaches from there, before the quit.
async def test_home(page): # Playwright, async API try: assert await page.title() == "Example Domain" except AssertionError: attach(data=await page.screenshot()) raise def tearDown(self): # unittest attach(data=self.driver.get_screenshot_as_png()) self.driver.quit() # after, never before
Every image is kept whatever the test did - a screenshot of a pass is a
baseline worth having. Each one also lands on the Screens column of the
Test Metrics row it belongs to, next to the error it explains.