Skip to main content

Pytest Plugin for Visual Testing with Playwright

Based on pixelmatch-py image comparison library.

Expands assert_snapshot fixture from pytest-playwright-snapshot library

Main Features:

  • snapshots creation on the first run
  • visual review of mismatches
  • failing on --update-snapshots to make users manually review images
  • snapshot name is optional, test_name[browser][os].png is auto-generated by default
  • updated folder structure: snapshots/file_name/test_name/test_name[browser][os].png

Installation

$ pip install pytest-playwright-visual

Usage

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

Example:

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

Then, run pytest:

$ pytest

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

Failed: --> 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.

Folder Structure Example

img_2.png

API

assert_snapshot(page.screenshot(), threshold: float = 0.1, name='test_name[browser][os].png', fail_fast=False)

  • threshold - sets the threshold for the comparison of the screenshots:0 to 1. Default is 0.1
  • name - .png extensions only. Default is test_name[browser][os].png (recommended)
  • fail_fast - If True, will fail after first different pixel. False by default

License

Apache 2.0 LICENSE

Metadata

Release files for pytest-playwright-visual 2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-playwright-visual 2.1.2
File Size Uploaded
pytest-playwright-visual-2.1.2.tar.gz 120.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-playwright-visual 2.1.2
File Interpreter ABI Platform
pytest_playwright_visual-2.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 124.0 kB

Release files / pytest-playwright-visual-2.1.2.tar.gz

Download URL pytest-playwright-visual-2.1.2.tar.gz
Size 120.1 kB
Tags Source
SHA-256 checksum
How to use checksums
947e82bf565a347652d1dd0c90531f49e31507273f45e6277dc7413842c12dbf
BLAKE2b-256 checksum
How to use checksums
7204c16c31e0f466a7274a6933faf90cde85b3d57287350b341ce5befe2a5273
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release files / pytest_playwright_visual-2.1.2-py3-none-any.whl

Download URL pytest_playwright_visual-2.1.2-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75e38eac2fa8e611aecfda48bbc557b948bfec1a9a472a25c3fbd7e418a773e7
BLAKE2b-256 checksum
How to use checksums
ee64786a2f83823c91f7e83e6d8a4e4c826639712417ed9442ad23f54b01cd5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files

2.1.1

2 release files

2.1

2 release files

2.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page