import type { Locator, Page } from 'playwright'; import type { VisitOptions } from './main.js'; import type { BasePage } from '../base/base_page.js'; import type { BaseInteraction } from '../base/base_interaction.js'; import type { BrowserContext, Browser as PlayWrightBrowser } from 'playwright'; /** * Types for custom methods we attach on playwright via * inbuilt decorators */ declare module 'playwright' { interface Page { /** * Use a page or an interaction to perform actions */ use(pageOrInteraction: T): InstanceType; /** * Pause page when condition is true */ pauseIf(condition: boolean): Promise; /** * Pause page when condition is false */ pauseUnless(condition: boolean): Promise; /** * Assert an element to exists */ assertExists(selector: string | Locator): Promise; /** * Assert an element to not exist */ assertNotExists(selector: string | Locator): Promise; /** * Assert an element to exists and have matching count */ assertElementsCount(selector: string | Locator, expectedCount: number): Promise; /** * Assert an element to be visible. Elements with display: none * and visibility:hidden are not visible. */ assertVisible(selector: string | Locator): Promise; /** * Assert an element to be not visible. Elements with display: none * and visibility:hidden are not visible. */ assertNotVisible(selector: string | Locator): Promise; /** * Assert the page title to match the expected * value */ assertTitle(expectedTitle: string): Promise; /** * Assert the page title to include a substring value */ assertTitleContains(expectedSubstring: string): Promise; /** * Assert the page URL to match the expected * value */ assertUrl(expectedUrl: string): Promise; /** * Assert the page URL to contain the expected substring */ assertUrlContains(expectedSubstring: string): Promise; /** * Assert the page URL to match regex */ assertUrlMatches(regex: RegExp): Promise; /** * Assert the page path to match the expected value. The URL * is parsed using the Node.js URL parser and the pathname * value is used for assertion. */ assertPath(expectedPathName: string): Promise; /** * Assert the page path to contain the expected substring. The URL * is parsed using the Node.js URL parser and the pathname value * is used for assertion. */ assertPathContains(expectedSubstring: string): Promise; /** * Assert the page path to match the expected regex. The URL is * parsed using the Node.js URL parser and the pathname value * is used for assertion. */ assertPathMatches(regex: RegExp): Promise; /** * Asserts the page URL querystring to match the subset * object */ assertQueryString(expectedSubset: Record): Promise; /** * Assert cookie to exist and optionally match the expected * value */ assertCookie(cookieName: string, value?: any): Promise; /** * Assert cookie to be missing */ assertCookieMissing(cookieName: string): Promise; /** * Assert innerText of a given selector to equal * the expected value */ assertText(selector: string | Locator, expectedValue: string): Promise; /** * Assert innerText of a given selector elements to match * the expected values */ assertElementsText(selector: string | Locator, expectedValues: string[]): Promise; /** * Assert innerText of a given selector to include * substring */ assertTextContains(selector: string | Locator, expectedSubstring: string): Promise; /** * Assert a checkbox to be checked */ assertChecked(selector: string | Locator): Promise; /** * Assert a checkbox not to be checked */ assertNotChecked(selector: string | Locator): Promise; /** * Assert an element to be disabled. All elements are considered * enabled, unless it is a button, select, input or a textarea * with disabled attribute */ assertDisabled(selector: string | Locator): Promise; /** * Assert an element to be not disabled. All elements are considered * enabled, unless it is a button, select, input or a textarea * with disabled attribute */ assertNotDisabled(selector: string | Locator): Promise; /** * Assert the input value to match the expected value. The assertion * must be performed against an `input`, `textarea` or a `select` * dropdown. */ assertInputValue(selector: string | Locator, expectedValue: string): Promise; /** * Assert the select box selected options to match the expected values. */ assertSelectedOptions(selector: string, expectedValues: string[]): Promise; } interface BrowserContext { /** * Open a new page and visit a URL */ visit(url: string, options?: VisitOptions): Promise; /** * Open a new page using a page model */ visit(page: PageModel): Promise>; /** * Open a new page using a page model and access it's * instance inside the callback. */ visit(page: PageModel, callback: (page: InstanceType) => void | Promise): Promise; } } /** * Extending types */ declare module '@japa/runner/core' { interface TestContext { /** * Playwright browser */ browser: PlayWrightBrowser; /** * Playwright browser context */ browserContext: BrowserContext; /** * Opens a new page and visit the URL */ visit: BrowserContext['visit']; record(url: string, options?: VisitOptions): Promise; record(callback: () => Promise): Promise; } }