Types
The types a project names when its own code holds what POMWright hands out or forwards its options. Every type is
imported from pomwright with import type. Guide: TypeScript.
PageObjectTypeOptions
Section titled “PageObjectTypeOptions”The second type argument of PageObject, types only: whether baseUrl and
urlPath are RegExps, and the session storage schema. See
pages whose URL varies and
the URL types.
import type { Page } from "@playwright/test";import { json, PageObject } from "pomwright";
const orderStorage = { cart: json<{ items: string[] }>() };
export class OrderPage extends PageObject<"main", { urlPathType: RegExp; storage: typeof orderStorage }> { constructor(page: Page) { super(page, "https://shop.example", /^\/orders\/\d+$/, { sessionStorage: { schema: orderStorage } }); }
protected defineLocators(): void { this.add("main").locator("main"); }}baseUrlType
Section titled “baseUrlType”string | RegExp (optional)
RegExp when baseUrl is a RegExp, tested against the URL’s origin. Defaults to string.
storage
Section titled “storage”SessionStorageSchema (optional)
The type of the session storage schema, typeof schema, so sessionStorage.set, get and seed are typed per key.
The schema itself goes in the constructor’s sessionStorage option.
urlPathType
Section titled “urlPathType”string | RegExp (optional)
RegExp when urlPath is a RegExp, tested against the rest of the URL: path, query and hash. Defaults to string.
BaseUrlTypeFromOptions
Section titled “BaseUrlTypeFromOptions”BaseUrlTypeFromOptions<Options>: the type of baseUrl, RegExp when baseUrlType is RegExp, otherwise string.
UrlPathTypeFromOptions
Section titled “UrlPathTypeFromOptions”UrlPathTypeFromOptions<Options>: the type of urlPath, RegExp when urlPathType is RegExp, otherwise string.
FullUrlTypeFromOptions
Section titled “FullUrlTypeFromOptions”FullUrlTypeFromOptions<Options>: the type of fullUrl, UrlMatcher
when either part is a RegExp, otherwise string. A type of your own that looks at fullUrl tests it against
UrlMatcher, not RegExp:
import type { FullUrlTypeFromOptions, UrlMatcher } from "pomwright";
type AccountUrl = FullUrlTypeFromOptions<{ urlPathType: RegExp }>;const isMatcher: AccountUrl extends UrlMatcher ? true : false = true;StorageTypeFromOptions
Section titled “StorageTypeFromOptions”StorageTypeFromOptions<Options>: the session storage schema type, storage, or a schema without declared keys.
PageObjectOptions
Section titled “PageObjectOptions”PageObjectOptions<Options>: the options of the PageObject constructor, for a base class of your own that forwards
them. Options is the page object’s PageObjectTypeOptions, which types the session storage schema.
import type { Page } from "@playwright/test";import { PageObject, type PageObjectOptions } from "pomwright";
export abstract class ShopPage<Paths extends string> extends PageObject<Paths> { protected constructor(page: Page, urlPath: string, options?: PageObjectOptions) { super(page, "https://shop.example", urlPath, { ...options, locators: { strictChains: true } }); }}string (optional)
The name in the page object’s step titles and error messages. Defaults to the class name.
locators
Section titled “locators”LocatorRegistryOptions (optional)
The registry’s options: strictChains: true makes the check after defineLocators() require every ancestor of every
registered path to be registered as well. Set it once in a base class of your own.
navOptions
Section titled “navOptions”NavigationOptions (optional)
Defaults for every navigation method (waitUntil, timeout); a call’s own options win.
sessionStorage
Section titled “sessionStorage”{ schema?: SessionStorageSchema } (optional)
The codecs of the session storage keys that hold structured values, typed by Options["storage"].
FilterDefinition
Section titled “FilterDefinition”FilterDefinition<Paths>: the argument of filter, Playwright’s
locator.filter() options, where has and hasNot
also take a registered path. See filters.
import type { FilterDefinition } from "pomwright";
type Paths = "list" | "list.items" | "list.items.badge";
export const withBadge: FilterDefinition<Paths> = { has: "list.items.badge" };Locator | Paths (optional)
Keeps the elements that contain this one. A registered path resolves to that path’s own locator, without its
ancestors; see filters. A path that is not registered, and a
cycle of such paths, fail verify().
hasNot
Section titled “hasNot”Locator | Paths (optional)
Keeps the elements that do not contain this one; a registered path as for has.
hasNotText
Section titled “hasNotText”string | RegExp (optional)
Keeps the elements that do not contain this text, as Playwright’s option.
hasText
Section titled “hasText”string | RegExp (optional)
Keeps the elements that contain this text, as Playwright’s option.
visible
Section titled “visible”boolean (optional)
Keeps only visible, or only hidden, elements, as Playwright’s option.
IndexSelector
Section titled “IndexSelector”number | "first" | "last": the argument of nth. "first" and "last" become Playwright’s first() and last(),
and a number goes to nth() as given, -1 being the last element.
LocatorSchemaPathFormat
Section titled “LocatorSchemaPathFormat”LocatorSchemaPathFormat<Path>: the path rules as a type. It is Path itself when the path is well formed (not
empty, no leading, trailing or consecutive ., no whitespace), and otherwise a tuple naming the rule it breaks, which
TypeScript shows in the error:
Argument of type 'string' is not assignable to parameter of type 'LocatorSchemaPathError<"main..list", "String can't contain consecutive '.'">'.A wide string is not checked by the type; the same rules are checked at run time for every path. See
the rules of a path.
LocatorSchemaPathArgument
Section titled “LocatorSchemaPathArgument”LocatorSchemaPathArgument<Path>: the type of the path parameter of add and the resolving methods, the path itself
when it is well formed. A helper in a base class that is generic in its paths takes its path with it; see
paths in a generic base class.
import { type LocatorSchemaPathArgument, PageObject } from "pomwright";
export abstract class ShopPage<Paths extends string> extends PageObject<Paths> { protected async clickOn<Path extends Paths>(path: LocatorSchemaPathArgument<Path>): Promise<void> { await this.getNestedLocator(path).click(); }}