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 to easily download them as artifacts
ability to mask out certain elements which cause comparison brittleness
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
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("...")
Masking Elements
You can mask certain elements during screenshot capture to prevent them from causing comparison failures. This is useful for dynamic content like timestamps, user avatars, etc.
By default, if a snapshot's dimensions change (width or height), pytest will raise an exception without generating visual comparison images. This can happen when taking snapshots of individual elements whose size changes due to visual modifications - for example, a button with updated padding or a container that dynamically adjusts its height.
To see visual diffs even when dimensions change, use the --ignore-size-diff flag:
When enabled, snapshots with different dimensions will still generate the actual_, expected_, and diff_ images in the failures folder, allowing you to see exactly what changed visually.
Example use-case: You're testing a UI component and update the button padding. Without --ignore-size-diff, you'd just get an exception. With it enabled, you get visual diff images showing the padding changes, making it easy to review and decide if the changes are intentional.
Disabling Visual Snapshots Locally
If CI screenshots are the source of truth, you can disable local visual assertions to keep developer runs fast and avoid creating/comparing snapshots; use pytest --disable-visual-snapshots (or set playwright_visual_disable_snapshots = true in pytest.ini). When disabled, assert_snapshot is a noop and logs a warning.
GitHub Actions Script
The CI Chrome will be slightly different than your dev chrome. You'll want to pull down screenshots from your CI run and use those for comparison. Here's a script to do that: