@argos-ci/playwright
Version:
Playwright SDK for visual testing with Argos.
98 lines (93 loc) • 3.31 kB
TypeScript
import { ElementHandle, Locator, Page, PageScreenshotOptions, LocatorScreenshotOptions } from '@playwright/test';
import { ViewportOption, StabilizationPluginOptions } from '@argos-ci/browser';
import { ScreenshotMetadata } from '@argos-ci/util';
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[];
/**
* Custom CSS evaluated during the screenshot process.
*/
argosCSS?: string;
/**
* Disable hover effects by moving the mouse to the top-left corner of the page.
* @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;
/**
* 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` object.
*/
page: Page,
/**
* Name of the screenshot. Must be unique.
*/
name: string,
/**
* Options for the screenshot.
*/
options?: ArgosScreenshotOptions): Promise<void>;
/**
* Get the CSP script hash.
*/
declare function getCSPScriptHash(): string;
type MetadataConfig = {
sdk: ScreenshotMetadata["sdk"];
playwrightLibraries: string[];
};
/**
* Set the metadata config.
*/
declare function setMetadataConfig(metadata: MetadataConfig): void;
export { type ArgosScreenshotOptions, setMetadataConfig as DO_NOT_USE_setMetadataConfig, argosScreenshot, getCSPScriptHash };