import { Page, Locator, Fixtures, expect } from '@playwright/test'; type AnyConstructor = new (...args: any[]) => object; type PageFirstConstructor = ConstructorParameters extends [Page, ...unknown[]] ? TClass : never; /** * Class decorator: sets root locator by test id regex. Use for list containers * whose items share a common test id pattern (e.g. `item-1`, `item-2`). * Package root classes should extend `RootPageObject`. * Plain external classes must receive Playwright `Page` as the first argument. * * The `id` string is used as a regex pattern. Pass a `RegExp` directly for full * control. Escape special characters in strings if the prefix contains regex * metacharacters. * * @param id - Regex pattern string or `RegExp` for `data-testid` * * @example * ```ts * @ListRootSelector("todo-item-") * class TodoListRoot extends RootPageObject {} * ``` */ declare function ListRootSelector(id: string | RegExp): (target: PageFirstConstructor, context: ClassDecoratorContext) => TClass; /** * Class decorator: sets root locator by test id or `body` when omitted. * Package root classes should extend `RootPageObject`. * Plain external classes must receive Playwright `Page` as the first argument. * * @param id - Optional `data-testid` value. If omitted, root is `body`. * * @example * ```ts * @RootSelector("app-header") * class HeaderPageObject extends RootPageObject {} * ``` */ declare function RootSelector(id?: string): (target: PageFirstConstructor, context: ClassDecoratorContext) => TClass; /** * Class decorator: sets root locator by text content. * Package root classes should extend `RootPageObject`. * Plain external classes must receive Playwright `Page` as the first argument. * @param text - Text to match (string or regex) */ declare function RootSelectorByText(text: string): (target: PageFirstConstructor, context: ClassDecoratorContext) => TClass; /** * Class decorator: sets root locator by ARIA role. * Package root classes should extend `RootPageObject`. * Plain external classes must receive Playwright `Page` as the first argument. * @param args - Same as {@link Locator.getByRole} (role, options) */ declare function RootSelectorByRole(...args: Parameters): (target: PageFirstConstructor, context: ClassDecoratorContext) => TClass; /** * Class decorator: sets root locator by associated label. * Package root classes should extend `RootPageObject`. * Plain external classes must receive Playwright `Page` as the first argument. * @param args - Same as {@link Locator.getByLabel} */ declare function RootSelectorByLabel(...args: Parameters): (target: PageFirstConstructor, context: ClassDecoratorContext) => TClass; /** * Class decorator: sets root locator by placeholder text. * Package root classes should extend `RootPageObject`. * Plain external classes must receive Playwright `Page` as the first argument. * @param args - Same as {@link Locator.getByPlaceholder} */ declare function RootSelectorByPlaceholder(...args: Parameters): (target: PageFirstConstructor, context: ClassDecoratorContext) => TClass; /** * Class decorator: sets root locator by alt text (e.g. images). * Package root classes should extend `RootPageObject`. * Plain external classes must receive Playwright `Page` as the first argument. * @param args - Same as {@link Locator.getByAltText} */ declare function RootSelectorByAltText(...args: Parameters): (target: PageFirstConstructor, context: ClassDecoratorContext) => TClass; /** * Class decorator: sets root locator by title attribute. * Package root classes should extend `RootPageObject`. * Plain external classes must receive Playwright `Page` as the first argument. * @param args - Same as {@link Locator.getByTitle} */ declare function RootSelectorByTitle(...args: Parameters): (target: PageFirstConstructor, context: ClassDecoratorContext) => TClass; /** * Accessor decorator for custom selector logic. Transforms the accessor value * using a function that receives the root locator and the accessor's return value. * * Use when built-in selectors (`Selector`, `SelectorByText`, etc.) are insufficient. * * @param selector - Function `(root, value) => value` that returns a locator or PageObject * * @example RootPageObject + @RootSelector * ```ts * @RootSelector("sidebar") * class Sidebar extends RootPageObject { * @SelectorBy((root, id) => root.getByTestId(id)) * accessor link = "nav-link" as string; * } * ``` * * @example Plain host with `page` (no @RootSelector) * ```ts * class Checkout { * constructor(readonly page: Page) {} * @Selector("promo") * accessor promo!: Locator; * } * ``` * * @example Fragment with `locator` (from `@Selector(..., Factory)`) * ```ts * class Section { * constructor(readonly locator: Locator) {} * @Selector("field") * accessor field!: Locator; * } * ``` */ declare function SelectorBy(selector: (root: Locator, value: TSelectorValue) => TSelectorValue): (target: ClassAccessorDecoratorTarget, context: ClassAccessorDecoratorContext) => ClassAccessorDecoratorResult; type LocatorFactoryArg = ((locator: Locator) => T) | (new (locator: Locator, ...args: never[]) => T); /** * Accessor decorator: locator by test id regex. Use for list items sharing a pattern. * * The `itemMask` string is used as a regex pattern (e.g. `"CartItem_"` matches * `CartItem_1`, `CartItem_2`, etc.). Pass a `RegExp` directly for full control. * Escape special characters in strings if the prefix contains regex metacharacters. * * @param itemMask - Regex pattern string or `RegExp` for `data-testid` * * @example * ```ts * @ListSelector("todo-item-") * accessor items = new ListPageObject(TodoItem); * ``` */ declare function ListSelector(itemMask: string | RegExp): ReturnType; declare function ListSelector(itemMask: string | RegExp, locatorFactory: LocatorFactoryArg): ReturnType; /** * Accessor decorator: locator by test id or self when omitted. * @param id - Optional `data-testid` value. If omitted, returns root locator. */ declare function Selector(id?: string): ReturnType; declare function Selector(id: string, locatorFactory: LocatorFactoryArg): ReturnType; /** * Accessor decorator: locator by ARIA role. * @param args - Same as {@link Locator.getByRole} (role, options) */ declare function SelectorByRole(...args: Parameters): ReturnType; declare function SelectorByRole(...args: [...Parameters, LocatorFactoryArg]): ReturnType; /** * Accessor decorator: locator by text content. * @param text - Text to match (string or regex) */ declare function SelectorByText(text: string): ReturnType; declare function SelectorByText(text: string, locatorFactory: LocatorFactoryArg): ReturnType; /** * Accessor decorator: locator by associated label. * @param args - Same as {@link Locator.getByLabel} */ declare function SelectorByLabel(...args: Parameters): ReturnType; declare function SelectorByLabel(...args: [...Parameters, LocatorFactoryArg]): ReturnType; /** * Accessor decorator: locator by placeholder text. * @param args - Same as {@link Locator.getByPlaceholder} */ declare function SelectorByPlaceholder(...args: Parameters): ReturnType; declare function SelectorByPlaceholder(...args: [...Parameters, LocatorFactoryArg]): ReturnType; /** * Accessor decorator: locator by alt text (e.g. images). * @param args - Same as {@link Locator.getByAltText} */ declare function SelectorByAltText(...args: Parameters): ReturnType; declare function SelectorByAltText(...args: [...Parameters, LocatorFactoryArg]): ReturnType; /** * Accessor decorator: locator by title attribute. * @param args - Same as {@link Locator.getByTitle} */ declare function SelectorByTitle(...args: Parameters): ReturnType; declare function SelectorByTitle(...args: [...Parameters, LocatorFactoryArg]): ReturnType; type EmptyFixtures = Record; type PageObjectConstructor$1 = new (page: Page) => T; type PageObjectFactory = (page: Page) => T; type PageObjectEntry = PageObjectConstructor$1 | PageObjectFactory; /** * Map of fixture names to PageObject constructors or factory functions. * Each entry receives `page` and returns a page object instance. * * - **Class constructor**: `CheckoutPage` — called as `new CheckoutPage(page)` * - **Factory function**: `(page) => new AuthPage(page, config)` — called directly */ type PageObjectConstructorsMap = Record>; /** Maps constructor/factory map to instance types for Fixtures. */ type FixturesFromMap = { [K in keyof T]: T[K] extends PageObjectEntry ? U : never; }; /** * Creates Playwright fixtures from a map of PageObject classes or factory functions. * Each fixture instantiates its PageObject with `page` and passes it to the test. * * Returns Playwright's `Fixtures` type. Pass the generic to `extend` for typed fixtures: * `base.extend<{ checkoutPage: CheckoutPage }>(createFixtures({ checkoutPage: CheckoutPage }))` * * @param pageObjects - Record of fixture name → PageObject constructor or factory * @returns Fixtures object for use with `test.extend()` * * @example Class constructor (most common) * ```ts * const test = base.extend<{ homePage: HomePage }>( * createFixtures({ homePage: HomePage }) * ); * ``` * * @example Factory function (when extra constructor args are needed) * ```ts * const test = base.extend<{ authPage: AuthPage }>( * createFixtures({ authPage: (page) => new AuthPage(page, authConfig) }) * ); * ``` * * @example Mixed * ```ts * const test = base.extend<{ homePage: HomePage; authPage: AuthPage }>( * createFixtures({ * homePage: HomePage, * authPage: (page) => new AuthPage(page, authConfig), * }) * ); * ``` */ declare function createFixtures(pageObjects: T): Fixtures, EmptyFixtures, EmptyFixtures, EmptyFixtures>; /** * Internal symbol key used by decorators to store a resolved `Locator` * on decorated root/page object instances. * * Registered via `Symbol.for` so two loaded copies of the library (e.g. the * CJS and ESM builds in one process) agree on the same key. */ declare const LOCATOR_SYMBOL: unique symbol; /** * Prototype brand carried by `PageObject` (and subclasses). Lets the static * type guards recognize instances/classes coming from another loaded copy of * the library, where `instanceof` would fail. */ declare const PAGE_OBJECT_BRAND: unique symbol; /** Prototype brand carried by `RootPageObject` (and subclasses). */ declare const ROOT_PAGE_OBJECT_BRAND: unique symbol; /** * Function type that derives a {@link Locator} from a root locator. * Used by decorators to resolve element selectors within a page object. */ type SelectorType = (p: Locator) => Locator; /** * Constructor signature for PageObject subclasses. * Used by `cloneWithContext()` for nested child composition. * Custom constructors that do not match this shape must override `cloneWithContext()`. */ type PageObjectConstructor = new (root?: Locator, selector?: SelectorType) => TPageObject; /** * Base class for the Page Object Model pattern with Playwright. * * Extend this class for nested child controls created by selector decorators. * Top-level root-decorated page objects should extend `RootPageObject`. * Provides wait helpers, assertions via `expect()`, and raw locator access via `$`. * * @example * ```ts * class HeaderSection extends PageObject { * @SelectorByText("Sign in") * accessor signInButton = new PageObject(); * } * ``` */ declare class PageObject { root?: Locator; /** * @param root - Root locator (set by decorators) * @param selector - Selector function (set by decorators) */ constructor(root?: Locator, selector?: SelectorType); private _selector?; protected get selector(): SelectorType | undefined; protected set selector(selector: SelectorType | undefined); get [LOCATOR_SYMBOL](): Locator; /** Cross-copy brand: lives on the prototype, inherited by all subclasses. */ get [PAGE_OBJECT_BRAND](): true; get page(): Page; /** * Resolved locator for this page object. * Throws if `RootSelector` or `Selector` decorators were not applied. */ protected get locator(): Locator; /** * Raw Playwright locator. Use for actions: `control.$.click()`, `control.$.fill()`, etc. * Keeps the library version-agnostic—any Playwright API is available via `$`. */ get $(): Locator; /** * Type guard: checks if a value is a PageObject class (constructor). * * @param value - Value to check * @returns `true` if value is a PageObject subclass constructor */ static isClass(value?: unknown): value is new (...args: TArgs) => PageObject; /** * Type guard: checks if a value is a PageObject instance. * * @param value - Value to check * @returns `true` if value is a PageObject instance */ static isInstance(value?: unknown): value is PageObject; /** * Creates a new instance with a different root and selector (used for nesting). * **Required override** when extending PageObject with a custom constructor. * * @param root - New root locator * @param selector - New selector function * @returns New instance of this class with the given context */ cloneWithContext(root: Locator, selector: SelectorType): this; /** Waits for the element to become visible. */ waitVisible(): Promise; /** Waits for the element to become hidden. */ waitHidden(): Promise; /** * Waits for the element to have the given text. * @param text - Expected text (string or regex) */ waitText(text: string | RegExp): Promise; /** * Waits for the element to have the given value. * @param value - Expected value (string, regex, or number) */ waitValue(value: string | RegExp | number): Promise; /** * Waits for the locator to resolve to the given count. * @param count - Expected number of matching elements */ waitCount(count: number): Promise; /** Waits for a checkbox/radio to be checked. */ waitChecked(): Promise; /** Waits for a checkbox/radio to be unchecked. */ waitUnChecked(): Promise; /** ASSERTIONS */ /** * Returns a Playwright expect assertion for this locator. * * @param options - Optional `message` and `soft` (for soft assertions) * @returns Playwright expect API for this locator */ expect(options?: { message?: string; soft?: boolean; }): ReturnType>; } /** * Page object for a list of items, each represented by a `TItem` page object. * * Use as a nested list control together with `Selector` or `ListSelector`. * Supports filtering, indexing, and async iteration. * * @typeParam TItem - PageObject type for each list item (default: `PageObject`) * * @example * ```ts * class TodoPage extends RootPageObject { * @Selector("TodoList") * accessor items = new ListPageObject(TodoItem); * } * ``` */ declare class ListPageObject extends PageObject { protected itemType?: TItem | (new (root?: Locator, selector?: SelectorType) => TItem); /** * @param itemType - PageObject class or instance for each list item. * - **Class**: Use when items use the default constructor `(root?, selector?)`. * - **Instance**: Use when items need a custom constructor — pass a pre-configured * instance and it will be cloned via `cloneWithContext()` for each item. * @param root - Root locator (set by decorators) * @param selector - Selector function (set by decorators) * @throws If `itemType` is provided but is neither a `PageObject` subclass nor a * `PageObject` instance. Pass a class (`new ListPageObject(MyItem)`) or an * instance (`new ListPageObject(new MyItem())`). */ constructor(itemType?: TItem | (new (root?: Locator, selector?: SelectorType) => TItem), root?: Locator, selector?: SelectorType); cloneWithContext(root: Locator, selector: SelectorType): this; /** * Returns the item at the given index (0-based). Supports negative indices like * `Array.at()` — use `-1` for last, `-2` for second-to-last, etc. * @param index - Item index * @returns PageObject for the item at that index */ getItemByIndex(index: number): TItem; /** * Returns the item at the given index. Alias for `getItemByIndex` with negative * index support matching `Array.at()` semantics. * @param index - Item index (0-based; -1 = last, -2 = second-to-last, etc.) * @returns PageObject for the item at that index */ at(index: number): TItem; /** * Returns a narrowed list matching the given Playwright filter options. * @param options - Playwright locator filter (e.g. `{ hasText: 'foo' }`) * @returns Narrowed list page object containing the filtered item(s) */ filter(options: Parameters[0]): this; /** * Returns a narrowed list of items containing the given text. * @param text - Text to match (string or regex) * @returns Narrowed list page object containing the matching item(s) */ filterByText(text: string | RegExp): this; /** * Returns a narrowed list of items whose **own** `data-testid` matches the given * value. Use this when the item row itself carries the test id. * * For rows that *contain* a descendant with the test id, use `filterByHasTestId`. * * @param id - Test id (string or regex) * @returns Narrowed list page object containing the matching item(s) */ filterByItemTestId(id: string | RegExp): this; /** * Returns a narrowed list of items that contain a **descendant** with the given * test id (Playwright `has` filter). Use this when matching by a child element's * test id, not the row's own test id. * * For rows whose own test id matches, use `filterByItemTestId`. * * @param id - Test id (string or regex) * @returns Narrowed list page object containing the matching item(s) */ filterByHasTestId(id: string | RegExp): this; /** * Returns the item whose own `data-testid` matches the given value. * @param id - Test id (string or regex) * @returns PageObject for the matching item */ getItemByTestId(id: string | RegExp): TItem; /** Returns the first item (index 0). */ first(): TItem; /** Returns the second item (index 1). */ second(): TItem; /** Returns the last item (index -1). */ last(): TItem; /** * Returns the item containing the given text. * @param text - Text to match (string or regex) * @returns PageObject for the matching item */ getItemByText(text: string | RegExp): TItem; /** * Returns the first item containing an element matching the given ARIA role and options. * @param args - Same as {@link Locator.getByRole} * @returns PageObject for the matching item */ getItemByRole(...args: Parameters): TItem; /** * Proxy for indexed access and async iteration. * * - **Numeric index**: `list.items[0]` returns the item at index 0 * - **at(index)**: `list.items.at(-1)` returns the last item (supports negative indices) * - **Async iteration**: `for await (const item of list.items)` yields each item * * Use `for await...of` or `await list.getAll()` — not synchronous `for...of`. */ get items(): Record & AsyncIterable & { at(index: number): TItem; }; /** * Returns the number of items in the list. * @returns Count of matching elements */ count(): Promise; /** * Returns all items as an array of page objects. Each item is a lazy locator * wrapper — the count is resolved eagerly but individual element actions are * deferred until called. * @returns Array of `TItem` instances */ getAll(): Promise; protected resolveList(selector: SelectorType): this; protected resolveItem(selector: SelectorType): TItem; } /** * Constructor signature for top-level root page objects. * The first constructor argument is always Playwright `Page`. */ type RootPageObjectConstructor = new (page: Page, ...rest: TRest) => TRootPageObject; /** * Base class for top-level page objects that use `@RootSelector...`. * * Use `RootPageObject` for root-decorated classes created directly from Playwright `Page`. * Use `PageObject` for nested child controls created by selector decorators. */ declare class RootPageObject extends PageObject { constructor(page: Page); /** Cross-copy brand: lives on the prototype, inherited by all subclasses. */ get [ROOT_PAGE_OBJECT_BRAND](): true; static isRootClass(value?: unknown): value is new (...args: TArgs) => RootPageObject; cloneWithContext(root: Locator, selector: SelectorType): this; } export { ListPageObject, ListRootSelector, ListSelector, PageObject, RootPageObject, RootSelector, RootSelectorByAltText, RootSelectorByLabel, RootSelectorByPlaceholder, RootSelectorByRole, RootSelectorByText, RootSelectorByTitle, Selector, SelectorBy, SelectorByAltText, SelectorByLabel, SelectorByPlaceholder, SelectorByRole, SelectorByText, SelectorByTitle, createFixtures }; export type { FixturesFromMap, PageObjectConstructor, PageObjectConstructorsMap, RootPageObjectConstructor, SelectorType };