Skip to main content

Easy pytest visual regression testing using playwright

Project description

Pytest Plugin for Visual Testing with Playwright

As of 2025-03-22 of all of the existing packages to do simple visual regression testing using playwright are long dead. I had a bunch of updates I wanted to make to existing systems so I rewrote the plugin with a bunch of updates:

  • snapshots are always written on CI
  • ability to mask out certain elements
  • failing on --update-snapshots to make users manually review images
  • snapshot name is optional, test_name[browser][os].png is auto-generated by default
  • multiple snapshots in a single test, file names are auto incremented
  • updated folder structure: snapshots/file_name/test_name/test_name[browser][os].png
  • ability to configure directories, etc via ini + pytest config.

You can see this implemented in a working project here.

Installation

pip install pytest-playwright-visual-snapshot

Usage

This plugin provides a assert_snapshot fixture which is used to create snapshots and compare it.

def test_myapp(page, assert_snapshot):
    page.goto("https://example.com")
    assert_snapshot(page)

Then, run pytest:

pytest

The first time you run pytest, snapshots will be created, and you will get the error:

New snapshot(s) created. Please review images

The next run, the snapshots comparison will take place. To update snapshots, run:

pytest --update-snapshots

After updating, tests will fail and you will need to review images.

In case of a mismatch, snapshot_tests_failures folder will be created with actual_.., expected_.. and diff_.. images generated.

Configuration

View all configuration options by running pytest --help. Here's a quick example:

# NOTE this runs on any pytest invocation, even if no tests are run
def pytest_configure(config: Config):
  config.option.playwright_visual_snapshots_path = Path("...")
  config.option.playwright_visual_snapshot_failures_path = Path("...")

API

  • threshold - sets the threshold for the comparison of the screenshots:0 to 1. Default is 0.1
  • fail_fast - If True, will fail after first different pixel. False by default

Alternatives

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_visual_snapshot-0.1.0.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

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

File details

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

File metadata

File hashes

Hashes for pytest_playwright_visual_snapshot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 018b68d844ad7af2116f80fb52fa9f39dd111e0eb7995e70ee48e4133145b0ac
MD5 821021da4b068a0ddfb5474017a79f8d
BLAKE2b-256 e3594909d8487fbffc3355d96f3a88155b3155ba1f393f24dbe50cb22d9c155f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_playwright_visual_snapshot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a97733e7ba7fbeb942b56ea6709b233641a4bd9c62a915488198c19df06692fa
MD5 6c8ad27706e332ee5d656679236837c3
BLAKE2b-256 99478b7bd4be06f4b093b12c1efc5db1323e0152517e7a742d58e16e25bbd77d

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