playwright/docs/src/api/class-screenshotassertions.md
Andrey Lushnikov 4897967780
cherry-pick(#12627): bring back maxDiffPixels in toMatchSnapshot (#12701)
This patch reverts 2 commits that removed the feature from the method:
- "fix: explicitly ignore maxDiffPixels in toMatchSnapshot (#12570)"
  commit b8af8458d6.
- "chore: remove `maxDiffPixels` from toMatchSnapshot (#12539)"
  commit a3dff45974.
2022-03-11 17:02:44 -08:00

1.4 KiB

class: ScreenshotAssertions

  • langs: js

Playwright provides methods for comparing page and element screenshots with expected values stored in files. See also [method: PageAssertions.toHaveScreenshot] and [LocatorAssertions.toHaveScreenshot].

expect(screenshot).toMatchSnapshot('landing-page.png');

method: ScreenshotAssertions.toMatchSnapshot

Ensures that passed value, either a [string] or a [Buffer], matches the expected snapshot stored in the test snapshots directory.

// Basic usage.
expect(await page.screenshot()).toMatchSnapshot('landing-page.png');

// Configure image matching threshold.
expect(await page.screenshot()).toMatchSnapshot('landing-page.png', { threshold: 0.3 });

// Bring some structure to your snapshot files by passing file path segments.
expect(await page.screenshot()).toMatchSnapshot(['landing', 'step2.png']);
expect(await page.screenshot()).toMatchSnapshot(['landing', 'step3.png']);

Learn more about visual comparisons.

param: ScreenshotAssertions.toMatchSnapshot.name

  • name <[string]|[Array]<[string]>>

Snapshot name.

option: ScreenshotAssertions.toMatchSnapshot.maxDiffPixels = %%-assertions-max-diff-pixels-%%

option: ScreenshotAssertions.toMatchSnapshot.maxDiffPixelRatio = %%-assertions-max-diff-pixel-ratio-%%

option: ScreenshotAssertions.toMatchSnapshot.threshold = %%-assertions-threshold-%%