import type { EventEmitter } from 'node:events'; import type { remote, SessionFlags, AttachOptions as WebDriverAttachOptions, BidiHandler, EventMap } from 'webdriver'; import type { Capabilities, Options, ThenArg } from '@wdio/types'; import type { ElementReference, ProtocolCommands } from '@wdio/protocols'; import type { Browser as PuppeteerBrowser } from 'puppeteer-core'; import type { Dialog as DialogImport } from './dialog.js'; import type * as BrowserCommands from './commands/browser.js'; import type * as ElementCommands from './commands/element.js'; import type { Button, ButtonNames } from './utils/actions/pointer.js'; import type WebDriverInterception from './utils/interception/index.js'; /** * export mock primitives */ export * from './utils/interception/types.js'; /** * re-export action primitives */ export * from './utils/actions/index.js'; /** * re-export command types */ export { InitScript } from './commands/browser/addInitScript.js'; type $BrowserCommands = typeof BrowserCommands; type $ElementCommands = typeof ElementCommands; type ElementQueryCommands = '$' | 'custom$' | 'shadow$' | 'react$'; type ElementsQueryCommands = '$$' | 'custom$$' | 'shadow$$' | 'react$$'; type ChainablePrototype = { [K in ElementQueryCommands]: (...args: Parameters<$ElementCommands[K]>) => ChainablePromiseElement; } & { [K in ElementsQueryCommands]: (...args: Parameters<$ElementCommands[K]>) => ChainablePromiseArray; }; type AsyncElementProto = { [K in keyof Omit<$ElementCommands, keyof ChainablePrototype>]: OmitThisParameter<$ElementCommands[K]>; } & ChainablePrototype; interface ChainablePromiseBaseElement { /** * WebDriver element reference */ elementId: Promise; /** * parent of the element if fetched via `$(parent).$(child)` */ parent: Promise; /** * selector used to fetch this element, can be * - undefined if element was created via `$({ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' })` * - a string if `findElement` was used and a reference was found * - or a function if element was found via e.g. `$(() => document.body)` */ selector: Promise; /** * Error message in case element fetch was not successful */ error?: Promise; /** * index of the element if fetched with `$$` */ index?: Promise; /** * get the `WebdriverIO.Element` reference */ getElement(): Promise; } export interface ChainablePromiseElement extends ChainablePromiseBaseElement, AsyncElementProto, Omit { } interface AsyncIterators { /** * Unwrap the nth element of the element list. */ forEach: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => void, thisArg?: T) => Promise; forEachSeries: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => void, thisArg?: T) => Promise; map: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => U | Promise, thisArg?: T) => Promise; mapSeries: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => U | Promise, thisArg?: T) => Promise; find: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise, thisArg?: T) => Promise; findSeries: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise, thisArg?: T) => Promise; findIndex: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise, thisArg?: T) => Promise; findIndexSeries: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise, thisArg?: T) => Promise; some: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise, thisArg?: T) => Promise; someSeries: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise, thisArg?: T) => Promise; every: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise, thisArg?: T) => Promise; everySeries: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise, thisArg?: T) => Promise; filter: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise, thisArg?: T) => Promise; filterSeries: (callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise, thisArg?: T) => Promise; reduce: (callback: (accumulator: U, currentValue: WebdriverIO.Element, currentIndex: number, array: T[]) => U | Promise, initialValue?: U) => Promise; } export interface ChainablePromiseArray extends AsyncIterators { [Symbol.asyncIterator](): AsyncIterableIterator; /** * Amount of element fetched. */ length: Promise; /** * selector used to fetch this element, can be * - undefined if element was created via `$({ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' })` * - a string if `findElement` was used and a reference was found * - or a function if element was found via e.g. `$(() => document.body)` */ selector: Promise; /** * parent of the element if fetched via `$(parent).$(child)` */ parent: Promise; /** * allow to access a specific index of the element set */ [n: number]: ChainablePromiseElement; /** * get the `WebdriverIO.Element[]` list */ getElements(): Promise; } export type BrowserCommandsType = Omit<$BrowserCommands, keyof ChainablePrototype> & ChainablePrototype; export type ElementCommandsType = Omit<$ElementCommands, keyof ChainablePrototype> & ChainablePrototype; /** * Multiremote command definition */ type SingleElementCommandNames = '$' | 'custom$' | 'react$'; type MultiElementCommandNames = '$$' | 'custom$$' | 'react$$'; type ElementCommandNames = SingleElementCommandNames | MultiElementCommandNames; type MultiRemoteElementCommands = { [K in keyof Pick]: (...args: Parameters) => ThenArg; } & { [K in keyof Pick]: (...args: Parameters) => ThenArg; }; export type MultiRemoteBrowserCommandsType = { [K in keyof Omit]: (...args: Parameters) => Promise>[]>; } & MultiRemoteElementCommands; export type MultiRemoteElementCommandsType = { [K in keyof Omit]: (...args: Parameters) => Promise>[]>; } & MultiRemoteElementCommands; export type MultiRemoteProtocolCommandsType = { [K in keyof ProtocolCommands]: (...args: Parameters) => Promise>[]>; }; interface ElementArrayExport extends Omit, keyof AsyncIterators>, AsyncIterators { /** * selector used to fetch this element, can be * - undefined if element was created via `$({ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' })` * - a string if `findElement` was used and a reference was found * - or a function if element was found via e.g. `$(() => document.body)` */ selector: Selector; /** * parent of the element if fetched via `$(parent).$(child)` */ parent: WebdriverIO.Element | WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser; /** * command name with which this element was found, e.g. `$$`, `react$$`, `custom$$`, `shadow$$` */ foundWith: string; /** * properties of the fetched elements */ props: any[]; /** * Amount of element fetched. */ length: number; /** * get the `WebdriverIO.Element[]` list */ getElements(): Promise; } export type ElementArray = ElementArrayExport; type AddCommandFnScoped = (this: IsElement extends true ? Element : InstanceType, ...args: any[]) => any; export type AddCommandFn = (...args: any[]) => any; type OverwriteCommandFnScoped = (this: IsElement extends true ? WebdriverIO.Element : WebdriverIO.Browser, origCommand: (...args: any[]) => IsElement extends true ? $ElementCommands[ElementKey] : $BrowserCommands[BrowserKey], ...args: any[]) => Promise; type OverwriteCommandFn = (origCommand: (...args: any[]) => IsElement extends true ? $ElementCommands[ElementKey] : $BrowserCommands[BrowserKey], ...args: any[]) => Promise; export type CustomLocatorReturnValue = HTMLElement | HTMLElement[] | NodeListOf; export interface CustomInstanceCommands { /** * add command to `browser` or `element` scope */ addCommand(name: string, func: AddCommandFn | AddCommandFnScoped, attachToElement?: IsElement, proto?: Record, instances?: Record): void; /** * overwrite `browser` or `element` command */ overwriteCommand(name: IsElement extends true ? ElementKey : BrowserKey, func: OverwriteCommandFn | OverwriteCommandFnScoped, attachToElement?: IsElement, proto?: Record, instances?: Record): void; /** * create custom selector */ addLocatorStrategy(name: string, func: ((selector: string, root: HTMLElement) => CustomLocatorReturnValue) | ((selector: string) => CustomLocatorReturnValue)): void; } interface InstanceBase extends EventEmitter, SessionFlags { /** * Session id for the current running session */ sessionId: string; /** * Applied WebdriverIO options (options that aren't officially part of WebdriverIO are stripped * out of this object). */ options: Options.WebdriverIO | Options.Testrunner; /** * Puppeteer instance */ puppeteer?: PuppeteerBrowser; strategies: Map; commandList: string[]; /** * @private */ __propertiesObject__: Record; /** * @private */ wdioRetries?: number; } /** * a browser base that has everything besides commands which are defined for sync and async separately */ export interface BrowserBase extends InstanceBase, CustomInstanceCommands { isMultiremote: false; /** * capabilities of the browser instance */ capabilities: WebdriverIO.Capabilities; } type WebdriverIOEventMap = EventMap & { 'dialog': WebdriverIO.Dialog; }; interface BidiEventHandler { on(event: K, listener: (this: WebdriverIO.Browser, param: WebdriverIOEventMap[K]) => void): this; once(event: K, listener: (this: WebdriverIO.Browser, param: WebdriverIOEventMap[K]) => void): this; } /** * @private */ export interface Browser extends Omit, BidiEventHandler, BidiHandler, ProtocolCommands, BrowserCommandsType { } /** * export a browser interface that can be used for typing plugins */ export interface ElementBase extends InstanceBase, ElementReference, CustomInstanceCommands { /** * capabilities of the browser instance */ capabilities: WebdriverIO.Capabilities; /** * WebDriver element reference */ elementId: string; /** * WebDriver element reference */ ELEMENT: string; /** * selector used to fetch this element, can be * - undefined if element was created via `$({ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' })` * - a string if `findElement` was used and a reference was found * - or a functin if element was found via e.g. `$(() => document.body)` */ selector: Selector; /** * index of the element if fetched with `$$` */ index?: number; /** * parent of the element if fetched via `$(parent).$(child)` */ parent: WebdriverIO.Element | WebdriverIO.Browser; /** * true if element is a React component */ isReactElement?: boolean; /** * true if element was queried from a shadow root */ isShadowElement?: boolean; /** * error response if element was not found */ error?: Error; /** * locator of the element * @requires WebDriver Bidi */ locator?: remote.BrowsingContextLocator; } /** * @deprecated use `WebdriverIO.Element` instead */ export interface Element extends ElementBase, ProtocolCommands, ElementCommandsType { } interface MultiRemoteBase extends Omit, CustomInstanceCommands { /** * capabilities of the browser instance */ capabilities: Capabilities.RequestedMultiremoteCapabilities; /** * multiremote browser instance names */ instances: string[]; /** * flag to indicate multiremote browser session */ isMultiremote: true; /** * get a specific instance to run commands on it */ getInstance: (browserName: string) => WebdriverIO.Browser; } interface MultiRemoteElementBase { selector: string; /** * multiremote browser instance names */ instances: string[]; commandList: string[]; addCommand: Function; overwriteCommand: Function; /** * flag to indicate multiremote browser session */ isMultiremote: true; /** * get a specific instance to run commands on it */ getInstance: (browserName: string) => WebdriverIO.Element; __propertiesObject__: never; } interface MultiRemoteBrowserType extends MultiRemoteBase, MultiRemoteBrowserCommandsType, MultiRemoteProtocolCommandsType { } /** * @deprecated use `WebdriverIO.MultiRemoteBrowser` instead */ export interface MultiRemoteBrowser extends MultiRemoteBrowserType { } interface MultiRemoteElementType extends MultiRemoteElementBase, MultiRemoteProtocolCommandsType, Omit, MultiRemoteElementCommandsType { } /** * @deprecated use `WebdriverIO.MultiRemoteElement` instead */ export interface MultiRemoteElement extends MultiRemoteElementType { } export type ElementFunction = ((elem: HTMLElement) => HTMLElement | undefined) | ((elem: HTMLElement) => (HTMLElement | undefined)[]); export type CustomStrategyFunction = (...args: any) => ElementReference | ElementReference[]; export type CustomStrategyReference = { strategy: CustomStrategyFunction; strategyName: string; strategyArguments: any[]; }; export type Selector = string | ElementReference | ElementFunction | CustomStrategyReference | HTMLElement; interface CSSValue { type: string; string: string; unit: string; value: any; } interface ParsedColor extends Partial { rgb?: string; rgba?: string; hex?: string; } export interface ParsedCSSValue { property?: string; value?: string; parsed: ParsedColor; } interface NoneActionEntity { type: 'pause'; duration: number; } interface PointerActionEntity { type: 'pointerMove' | 'pointerDown' | 'pointerUp' | 'pointerCancel' | 'pause'; duration?: number; x?: number; y?: number; button?: number; } interface KeyActionEntity { type: 'keyUp' | 'keyDown'; duration?: number; value?: string; } export interface Action { id: string; actions: (NoneActionEntity | PointerActionEntity | KeyActionEntity)[]; type?: 'pointer' | 'key'; parameters?: { pointerType: 'mouse' | 'pen' | 'touch'; }; } export interface ActionParameter { actions: Action[]; } export type ActionTypes = 'press' | 'longPress' | 'tap' | 'moveTo' | 'wait' | 'release'; export interface TouchAction { action: ActionTypes; x?: number; y?: number; element?: WebdriverIO.Element; ms?: number; } export type TouchActionParameter = string | string[] | TouchAction | TouchAction[]; export type TouchActions = TouchActionParameter | TouchActionParameter[]; export type Matcher = { name: string; args: Array; class?: string; }; export type ReactSelectorOptions = { props?: object; state?: any[] | number | string | object | boolean; }; export type MoveToOptions = { xOffset?: number; yOffset?: number; }; export type DragAndDropOptions = { duration?: number; }; export type NewWindowOptions = { windowName?: string; windowFeatures?: string; }; export type ClickOptions = { button: Button | ButtonNames; x: number; y: number; skipRelease: boolean; }; export type WaitForOptions = { timeout?: number; interval?: number; timeoutMsg?: string; reverse?: boolean; withinViewport?: boolean; }; export type WaitUntilOptions = { timeout?: number; timeoutMsg?: string; interval?: number; }; export type DragAndDropCoordinate = { x: number; y: number; }; export interface AttachOptions extends Omit { options?: Options.WebdriverIO; capabilities?: WebDriverAttachOptions['capabilities']; requestedCapabilities?: WebDriverAttachOptions['capabilities']; } export type ThrottlePreset = 'offline' | 'GPRS' | 'Regular2G' | 'Good2G' | 'Regular3G' | 'Good3G' | 'Regular4G' | 'DSL' | 'WiFi' | 'online'; export interface CustomThrottle { offline: boolean; downloadThroughput: number; uploadThroughput: number; latency: number; } export type ThrottleOptions = ThrottlePreset | CustomThrottle; export interface ExtendedElementReference { 'element-6066-11e4-a52e-4f735466cecf': string; locator: remote.BrowsingContextLocator; } export type SupportedScopes = 'geolocation' | 'userAgent' | 'colorScheme' | 'onLine' | 'clock' | 'device'; export type RestoreMap = Map Promise)[]>; declare global { namespace WebdriverIO { /** * WebdriverIO browser object * @see https://webdriver.io/docs/api/browser */ interface Browser extends Omit, BidiEventHandler, BidiHandler, ProtocolCommands, BrowserCommandsType { } /** * WebdriverIO element object * @see https://webdriver.io/docs/api/element */ interface Element extends ElementBase, ProtocolCommands, ElementCommandsType { } /** * WebdriverIO element array * When fetching elements via `$$`, `custom$$` or `shadow$$` commands an array of elements * is returns. This array has extended prototype properties to provide information about * the parent element, selector and properties of the fetched elements. This is useful to * e.g. re-fetch the set in case no elements got returned. */ interface ElementArray extends ElementArrayExport { } /** * WebdriverIO multiremote browser object * A multiremote browser instance is a property on the global WebdriverIO browser object that * allows to control multiple browser instances at once. It can be represented as `Record` * where `string` is the capability name defined in the WebdriverIO options. * * @see https://webdriver.io/docs/multiremote/ */ interface MultiRemoteBrowser extends MultiRemoteBrowserType { } /** * WebdriverIO multiremote browser object * A multiremote browser instance is a property on the global WebdriverIO browser object that * allows to control multiple browser instances at once. It can be represented as `Record` * where `string` is the capability name defined in the WebdriverIO options. * * @see https://webdriver.io/docs/multiremote/ */ interface MultiRemoteElement extends MultiRemoteElementType { } /** * WebdriverIO Mock object * The mock object is an object that represents a network mock and contains information about * requests that were matching given url and filterOptions. It can be received using the mock command. * * @see https://webdriver.io/docs/api/mock */ interface Mock extends WebDriverInterception { } /** * WebdriverIO Dialog object * The dialog object represents a user prompt that was triggered by the browser. It contains * information about the message, type and default value of the prompt. * It can be received using the `on('dialog')` event. * * @see https://webdriver.io/docs/api/dialog */ interface Dialog extends DialogImport { } } } //# sourceMappingURL=types.d.ts.map