UNPKG

playwright-elements

Version:
205 lines (204 loc) 11.6 kB
import { Locator, LocatorScreenshotOptions, Page } from 'playwright-core'; import { Expect } from '@playwright/test'; type NestedElements<T extends WebElement, A> = { [K in keyof A]: A[K] extends WebElement ? A[K] & NestedElements<A[K], InferNestedElements<A[K]>> : A[K] extends (this: any, ...args: infer Args) => infer Result ? (this: T & Omit<NestedElements<T, A>, K>, ...args: Args) => Result : A[K]; }; type InferNestedElements<T> = T extends { with(config: infer Config): any; } ? Config extends object ? Config : {} : {}; type InternalMethods<T extends WebElement, M> = { [K in keyof M]: M[K] extends (this: any, ...args: infer Args) => infer Result ? (this: T & Omit<InternalMethods<T, M>, K>, ...args: Args) => Result : M[K]; }; type AriaSnapshotOptions = Parameters<Locator['ariaSnapshot']>[0]; type BlurOptions = Parameters<Locator['blur']>[0]; type BoundingBoxOptions = Parameters<Locator['boundingBox']>[0]; type BoundingBoxReturnType = ReturnType<Locator['boundingBox']>; type CheckOptions = Parameters<Locator['check']>[0]; type ClearOptions = Parameters<Locator['clear']>[0]; type ClickOptions = Parameters<Locator['click']>[0]; type DblClickOptions = Parameters<Locator['dblclick']>[0]; type DispatchEventInit = Parameters<Locator['dispatchEvent']>[1]; type DispatchEventOptions = Parameters<Locator['dispatchEvent']>[2]; type DragToOptions = Parameters<Locator['dragTo']>[1]; type FillOptions = Parameters<Locator['fill']>[1]; type FocusOptions = Parameters<Locator['focus']>[0]; type GetAttributeOptions = Parameters<Locator['getAttribute']>[1]; type HoverOptions = Parameters<Locator['hover']>[0]; type InnerHTMLOptions = Parameters<Locator['innerHTML']>[0]; type InnerTextOptions = Parameters<Locator['innerText']>[0]; type InputValueOptions = Parameters<Locator['inputValue']>[0]; type IsCheckedOptions = Parameters<Locator['isChecked']>[0]; type IsDisabledOptions = Parameters<Locator['isDisabled']>[0]; type IsEditableOptions = Parameters<Locator['isEditable']>[0]; type IsEnabledOptions = Parameters<Locator['isEnabled']>[0]; type IsVisibleOptions = Parameters<Locator['isVisible']>[0]; type PressOptions = Parameters<Locator['press']>[1]; type ScrollIntoViewIfNeededOptions = Parameters<Locator['scrollIntoViewIfNeeded']>[0]; type SelectOptionValuesType = Parameters<Locator['selectOption']>[0]; type SelectOptionOptions = Parameters<Locator['selectOption']>[1]; type SelectTextOptions = Parameters<Locator['selectText']>[0]; type SetCheckedOptions = Parameters<Locator['setChecked']>[1]; type SetInputFilesType = Parameters<Locator['setInputFiles']>[0]; type SetInputFilesOptions = Parameters<Locator['setInputFiles']>[1]; type TapOptions = Parameters<Locator['tap']>[0]; type TextContentOptions = Parameters<Locator['textContent']>[0]; type TypeOptions = Parameters<Locator['type']>[1]; type PressSequentiallyOptions = Parameters<Locator['pressSequentially']>[1]; type UncheckOptions = Parameters<Locator['uncheck']>[0]; type WaitForOptions = Parameters<Locator['waitFor']>[0]; type AddLocatorHandlerOptions = Parameters<Page['addLocatorHandler']>[2]; declare const _expect: Expect<{ [key: string]: (...args: any[]) => Promise<void>; }>; type LocatorExpect = ReturnType<typeof _expect<Locator>>; export declare class WebElement { protected _isFrame: boolean; protected _isInFrame: boolean; protected _frameSelector: string; private _parents; private readonly _selector; private readonly _by; private _byOptions; private _hasLocator; private _hasNotLocator; private _hasText; private _hasNotText; private _nth; private _and; private _or; constructor(selector: string, by?: By, options?: ByOptions | ByRoleOptions); private selectLocatorMethod; private buildLocator; private buildParentLocatorsChain; get locator(): Locator; get _(): Locator; static useExpect<T>(expect: Expect<T>): void; expect(message?: string): LocatorExpect; softExpect(message?: string): LocatorExpect; private recursiveParentSelectorInjection; subElements<T extends WebElement, A>(this: T, augment: NestedElements<T, A>): T & A; withMethods<T extends WebElement, A>(this: T, augment: InternalMethods<T, A>): T & A; with<T extends WebElement, A>(this: T, augment: NestedElements<T, A>): T & A; get narrowSelector(): string; private buildNarrowSelectorWithInternalLocator; get selector(): string; get parentsSelector(): string; parent<T>(this: WebElement): WebElement & T; private get parentElements(); private addParentSelector; clone<T extends WebElement>(this: T, options?: { selector?: string; hasLocator?: string | WebElement; hasNotLocator?: string | WebElement; hasText?: string | RegExp; hasNotText?: string | RegExp; nth?: number; }): T; and<T extends WebElement, R extends WebElement>(this: R, element: string | T): R; or<T extends WebElement, R extends WebElement>(this: R, element: string | T): R; has<T extends WebElement, R extends WebElement>(this: R, element: string | T): R; hasNot<T extends WebElement, R extends WebElement>(this: R, element: string | T): R; hasText<R extends WebElement>(this: R, text: string | RegExp): R; hasNotText<R extends WebElement>(this: R, text: string | RegExp): R; private addParentsToWebElement; contentFrame(): this; owner(): this; addHandler<T extends WebElement>(this: T, handler: (element: T) => Promise<any>, options?: AddLocatorHandlerOptions): Promise<void>; removeHandler(): Promise<void>; $(selector: string): WebElement; $getByAltText(altText: string, options?: ByOptions): WebElement; $getByLabel(label: string, options?: ByOptions): WebElement; $getByPlaceholder(placeholder: string, options?: ByOptions): WebElement; $getByRole(role: Role, options?: ByRoleOptions): WebElement; $getByTestId(testId: string): WebElement; $getByText(text: string, options?: ByOptions): WebElement; $getByTitle(title: string, options?: ByOptions): WebElement; nth(index: number): this; first(): this; last(): this; getAll<T extends WebElement>(this: T): Promise<T[]>; asyncForEach<T extends WebElement>(this: T, action: (element: T) => unknown | Promise<unknown>): Promise<void>; syncForEach<T extends WebElement>(this: T, action: (element: T) => unknown | Promise<unknown>): Promise<void>; map<T extends WebElement, R>(this: T, item: (element: T) => R | Promise<R>): Promise<Awaited<R[]>>; filter<T extends WebElement, R extends WebElement>(this: R, options: { has?: string | T; hasNot?: string | T; hasText?: string | RegExp; hasNotText?: string | RegExp; }): R; filterElements<T extends WebElement>(this: T, predicate: (element: T) => boolean | Promise<boolean>): Promise<T[]>; allInnerTexts(): Promise<Array<string>>; allTextContents(): Promise<Array<string>>; ariaSnapshot(options?: AriaSnapshotOptions): Promise<string>; blur(options?: BlurOptions): Promise<void>; boundingBox(options?: BoundingBoxOptions): BoundingBoxReturnType; check(options?: CheckOptions): Promise<void>; clear(options?: ClearOptions): Promise<void>; click(options?: ClickOptions): Promise<void>; count(): Promise<number>; dblclick(options?: DblClickOptions): Promise<void>; dispatchEvent(type: string, eventInit?: DispatchEventInit, options?: DispatchEventOptions): Promise<void>; dragTo(target: Locator | WebElement, options?: DragToOptions): Promise<void>; fill(value: string, options?: FillOptions): Promise<void>; focus(options?: FocusOptions): Promise<void>; getAttribute(name: string, options?: GetAttributeOptions): Promise<string | null>; highlight(): Promise<void>; hover(options?: HoverOptions): Promise<void>; innerHTML(options?: InnerHTMLOptions): Promise<string>; innerText(options?: InnerTextOptions): Promise<string>; inputValue(options?: InputValueOptions): Promise<string>; isChecked(options?: IsCheckedOptions): Promise<boolean>; isDisabled(options?: IsDisabledOptions): Promise<boolean>; isEditable(options?: IsEditableOptions): Promise<boolean>; isEnabled(options?: IsEnabledOptions): Promise<boolean>; isHidden(): Promise<boolean>; isVisible(options?: IsVisibleOptions): Promise<boolean>; press(key: string, options?: PressOptions): Promise<void>; screenshot(options?: LocatorScreenshotOptions): Promise<Buffer>; scrollIntoViewIfNeeded(options?: ScrollIntoViewIfNeededOptions): Promise<void>; selectOption(values: SelectOptionValuesType, options?: SelectOptionOptions): Promise<Array<string>>; selectText(options?: SelectTextOptions): Promise<void>; setChecked(checked: boolean, options?: SetCheckedOptions): Promise<void>; setInputFiles(files: SetInputFilesType, options?: SetInputFilesOptions): Promise<void>; tap(options?: TapOptions): Promise<void>; textContent(options?: TextContentOptions): Promise<string | null>; type(text: string, options?: TypeOptions): Promise<void>; pressSequentially(text: string, options?: PressSequentiallyOptions): Promise<void>; uncheck(options?: UncheckOptions): Promise<void>; waitFor(options?: WaitForOptions): Promise<void>; getText(options?: TextContentOptions): Promise<string>; } declare enum By { getByAltText = "getByAltText", getByLabel = "getByLabel", getByPlaceholder = "getByPlaceholder", getByRole = "getByRole", getByTestId = "getByTestId", getByText = "getByText", getByTitle = "getByTitle" } type ByOptions = { exact?: boolean; }; type Role = 'alert' | 'alertdialog' | 'application' | 'article' | 'banner' | 'blockquote' | 'button' | 'caption' | 'cell' | 'checkbox' | 'code' | 'columnheader' | 'combobox' | 'complementary' | 'contentinfo' | 'definition' | 'deletion' | 'dialog' | 'directory' | 'document' | 'emphasis' | 'feed' | 'figure' | 'form' | 'generic' | 'grid' | 'gridcell' | 'group' | 'heading' | 'img' | 'insertion' | 'link' | 'list' | 'listbox' | 'listitem' | 'log' | 'main' | 'marquee' | 'math' | 'meter' | 'menu' | 'menubar' | 'menuitem' | 'menuitemcheckbox' | 'menuitemradio' | 'navigation' | 'none' | 'note' | 'option' | 'paragraph' | 'presentation' | 'progressbar' | 'radio' | 'radiogroup' | 'region' | 'row' | 'rowgroup' | 'rowheader' | 'scrollbar' | 'search' | 'searchbox' | 'separator' | 'slider' | 'spinbutton' | 'status' | 'strong' | 'subscript' | 'superscript' | 'switch' | 'tab' | 'table' | 'tablist' | 'tabpanel' | 'term' | 'textbox' | 'time' | 'timer' | 'toolbar' | 'tooltip' | 'tree' | 'treegrid' | 'treeitem'; type ByRoleOptions = { checked?: boolean; disabled?: boolean; exact?: boolean; expanded?: boolean; includeHidden?: boolean; level?: number; name?: string | RegExp; pressed?: boolean; selected?: boolean; }; export declare function $(selector: string): WebElement; export declare function $getByAltText(altText: string, options?: ByOptions): WebElement; export declare function $getByLabel(label: string, options?: ByOptions): WebElement; export declare function $getByPlaceholder(placeholder: string, options?: ByOptions): WebElement; export declare function $getByRole(role: Role, options?: ByRoleOptions): WebElement; export declare function $getByTestId(testId: string): WebElement; export declare function $getByText(text: string, options?: ByOptions): WebElement; export declare function $getByTitle(title: string, options?: ByOptions): WebElement; export declare function initDesktopOrMobile<T>(desktop: T, mobile: T): T; export {};