Snapshot Helper

API reference for the veraSnapshot() helper function.

Import

import { veraSnapshot } from "@vera-ci/playwright-reporter";

Usage

The veraSnapshot function takes a named screenshot and automatically attaches it to the current Playwright test. Vera CI uses these named screenshots for pixel-level diffing against baselines.

import { test } from "@playwright/test";
import { veraSnapshot } from "@vera-ci/playwright-reporter";

test("my test", async ({ page }) => {
  await page.goto("/");
  await veraSnapshot(page, "homepage");
});

API

veraSnapshot(page: Page, name: string, options?: VeraSnapshotOptions): Promise<void>
ParameterTypeDescription
pagePageThe Playwright Page object
namestringA unique name for this screenshot
optionsVeraSnapshotOptionsOptional configuration (see below)

Options

OptionTypeDefaultDescription
fullPagebooleanfalseCapture the full scrollable page
elementstring | LocatorCSS selector or Playwright Locator to capture a specific element
waitForStablenumber500Milliseconds to wait for animations to settle. Pass 0 to disable

Examples

Capture a specific element:

await veraSnapshot(page, "navigation", {
  element: "nav.main-nav",
});

Capture using a Playwright Locator:

const card = page.getByTestId("product-card");
await veraSnapshot(page, "product-card", {
  element: card,
});

Capture a full-page screenshot with no stabilization delay:

await veraSnapshot(page, "full-page", {
  fullPage: true,
  waitForStable: 0,
});

See the Playwright Quickstart for a complete setup guide.