0.3.9 • Published 1 year ago

@ayroblu/playwright-image-snapshot v0.3.9

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

playwright-image-snapshot

Enhanced image snapshots for @playwright/test. A modified fork of playwright-image-snapshot which is derived from jest-image-snapshot (https://github.com/americanexpress/jest-image-snapshot) for Playwright.

Installation

npm install --save-dev @ayroblu/playwright-image-snapshot

Usage

// add a global.d.ts to your src directory (if you use TypeScript)
import type {
  ImageSnapshotOptions,
  TestInfo,
} from "@ayroblu/playwright-image-snapshot";

declare global {
  namespace PlaywrightTest {
    interface Matchers<R> {
      toMatchImageSnapshot(
        testInfo: TestInfo,
        name: string[] | string,
        options?: ImageSnapshotOptions,
      ): R;
    }
  }
}

// playwright.config.ts file
import { toMatchImageSnapshot } from "playwright-image-snapshot";
expect.extend({ toMatchImageSnapshot });

// or if you want to configure it
import { configureToMatchImageSnapshot } from "playwright-image-snapshot";
const toMatchImageSnapshot = configureToMatchImageSnapshot({
  failureThreshold: process.env["CI"] ? 0.05 : 0.01,
});
expect.extend({ toMatchImageSnapshot });

// In your test.spec.ts
expect(await page.screenshot()).toMatchImageSnapshot(test.info(), ["folder-name", "name-to-identify-snapshot.png"]);

// alternatively for more control
// expect(await page.screenshot()).toMatchImageSnapshot(test.info(), "name-to-identify-snapshot.png", {
//   blur: 2,
//   comparisonMethod: "ssim",
//   failureThreshold: 0.02,
//   failureThresholdType: "percent",
// });
0.3.9

1 year ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago