Skip to main content

Pytest plugin that captures HTML, screenshots, and console logs on Playwright test failures

Project description

Capture debugging artifacts on Playwright test failures

When your Playwright tests fail, you need to see what went wrong. This pytest plugin automatically captures HTML, screenshots, console logs, and failure summaries the moment a test fails.

I built this because debugging failed tests without artifacts is painful. You're left guessing what the page looked like, what JavaScript errors occurred, or what the actual DOM content was. This plugin captures all of that automatically.

Installation

uv add pytest-playwright-artifacts

Usage

The plugin activates automatically once installed. No configuration needed.

Basic Test

def test_my_page(page):
    page.goto("https://example.com")
    assert page.title() == "Example"

When this test fails, you'll find artifacts in test-results/<test-name>/:

  • failure.html - Rendered DOM content at the moment of failure
  • screenshot.png - Full-page screenshot
  • failure.txt - Failure summary with traceback
  • console_logs.log - All captured console messages

Fail tests on console errors

from pytest_playwright_artifacts import assert_no_console_errors

def test_no_console_errors(page, request):
    page.goto("https://example.com")
    assert_no_console_errors(request)

This fails the test if any console.error() messages were logged during the test.

Features

  • Automatic artifact capture on test failure: HTML, screenshots, failure summary, and console logs
  • Console log monitoring for all browser console messages during tests
  • Regex-based filtering to ignore noisy console messages
  • Helper assertion assert_no_console_errors() to fail tests on console errors
  • Per-test artifact directories for clean organization

Configuration

Filter noisy console messages

Use regex patterns to ignore known noisy messages:

pyproject.toml:

[tool.pytest.ini_options]
playwright_console_ignore = [
  "Invalid Sentry Dsn:.*",
  "Radar SDK: initialized.*",
  "\\[Meta Pixel\\].*",
]

pytest.ini:

[pytest]
playwright_console_ignore =
  Invalid Sentry Dsn:.*
  Radar SDK: initialized.*
  \\[Meta Pixel\\].*

Patterns match against both the raw console text and the formatted log line.

Change artifact output directory

pytest --output=my-artifacts

How it works

The plugin uses pytest hooks and fixtures to capture artifacts:

  1. An autouse fixture attaches a console listener to every Playwright page
  2. Console logs are stored in memory at request.config._playwright_console_logs[nodeid]
  3. The pytest_runtest_makereport hook detects test failures
  4. On failure, the plugin captures page content, takes a screenshot, and writes all artifacts
  5. Console logs are cleaned up from memory after test completion

Disabling features

Disable console logging:

# In pytest_playwright_artifacts/plugin.py, change:
@pytest.fixture(autouse=False)
def playwright_console_logging(...):

Disable failure artifacts: Comment out the pytest_runtest_makereport hook in plugin.py.

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_playwright_artifacts-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_playwright_artifacts-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest_playwright_artifacts-0.1.0.tar.gz.

File metadata

  • Download URL: pytest_playwright_artifacts-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pytest_playwright_artifacts-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b8eb437598dd054b4604b18fd0f88cfe20d607a4c8db2da9dd994c39d120d3d1
MD5 49351277f3bdd73f6d24fb1c0861321e
BLAKE2b-256 c8f14e67bfa8c30b365847cc2f91d8ed1b1dbf9ea31b761dc27cef357a5afcfc

See more details on using hashes here.

File details

Details for the file pytest_playwright_artifacts-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_playwright_artifacts-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pytest_playwright_artifacts-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 750392c2c76ee14f74cf8f39e9060da620cf6db1f24d137b061d410d254215c3
MD5 46d3267bbd2502d62175ac014b1d6cd6
BLAKE2b-256 7ae1631dd27ff80c3ba4a8a0784a4cc40ea21c034a6dfb58e361dfe97c413e5d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page