import { Page, Locator } from '@playwright/test'; import { CountVerifyOptions, TextVerifyOptions } from '../enum/Options'; /** * Internal shape that `Verifications.visuallyMatches` consumes. The * high-level step layer (`steps.verifyVisualMatch`) resolves * {@link import('../enum/Options').VisualMaskTarget} entries to * Playwright Locators before calling in; this interface is therefore * already-resolved. */ export interface VisualMatchPrimitiveOptions { mask?: Locator[]; maskColor?: string; fullPage?: boolean; maxDiffPixelRatio?: number; maxDiffPixels?: number; timeout?: number; errorMessage?: string; } import { WebElement } from '@civitas-cerebrum/element-repository'; /** Shared options every Verifications method accepts. */ export interface VerifyOptions { /** When `true`, flips the assertion — passes when the underlying condition fails. */ negated?: boolean; /** Override the class-level timeout for this single assertion. */ timeout?: number; /** Custom message prepended to Playwright's error on failure. */ errorMessage?: string; } /** * The `Verifications` class provides a unified wrapper around Playwright's `expect` assertions. * It standardizes timeouts and includes advanced custom, robust verifications * (like image decoding) to keep your test assertions clean and reliable. */ export declare class Verifications { private page; /** The standard timeout applied to all verifications in this class. */ private ELEMENT_TIMEOUT; /** * Initializes the Verifications class. * @param page - The current Playwright Page object. * @param timeout - Optional override for the default element timeout. */ constructor(page: Page, timeout?: number); /** Pick `expect(locator)` vs `expect(locator).not` based on options, with the right timeout and custom error message. */ private prepare; /** * Asserts the text content of an element. * Can verify exact text matches or simply check that the element contains some text. * @param target - A Playwright Locator or Element pointing to the target element. * @param expectedText - The exact text string expected (optional if checking 'notEmpty'). * @param options - Configuration to alter the verification behavior. */ text(target: WebElement, expectedText?: string, options?: TextVerifyOptions & VerifyOptions): Promise; /** * Asserts that the specified element contains the expected substring. */ textContains(target: WebElement, expectedText: string, options?: VerifyOptions): Promise; /** Asserts the element's text matches a regular expression. */ textMatches(target: WebElement, regex: RegExp, options?: VerifyOptions): Promise; /** Asserts the element's text starts with the given prefix. */ textStartsWith(target: WebElement, prefix: string, options?: VerifyOptions): Promise; /** Asserts the element's text ends with the given suffix. */ textEndsWith(target: WebElement, suffix: string, options?: VerifyOptions): Promise; /** * Asserts that the specified element is attached to the DOM and is visible. * @param target - A Playwright Locator or Element pointing to the target element. */ presence(target: WebElement, options?: VerifyOptions): Promise; /** * Asserts that the specified element is either hidden or completely detached from the DOM. * Accepts a Target or a raw selector string to prevent unnecessary repository waits. * @param selectorOrTarget - A Playwright Locator, Element, or raw selector string. */ absence(selectorOrTarget: WebElement | string): Promise; /** * Asserts the state of an element using Playwright's built-in locator assertions. * @param target - A Playwright Locator or Element pointing to the target element. * @param state - The expected state to verify. */ state(target: WebElement, state: 'enabled' | 'disabled' | 'editable' | 'checked' | 'focused' | 'visible' | 'hidden' | 'attached' | 'inViewport', options?: VerifyOptions): Promise; /** * Asserts the state of an element using Playwright's built-in locator assertions. * @param locator - A CSS/XPath selector string to locate the target element. * @param state - The expected state to verify. * @param timeout - Optional timeout in milliseconds, overrides the default ELEMENT_TIMEOUT. */ state(locator: string, state: 'enabled' | 'disabled' | 'editable' | 'checked' | 'focused' | 'visible' | 'hidden' | 'attached' | 'inViewport', timeout?: number): Promise; /** * Asserts that the current browser URL contains the expected substring. * Evaluates using a case-insensitive regular expression. * @param text - The substring expected to be present within the active URL. */ urlContains(text: string): Promise; /** * Asserts the document body contains the given text (substring or RegExp). * Web-first: retries until the body text matches or the timeout expires. * @param text - Substring or RegExp expected somewhere in the rendered body text. */ pageContainsText(text: string | RegExp, options?: VerifyOptions): Promise; /** * Asserts the document body does NOT contain the given text — the negated * companion to {@link pageContainsText}. Use for "not a 404" / no-error-copy * checks. Text-level only: raw markup never appears in rendered text — for * markup-level assertions use `pageHtmlContains` with `{ negated: true }`. * @param text - Substring or RegExp expected to be absent from the body text. */ pageNotContainsText(text: string | RegExp, options?: VerifyOptions): Promise; /** * Asserts the page `` equals the given string or matches the RegExp. * Wraps Playwright's `expect(page).toHaveTitle`. * @param title - Exact title string or a RegExp the title must match. */ pageTitle(title: string | RegExp, options?: VerifyOptions): Promise<void>; /** Read innerHTML / outerHTML for an element-scoped html assertion. Locator-only — caller resolves the WebElement. */ private readElementHtml; /** Read the page-level HTML — body innerHTML by default, full document outerHTML when `outer`. */ private readPageHtml; /** * Polls a string predicate against an HTML source until it satisfies the * predicate (or its negation) or the timeout expires. Single source of * truth for every html / pageHtml assertion variant. */ private pollHtml; /** Asserts the element's `innerHTML` (or `outerHTML` with `{ outer: true }`) equals the expected string exactly. */ html(target: WebElement, expected: string, options?: VerifyOptions & { outer?: boolean; }): Promise<void>; /** Asserts the element's HTML contains the given substring. */ htmlContains(target: WebElement, substring: string, options?: VerifyOptions & { outer?: boolean; }): Promise<void>; /** Asserts the element's HTML matches a regular expression. */ htmlMatches(target: WebElement, regex: RegExp, options?: VerifyOptions & { outer?: boolean; }): Promise<void>; /** Asserts the element's HTML starts with the given prefix. */ htmlStartsWith(target: WebElement, prefix: string, options?: VerifyOptions & { outer?: boolean; }): Promise<void>; /** Asserts the element's HTML ends with the given suffix. */ htmlEndsWith(target: WebElement, suffix: string, options?: VerifyOptions & { outer?: boolean; }): Promise<void>; /** Asserts the page-level HTML equals the expected string exactly. Defaults to `document.body.innerHTML`; pass `{ outer: true }` for the full document outerHTML. */ pageHtml(expected: string, options?: VerifyOptions & { outer?: boolean; }): Promise<void>; /** Asserts the page-level HTML contains the given substring. */ pageHtmlContains(substring: string, options?: VerifyOptions & { outer?: boolean; }): Promise<void>; /** Asserts the page-level HTML matches a regular expression. */ pageHtmlMatches(regex: RegExp, options?: VerifyOptions & { outer?: boolean; }): Promise<void>; /** Asserts the page-level HTML starts with the given prefix. */ pageHtmlStartsWith(prefix: string, options?: VerifyOptions & { outer?: boolean; }): Promise<void>; /** Asserts the page-level HTML ends with the given suffix. */ pageHtmlEndsWith(suffix: string, options?: VerifyOptions & { outer?: boolean; }): Promise<void>; /** Read a value from `window.localStorage`. */ private readLocalStorage; /** Read a value from `window.sessionStorage`. */ private readSessionStorage; /** * Polls a `string | null` predicate against a storage source until it * satisfies the predicate (or its negation) or the timeout expires. * Single source of truth for every localStorage / sessionStorage variant. */ private pollStorage; /** Asserts that `localStorage[key]` equals the expected string exactly. */ localStorage(key: string, expected: string, options?: VerifyOptions): Promise<void>; /** Asserts that `localStorage[key]` contains the given substring. Fails if the key is absent. */ localStorageContains(key: string, substring: string, options?: VerifyOptions): Promise<void>; /** Asserts that `localStorage[key]` matches a regular expression. Fails if the key is absent. */ localStorageMatches(key: string, regex: RegExp, options?: VerifyOptions): Promise<void>; /** Asserts that the `localStorage` key is present (any non-null value). Use `{ negated: true }` to assert absence. */ localStoragePresent(key: string, options?: VerifyOptions): Promise<void>; /** Asserts that `sessionStorage[key]` equals the expected string exactly. */ sessionStorage(key: string, expected: string, options?: VerifyOptions): Promise<void>; /** Asserts that `sessionStorage[key]` contains the given substring. Fails if the key is absent. */ sessionStorageContains(key: string, substring: string, options?: VerifyOptions): Promise<void>; /** Asserts that `sessionStorage[key]` matches a regular expression. Fails if the key is absent. */ sessionStorageMatches(key: string, regex: RegExp, options?: VerifyOptions): Promise<void>; /** Asserts that the `sessionStorage` key is present (any non-null value). Use `{ negated: true }` to assert absence. */ sessionStoragePresent(key: string, options?: VerifyOptions): Promise<void>; /** * Polls a `window` value (read by dotted path) against a predicate until it * holds (or its negation) or the timeout expires. The single source of * truth behind `steps.verifyWindowProperty`. The `describe` string is the * human-readable tail of the failure header (e.g. `to be greater than 0`). */ windowProperty(path: string, predicate: (value: unknown) => boolean, describe: string, options?: VerifyOptions): Promise<void>; /** * Asserts that an element has a specific HTML attribute with an exact value. * @param target - A Playwright Locator or Element pointing to the target element. * @param attributeName - The name of the HTML attribute to check (e.g., 'href', 'class', 'alt'). * @param expectedValue - The exact expected value of the attribute. */ attribute(target: WebElement, attributeName: string, expectedValue: string, options?: VerifyOptions): Promise<void>; /** Asserts that a given HTML attribute contains the substring. */ attributeContains(target: WebElement, attributeName: string, substring: string, options?: VerifyOptions): Promise<void>; /** Asserts that a given HTML attribute matches a regular expression. */ attributeMatches(target: WebElement, attributeName: string, regex: RegExp, options?: VerifyOptions): Promise<void>; /** Asserts that the element has a given HTML attribute present (regardless of value). */ hasAttribute(target: WebElement, attributeName: string, options?: VerifyOptions): Promise<void>; /** * Performs a multi-step verification on one or more images. * * By default checks visibility, a non-empty `src` attribute, and a non-zero * `naturalWidth`. Pass `{ verifyDecoded: true }` to additionally run the * browser-native `Image.decode()` round-trip, which confirms the image is * fully rendered and not a broken link but adds a CDP round-trip per image. * * @param imagesTarget - A Playwright Locator or Element pointing to the image element(s). * @param scroll - Whether to scroll the image(s) into the viewport before verifying (default: true). * @param options - `verifyDecoded`: run `Image.decode()` per image (default: false). * @throws Will throw an error if no images are found or any image fails verification. */ images(imagesTarget: WebElement, scroll?: boolean, options?: { verifyDecoded?: boolean; }): Promise<void>; /** * Asserts that an input, textarea, or select element has the expected value. * Unlike `text()` which checks `textContent`, this checks the `value` property. * @param target - A Playwright Locator or Element pointing to the input element. * @param expectedValue - The expected value of the input. */ inputValue(target: WebElement, expectedValue: string, options?: VerifyOptions): Promise<void>; /** Asserts the input value contains the given substring. */ inputValueContains(target: WebElement, substring: string, options?: VerifyOptions): Promise<void>; /** Asserts the input value matches a regular expression. */ inputValueMatches(target: WebElement, regex: RegExp, options?: VerifyOptions): Promise<void>; /** Asserts the input value starts with the given prefix. */ inputValueStartsWith(target: WebElement, prefix: string, options?: VerifyOptions): Promise<void>; /** Asserts the input value ends with the given suffix. */ inputValueEndsWith(target: WebElement, suffix: string, options?: VerifyOptions): Promise<void>; /** * Asserts the number of open browser tabs/pages matches the expected count. * @param expectedCount - The expected number of open tabs. */ tabCount(expectedCount: number): Promise<void>; /** * Asserts that two values are strictly equal. * Typically used to compare two values captured from the page via getText() or getInputValue(). * Both parameters accept null to support values that may not be present in the DOM. * * @param actual - The value captured from the page. * @param expected - The value to compare against. Can be another captured value or a literal string. */ expectEqual(actual: string | null, expected: string | null): void; /** * Asserts that two values are not equal. * Typically used to confirm that two values captured from the page differ from each other. * Both parameters accept null to support values that may not be present in the DOM. * * @param actual - The value captured from the page. * @param notExpected - The value that actual must differ from. */ expectNotEqual(actual: string | null, notExpected: string | null): void; /** * Asserts that the text contents of all elements matching the locator appear in the exact * order specified by `expectedTexts`. Each element's trimmed `textContent` is compared * against the corresponding entry in the array. * @param target - A Playwright Locator or Element resolving to the list of elements. * @param expectedTexts - The expected text values in order. */ order(target: WebElement, expectedTexts: string[]): Promise<void>; /** * Asserts that a computed CSS property of an element matches the expected value. * Uses `getComputedStyle` under the hood, so values are in their resolved form * (e.g. `'rgb(255, 0, 0)'` instead of `'red'`). * @param target - A Playwright Locator or Element pointing to the target element. * @param property - The CSS property name (e.g. `'color'`, `'font-size'`, `'display'`). * @param expectedValue - The expected computed value. */ cssProperty(target: WebElement, property: string, expectedValue: string, options?: VerifyOptions): Promise<void>; /** Asserts a computed CSS property value contains the given substring. */ cssPropertyContains(target: WebElement, property: string, substring: string, options?: VerifyOptions): Promise<void>; /** Asserts a computed CSS property value matches a regular expression. */ cssPropertyMatches(target: WebElement, property: string, regex: RegExp, options?: VerifyOptions): Promise<void>; /** * Asserts that the text contents of all elements matching the locator are sorted * in the specified direction. Each element's trimmed `textContent` is compared * using locale-aware string comparison. * @param target - A Playwright Locator or Element resolving to the list of elements. * @param direction - `'asc'` for ascending (A-Z) or `'desc'` for descending (Z-A). */ listOrder(target: WebElement, direction: 'asc' | 'desc'): Promise<void>; /** * Asserts the number of elements matching the locator based on the provided conditions. * Exactly one of `exactly`, `greaterThan`, `lessThan`, `greaterThanOrEqual`, or * `lessThanOrEqual` must be set on `options`. * @param target - A Playwright Locator or Element pointing to the target elements. * @param options - Configuration specifying which comparator to apply and the expected count. * @param verifyOptions - Optional `{ negated?, timeout?, errorMessage? }` override. * @throws Error if any count in `options` is negative, or if the count does not match. */ count(target: WebElement, options: CountVerifyOptions, verifyOptions?: VerifyOptions): Promise<void>; /** * Assert that the current page or a specific element matches its * stored baseline screenshot, optionally masking regions of dynamic * data. * * @param target — pass the framework's `WebElement` for an * element snapshot, or the framework's * page object via `this.page` semantics * (handled by the higher-level step). * @param snapshotName — file name for the baseline (e.g. * `dashboard.png`). Playwright derives * OS- / browser-specific directories * automatically. * @param options — see {@link VisualMatchOptions}. Use * `mask` for any region whose content * changes between runs (clocks, ids, * live counters, "updated N minutes ago" * badges, user avatars, etc.). */ visuallyMatches(target: WebElement | Page, snapshotName?: string, options?: VisualMatchPrimitiveOptions): Promise<void>; /** Type guard — distinguishes a Playwright Page from a framework WebElement. */ private isPage; }