Skip to main content

Capture screenshots, HTML, and console logs on Playwright test failures

Project description

Capture debugging artifacts on Playwright test failures

Release Notes Downloads GitHub CI Status License: MIT

When your Playwright tests fail, you need to see what went wrong. This pytest plugin does a couple things to make it easier to debug and build playwight tests:

  1. Automatically captures HTML, screenshots, console logs, and failure summaries the moment a test fails and dumps them into a per-test folder for easy debugging.
  2. Allows you to assert that no console errors were logged during a test.
  3. Automatically retry tests that fail due to playwright flakiness

No more guessing what the page looked like, what JavaScript errors occurred, or what the actual DOM content was.

Installation

uv add --dev pytest-playwright-artifacts

The plugin activates automatically once installed. No configuration needed.

Usage

Artifacts on failure

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.

Retry on Playwright timeouts

Playwright tests can flake due to network latency or slow animations. The plugin can retry a test automatically when it fails with a TimeoutError. Only playwright._impl._errors.TimeoutError triggers a retry — assertion failures and other errors fail immediately. Retried attempts show as R / RERUN in pytest output.

Per-test

@pytest.mark.playwright_timeout_retries(2)
def test_checkout(page):
    page.goto("https://example.com/checkout")
    page.click("#pay-button")
    expect(page.locator(".success")).to_be_visible()

Per-folder

Add a pytestmark to conftest.py in the folder you want to cover:

# tests/e2e/conftest.py
import pytest

pytestmark = [pytest.mark.playwright_timeout_retries(2)]

Global default

Set a default for the entire suite in pyproject.toml. A marker on an individual test or folder always takes precedence.

[tool.pytest.ini_options]
playwright_timeout_retries = 2

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\\].*",
]

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

Change artifact output directory

By default, artifacts are saved to test-results/. You can customize this:

Command line:

pytest --playwright-artifacts-output=my-artifacts

pyproject.toml:

[tool.pytest.ini_options]
playwright_artifacts_output = "my-artifacts"

Related Projects

  • pytest-playwright-visual-snapshot: Adds visual regression testing capabilities to your Playwright and pytest suite.
  • playwright-trace-analyzer: Provides a CLI for inspecting Playwright trace files without needing the full browser viewer.
  • pytest-plugin-utils: Offers reusable logic for managing artifacts and configurations when building other pytest plugins.
  • gh-clean-artifacts: Helps manage storage costs by pruning old or large GitHub Actions artifacts.
  • pytest-line-runner: Simplifies test execution by allowing you to run pytest tests using file line numbers.
  • pytest-celery-utils: Enables inspection of Celery task queues in Redis directly from your pytest environment.
  • python-package-prompts: Contains LLM instructions for maintaining Python standards across projects using pytest and other libraries.

MIT License


This project was created from iloveitaly/python-package-template

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.2.0.tar.gz (7.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.2.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_playwright_artifacts-0.2.0.tar.gz
  • Upload date:
  • Size: 7.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.2.0.tar.gz
Algorithm Hash digest
SHA256 3a690c6f7a9a839a42b4f52111eb3cca284cff1115607443f7312936b6ef2c0c
MD5 398aef56403dcf7da06aba193fe838c3
BLAKE2b-256 5c250952655c275f22f6638350e23c2785c9eaa447a93a697f3f902c9fb1654b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_playwright_artifacts-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa788ed52b6ed9f706962c819a737bfa01465dc55d03471907f9eed09579a5b8
MD5 18e9fa72adfe89631ac9458209cd011b
BLAKE2b-256 d58b63a1d3af8d05f8cdc8264ce698c32903fa140fdfec08c9fe91b74c7aaf02

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