import type { Locator, Page, PageScreenshotOptions } from '@playwright/test'; export type Theme = 'light' | 'dark'; export type OnSwitchThemeCallback = (theme: Theme, page: Page) => Promise; export type ScreenshotOptions = Omit & { /** * An acceptable ratio of pixels that are different to the total amount of pixels, between `0` and `1`. Default is * configurable with `TestConfig.expect`. Unset by default. */ maxDiffPixelRatio?: number; /** * An acceptable amount of pixels that could be different. Default is configurable with `TestConfig.expect`. Unset by * default. */ maxDiffPixels?: number; /** * An acceptable perceived color difference in the [YIQ color space](https://en.wikipedia.org/wiki/YIQ) between the same * pixel in compared images, between zero (strict) and one (lax), default is configurable with `TestConfig.expect`. * Defaults to `0.2`. */ threshold?: number; }; export type OnBeforeScreenshotCallback = (page: Page, options: ScreenshotOptions) => Promise; export type MatchScreenshotOptions = { /** * The element or page to be screenshotted * @defaultValue `page` */ locator?: Locator | Page; /** * The name of the screenshot in the test, it is not necessary to specify it for a single screenshot * @defaultValue globalSettings.matchScreenshot.name */ name?: string; /** * Screenshot creation and comparison parameters (parameters of `toHaveScreenshot` call) * @defaultValue globalSettings.matchScreenshot.options */ options?: ScreenshotOptions; /** * CSS selectors (pure CSS) of elements to hide * @defaultValue globalSettings.matchScreenshot.hideBySelector */ hideBySelector?: string[]; /** * Pause before screenshot (ms) * @defaultValue globalSettings.matchScreenshot.pause */ pause?: number; /** * Use soft assertion * @defaultValue globalSettings.matchScreenshot.soft */ soft?: boolean; /** * Move the mouse cursor to the specified coordinates (to avoid unnecessary hover in the screenshot) */ moveMouse?: { x: number; y: number; } | [x: number, y: number] | number; /** * Should I add a slug to the screenshot file name? * @defaultValue globalSettings.matchScreenshot.shouldPrependSlugToName */ shouldPrependSlugToName?: boolean; /** * Topics that require a screenshot * By default, screenshots are taken for the current theme. Switching does not occur * @defaultValue globalSettings.matchScreenshot.themes */ themes?: Theme[]; /** * Callback before taking a screenshot. Useful for any special stabilizing actions * @param page Page current page * @defaultValue globalSettings.matchScreenshot.onBeforeScreenshot */ onBeforeScreenshot?: OnBeforeScreenshotCallback; /** * Callback to switch theme to pages before taking screenshot * By default, switches the theme using `page.emulateMedia({ colorScheme: theme });` * @param theme Theme The theme for which the screenshot will be taken * @param page Page current page * @defaultValue globalSettings.matchScreenshot.onSwitchTheme */ onSwitchTheme?: OnSwitchThemeCallback; }; /** * Performs a check on a screenshot, with a prefix of the test slug in the name */ export declare function matchScreenshot(page: Page, { locator, name, options, hideBySelector, pause, soft, moveMouse, shouldPrependSlugToName, themes, onBeforeScreenshot, onSwitchTheme, }?: MatchScreenshotOptions): Promise;