UNPKG

@argos-ci/playwright

Version:

Playwright SDK for visual testing with Argos.

185 lines (179 loc) 5.73 kB
import { ScreenshotMetadata } from "@argos-ci/util"; import { StabilizationPluginOptions, ViewportOption } from "@argos-ci/browser"; import { ElementHandle, Frame, Locator, LocatorScreenshotOptions, Page, PageScreenshotOptions } from "@playwright/test"; //#region ../../node_modules/.pnpm/playwright@1.58.2/node_modules/playwright/types/test.d.ts // --- BEGINGLOBAL --- declare global { export namespace PlaywrightTest { export interface Matchers<R, T = unknown> {} } } // --- ENDGLOBAL --- /** * These tests are executed in Playwright environment that launches the browser * and provides a fresh page to each test. */ //#endregion //#region src/attachment.d.ts type ArgosAttachment = { name: string; contentType: string; path: string; }; //#endregion //#region src/aria-snapshot.d.ts type LocatorOptions$1 = Parameters<Page["locator"]>[1]; type ArgosSnapshotOptions = { /** * `Locator` or string selector of the element to take a snapshot of. */ element?: string | Locator; /** * Folder where the snapshots will be saved if not using the Argos reporter. * @default "./screenshots" */ root?: string; /** * Wait for the UI to stabilize before taking the snapshot. * Set to `false` to disable stabilization. * Pass an object to customize the stabilization. * @default true */ stabilize?: boolean | StabilizationPluginOptions; /** * Maximum time in milliseconds. Defaults to `0` - no timeout */ timeout?: number; } & LocatorOptions$1; /** * Stabilize the UI and takes a snapshot of the application under test. * * @example * argosAriaSnapshot(page, "my-screenshot") * @see https://playwright.dev/docs/aria-snapshots */ declare function argosAriaSnapshot( /** * Playwright `page` or `frame` object. */ handler: Page | Frame, /** * Name of the snapshot. Must be unique. */ name: string, /** * Options for the snapshot. */ options?: ArgosSnapshotOptions): Promise<ArgosAttachment[]>; //#endregion //#region src/screenshot.d.ts type LocatorOptions = Parameters<Page["locator"]>[1]; type ScreenshotOptions<TBase extends PageScreenshotOptions | LocatorScreenshotOptions> = Omit<TBase, "encoding" | "type" | "omitBackground" | "path">; type ArgosScreenshotOptions = { /** * `Locator` or string selector of the element to take a screenshot of. * Passing an `ElementHandle` is discouraged, use a `Locator` instead. */ element?: string | ElementHandle | Locator; /** * Viewports to take screenshots of. */ viewports?: ViewportOption[]; /** * Capture an ARIA snapshot along with the screenshot. * Each ARIA snapshot counts as an additional screenshot for billing. * When using the viewports setting, one ARIA snapshot is taken per viewport. * @see https://playwright.dev/docs/aria-snapshots#aria-snapshots * @default false */ ariaSnapshot?: boolean; /** * Custom CSS evaluated during the screenshot process. */ argosCSS?: string; /** * Disable hover effects by moving the mouse to the top-left corner of the document. * @default true */ disableHover?: boolean; /** * Sensitivity threshold between 0 and 1. * The higher the threshold, the less sensitive the diff will be. * @default 0.5 */ threshold?: number; /** * Folder where the screenshots will be saved if not using the Argos reporter. * @default "./screenshots" */ root?: string; /** * Tag or array of tags to attach to the screenshot. */ tag?: string | string[]; /** * Wait for the UI to stabilize before taking the screenshot. * Set to `false` to disable stabilization. * Pass an object to customize the stabilization. * @default true */ stabilize?: boolean | StabilizationPluginOptions; /** * Run a function before taking the screenshot. * When using viewports, this function will run before taking sreenshots on each viewport. */ beforeScreenshot?: (api: { /** * Run Argos stabilization alorithm. * Accepts an object to customize the stabilization. * Note that this function is independent of the `stabilize` option. */ runStabilization: (options?: StabilizationPluginOptions) => Promise<void>; }) => Promise<void> | void; /** * Run a function after taking the screenshot. * When using viewports, this function will run after taking sreenshots on each viewport. */ afterScreenshot?: () => Promise<void> | void; } & LocatorOptions & ScreenshotOptions<LocatorScreenshotOptions> & ScreenshotOptions<PageScreenshotOptions>; /** * Stabilize the UI and takes a screenshot of the application under test. * * @example * argosScreenshot(page, "my-screenshot") * @see https://argos-ci.com/docs/playwright#api-overview */ declare function argosScreenshot( /** * Playwright `page` or `frame` object. */ handler: Page | Frame, /** * Name of the screenshot. Must be unique. */ name: string, /** * Options for the screenshot. */ options?: ArgosScreenshotOptions): Promise<ArgosAttachment[]>; //#endregion //#region src/csp.d.ts /** * Get the CSP script hash. */ declare function getCSPScriptHash(): string; //#endregion //#region src/metadata.d.ts type MetadataConfig = { sdk: ScreenshotMetadata["sdk"]; playwrightLibraries: string[]; url?: string; test?: ScreenshotMetadata["test"]; story?: ScreenshotMetadata["story"]; viewport?: ScreenshotMetadata["viewport"]; }; /** * Set the metadata config. */ declare function setMetadataConfig(metadata: MetadataConfig): void; //#endregion export { type ArgosAttachment, type ArgosScreenshotOptions, type ArgosSnapshotOptions, setMetadataConfig as DO_NOT_USE_setMetadataConfig, type MetadataConfig, argosAriaSnapshot, argosScreenshot, getCSPScriptHash };