UNPKG

22.3 kBTypeScriptView Raw
1import type { EventEmitter } from 'node:events';
2import type { remote, SessionFlags, AttachOptions as WebDriverAttachOptions, BidiHandler, EventMap } from 'webdriver';
3import type { Capabilities, Options, ThenArg } from '@wdio/types';
4import type { ElementReference, ProtocolCommands } from '@wdio/protocols';
5import type { Browser as PuppeteerBrowser } from 'puppeteer-core';
6import type { Dialog as DialogImport } from './dialog.js';
7import type * as BrowserCommands from './commands/browser.js';
8import type * as ElementCommands from './commands/element.js';
9import type { Button, ButtonNames } from './utils/actions/pointer.js';
10import type WebDriverInterception from './utils/interception/index.js';
11/**
12 * export mock primitives
13 */
14export * from './utils/interception/types.js';
15/**
16 * re-export action primitives
17 */
18export * from './utils/actions/index.js';
19/**
20 * re-export command types
21 */
22export { InitScript } from './commands/browser/addInitScript.js';
23type $BrowserCommands = typeof BrowserCommands;
24type $ElementCommands = typeof ElementCommands;
25type ElementQueryCommands = '$' | 'custom$' | 'shadow$' | 'react$';
26type ElementsQueryCommands = '$$' | 'custom$$' | 'shadow$$' | 'react$$';
27type ChainablePrototype = {
28 [K in ElementQueryCommands]: (...args: Parameters<$ElementCommands[K]>) => ChainablePromiseElement;
29} & {
30 [K in ElementsQueryCommands]: (...args: Parameters<$ElementCommands[K]>) => ChainablePromiseArray;
31};
32type AsyncElementProto = {
33 [K in keyof Omit<$ElementCommands, keyof ChainablePrototype>]: OmitThisParameter<$ElementCommands[K]>;
34} & ChainablePrototype;
35interface ChainablePromiseBaseElement {
36 /**
37 * WebDriver element reference
38 */
39 elementId: Promise<string>;
40 /**
41 * parent of the element if fetched via `$(parent).$(child)`
42 */
43 parent: Promise<WebdriverIO.Element | WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser>;
44 /**
45 * selector used to fetch this element, can be
46 * - undefined if element was created via `$({ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' })`
47 * - a string if `findElement` was used and a reference was found
48 * - or a function if element was found via e.g. `$(() => document.body)`
49 */
50 selector: Promise<Selector>;
51 /**
52 * Error message in case element fetch was not successful
53 */
54 error?: Promise<Error>;
55 /**
56 * index of the element if fetched with `$$`
57 */
58 index?: Promise<number>;
59 /**
60 * get the `WebdriverIO.Element` reference
61 */
62 getElement(): Promise<WebdriverIO.Element>;
63}
64export interface ChainablePromiseElement extends ChainablePromiseBaseElement, AsyncElementProto, Omit<WebdriverIO.Element, keyof ChainablePromiseBaseElement | keyof AsyncElementProto> {
65}
66interface AsyncIterators<T> {
67 /**
68 * Unwrap the nth element of the element list.
69 */
70 forEach: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => void, thisArg?: T) => Promise<void>;
71 forEachSeries: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => void, thisArg?: T) => Promise<void>;
72 map: <U>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => U | Promise<U>, thisArg?: T) => Promise<U[]>;
73 mapSeries: <T, U>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => U | Promise<U>, thisArg?: T) => Promise<U[]>;
74 find: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise<boolean>, thisArg?: T) => Promise<T>;
75 findSeries: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise<boolean>, thisArg?: T) => Promise<T>;
76 findIndex: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise<boolean>, thisArg?: T) => Promise<number>;
77 findIndexSeries: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise<boolean>, thisArg?: T) => Promise<number>;
78 some: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise<boolean>, thisArg?: T) => Promise<boolean>;
79 someSeries: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise<boolean>, thisArg?: T) => Promise<boolean>;
80 every: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise<boolean>, thisArg?: T) => Promise<boolean>;
81 everySeries: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise<boolean>, thisArg?: T) => Promise<boolean>;
82 filter: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise<boolean>, thisArg?: T) => Promise<WebdriverIO.Element[]>;
83 filterSeries: <T>(callback: (currentValue: WebdriverIO.Element, index: number, array: T[]) => boolean | Promise<boolean>, thisArg?: T) => Promise<WebdriverIO.Element[]>;
84 reduce: <T, U>(callback: (accumulator: U, currentValue: WebdriverIO.Element, currentIndex: number, array: T[]) => U | Promise<U>, initialValue?: U) => Promise<U>;
85}
86export interface ChainablePromiseArray extends AsyncIterators<WebdriverIO.Element> {
87 [Symbol.asyncIterator](): AsyncIterableIterator<WebdriverIO.Element>;
88 /**
89 * Amount of element fetched.
90 */
91 length: Promise<number>;
92 /**
93 * selector used to fetch this element, can be
94 * - undefined if element was created via `$({ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' })`
95 * - a string if `findElement` was used and a reference was found
96 * - or a function if element was found via e.g. `$(() => document.body)`
97 */
98 selector: Promise<Selector>;
99 /**
100 * parent of the element if fetched via `$(parent).$(child)`
101 */
102 parent: Promise<WebdriverIO.Element | WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser>;
103 /**
104 * allow to access a specific index of the element set
105 */
106 [n: number]: ChainablePromiseElement;
107 /**
108 * get the `WebdriverIO.Element[]` list
109 */
110 getElements(): Promise<WebdriverIO.ElementArray>;
111}
112export type BrowserCommandsType = Omit<$BrowserCommands, keyof ChainablePrototype> & ChainablePrototype;
113export type ElementCommandsType = Omit<$ElementCommands, keyof ChainablePrototype> & ChainablePrototype;
114/**
115 * Multiremote command definition
116 */
117type SingleElementCommandNames = '$' | 'custom$' | 'react$';
118type MultiElementCommandNames = '$$' | 'custom$$' | 'react$$';
119type ElementCommandNames = SingleElementCommandNames | MultiElementCommandNames;
120type MultiRemoteElementCommands = {
121 [K in keyof Pick<BrowserCommandsType, SingleElementCommandNames>]: (...args: Parameters<BrowserCommandsType[K]>) => ThenArg<WebdriverIO.MultiRemoteElement>;
122} & {
123 [K in keyof Pick<BrowserCommandsType, MultiElementCommandNames>]: (...args: Parameters<BrowserCommandsType[K]>) => ThenArg<WebdriverIO.MultiRemoteElement[]>;
124};
125export type MultiRemoteBrowserCommandsType = {
126 [K in keyof Omit<BrowserCommandsType, ElementCommandNames | 'SESSION_MOCKS' | 'CDP_SESSIONS'>]: (...args: Parameters<BrowserCommandsType[K]>) => Promise<ThenArg<ReturnType<BrowserCommandsType[K]>>[]>;
127} & MultiRemoteElementCommands;
128export type MultiRemoteElementCommandsType = {
129 [K in keyof Omit<ElementCommandsType, ElementCommandNames>]: (...args: Parameters<ElementCommandsType[K]>) => Promise<ThenArg<ReturnType<ElementCommandsType[K]>>[]>;
130} & MultiRemoteElementCommands;
131export type MultiRemoteProtocolCommandsType = {
132 [K in keyof ProtocolCommands]: (...args: Parameters<ProtocolCommands[K]>) => Promise<ThenArg<ReturnType<ProtocolCommands[K]>>[]>;
133};
134interface ElementArrayExport extends Omit<Array<WebdriverIO.Element>, keyof AsyncIterators<WebdriverIO.Element>>, AsyncIterators<WebdriverIO.Element> {
135 /**
136 * selector used to fetch this element, can be
137 * - undefined if element was created via `$({ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' })`
138 * - a string if `findElement` was used and a reference was found
139 * - or a function if element was found via e.g. `$(() => document.body)`
140 */
141 selector: Selector;
142 /**
143 * parent of the element if fetched via `$(parent).$(child)`
144 */
145 parent: WebdriverIO.Element | WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser;
146 /**
147 * command name with which this element was found, e.g. `$$`, `react$$`, `custom$$`, `shadow$$`
148 */
149 foundWith: string;
150 /**
151 * properties of the fetched elements
152 */
153 props: any[];
154 /**
155 * Amount of element fetched.
156 */
157 length: number;
158 /**
159 * get the `WebdriverIO.Element[]` list
160 */
161 getElements(): Promise<WebdriverIO.ElementArray>;
162}
163export type ElementArray = ElementArrayExport;
164type AddCommandFnScoped<InstanceType = WebdriverIO.Browser, IsElement extends boolean = false> = (this: IsElement extends true ? Element : InstanceType, ...args: any[]) => any;
165export type AddCommandFn = (...args: any[]) => any;
166type OverwriteCommandFnScoped<ElementKey extends keyof $ElementCommands, BrowserKey extends keyof $BrowserCommands, IsElement extends boolean = false> = (this: IsElement extends true ? WebdriverIO.Element : WebdriverIO.Browser, origCommand: (...args: any[]) => IsElement extends true ? $ElementCommands[ElementKey] : $BrowserCommands[BrowserKey], ...args: any[]) => Promise<any>;
167type OverwriteCommandFn<ElementKey extends keyof $ElementCommands, BrowserKey extends keyof $BrowserCommands, IsElement extends boolean = false> = (origCommand: (...args: any[]) => IsElement extends true ? $ElementCommands[ElementKey] : $BrowserCommands[BrowserKey], ...args: any[]) => Promise<any>;
168export type CustomLocatorReturnValue = HTMLElement | HTMLElement[] | NodeListOf<HTMLElement>;
169export interface CustomInstanceCommands<T> {
170 /**
171 * add command to `browser` or `element` scope
172 */
173 addCommand<IsElement extends boolean = false>(name: string, func: AddCommandFn | AddCommandFnScoped<T, IsElement>, attachToElement?: IsElement, proto?: Record<string, any>, instances?: Record<string, WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser>): void;
174 /**
175 * overwrite `browser` or `element` command
176 */
177 overwriteCommand<ElementKey extends keyof $ElementCommands, BrowserKey extends keyof $BrowserCommands, IsElement extends boolean = false>(name: IsElement extends true ? ElementKey : BrowserKey, func: OverwriteCommandFn<ElementKey, BrowserKey, IsElement> | OverwriteCommandFnScoped<ElementKey, BrowserKey, IsElement>, attachToElement?: IsElement, proto?: Record<string, any>, instances?: Record<string, WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser>): void;
178 /**
179 * create custom selector
180 */
181 addLocatorStrategy(name: string, func: ((selector: string, root: HTMLElement) => CustomLocatorReturnValue) | ((selector: string) => CustomLocatorReturnValue)): void;
182}
183interface InstanceBase extends EventEmitter, SessionFlags {
184 /**
185 * Session id for the current running session
186 */
187 sessionId: string;
188 /**
189 * Applied WebdriverIO options (options that aren't officially part of WebdriverIO are stripped
190 * out of this object).
191 */
192 options: Options.WebdriverIO | Options.Testrunner;
193 /**
194 * Puppeteer instance
195 */
196 puppeteer?: PuppeteerBrowser;
197 strategies: Map<any, any>;
198 commandList: string[];
199 /**
200 * @private
201 */
202 __propertiesObject__: Record<string, PropertyDescriptor>;
203 /**
204 * @private
205 */
206 wdioRetries?: number;
207}
208/**
209 * a browser base that has everything besides commands which are defined for sync and async separately
210 */
211export interface BrowserBase extends InstanceBase, CustomInstanceCommands<WebdriverIO.Browser> {
212 isMultiremote: false;
213 /**
214 * capabilities of the browser instance
215 */
216 capabilities: WebdriverIO.Capabilities;
217}
218type WebdriverIOEventMap = EventMap & {
219 'dialog': WebdriverIO.Dialog;
220};
221interface BidiEventHandler {
222 on<K extends keyof WebdriverIOEventMap>(event: K, listener: (this: WebdriverIO.Browser, param: WebdriverIOEventMap[K]) => void): this;
223 once<K extends keyof WebdriverIOEventMap>(event: K, listener: (this: WebdriverIO.Browser, param: WebdriverIOEventMap[K]) => void): this;
224}
225/**
226 * @private
227 */
228export interface Browser extends Omit<BrowserBase, 'on' | 'once'>, BidiEventHandler, BidiHandler, ProtocolCommands, BrowserCommandsType {
229}
230/**
231 * export a browser interface that can be used for typing plugins
232 */
233export interface ElementBase extends InstanceBase, ElementReference, CustomInstanceCommands<WebdriverIO.Element> {
234 /**
235 * capabilities of the browser instance
236 */
237 capabilities: WebdriverIO.Capabilities;
238 /**
239 * WebDriver element reference
240 */
241 elementId: string;
242 /**
243 * WebDriver element reference
244 */
245 ELEMENT: string;
246 /**
247 * selector used to fetch this element, can be
248 * - undefined if element was created via `$({ 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' })`
249 * - a string if `findElement` was used and a reference was found
250 * - or a functin if element was found via e.g. `$(() => document.body)`
251 */
252 selector: Selector;
253 /**
254 * index of the element if fetched with `$$`
255 */
256 index?: number;
257 /**
258 * parent of the element if fetched via `$(parent).$(child)`
259 */
260 parent: WebdriverIO.Element | WebdriverIO.Browser;
261 /**
262 * true if element is a React component
263 */
264 isReactElement?: boolean;
265 /**
266 * true if element was queried from a shadow root
267 */
268 isShadowElement?: boolean;
269 /**
270 * error response if element was not found
271 */
272 error?: Error;
273 /**
274 * locator of the element
275 * @requires WebDriver Bidi
276 */
277 locator?: remote.BrowsingContextLocator;
278}
279/**
280 * @deprecated use `WebdriverIO.Element` instead
281 */
282export interface Element extends ElementBase, ProtocolCommands, ElementCommandsType {
283}
284interface MultiRemoteBase extends Omit<InstanceBase, 'sessionId'>, CustomInstanceCommands<WebdriverIO.MultiRemoteBrowser> {
285 /**
286 * capabilities of the browser instance
287 */
288 capabilities: Capabilities.RequestedMultiremoteCapabilities;
289 /**
290 * multiremote browser instance names
291 */
292 instances: string[];
293 /**
294 * flag to indicate multiremote browser session
295 */
296 isMultiremote: true;
297 /**
298 * get a specific instance to run commands on it
299 */
300 getInstance: (browserName: string) => WebdriverIO.Browser;
301}
302interface MultiRemoteElementBase {
303 selector: string;
304 /**
305 * multiremote browser instance names
306 */
307 instances: string[];
308 commandList: string[];
309 addCommand: Function;
310 overwriteCommand: Function;
311 /**
312 * flag to indicate multiremote browser session
313 */
314 isMultiremote: true;
315 /**
316 * get a specific instance to run commands on it
317 */
318 getInstance: (browserName: string) => WebdriverIO.Element;
319 __propertiesObject__: never;
320}
321interface MultiRemoteBrowserType extends MultiRemoteBase, MultiRemoteBrowserCommandsType, MultiRemoteProtocolCommandsType {
322}
323/**
324 * @deprecated use `WebdriverIO.MultiRemoteBrowser` instead
325 */
326export interface MultiRemoteBrowser extends MultiRemoteBrowserType {
327}
328interface MultiRemoteElementType extends MultiRemoteElementBase, MultiRemoteProtocolCommandsType, Omit<MultiRemoteBrowserCommandsType, keyof MultiRemoteElementCommandsType>, MultiRemoteElementCommandsType {
329}
330/**
331 * @deprecated use `WebdriverIO.MultiRemoteElement` instead
332 */
333export interface MultiRemoteElement extends MultiRemoteElementType {
334}
335export type ElementFunction = ((elem: HTMLElement) => HTMLElement | undefined) | ((elem: HTMLElement) => (HTMLElement | undefined)[]);
336export type CustomStrategyFunction = (...args: any) => ElementReference | ElementReference[];
337export type CustomStrategyReference = {
338 strategy: CustomStrategyFunction;
339 strategyName: string;
340 strategyArguments: any[];
341};
342export type Selector = string | ElementReference | ElementFunction | CustomStrategyReference | HTMLElement;
343interface CSSValue {
344 type: string;
345 string: string;
346 unit: string;
347 value: any;
348}
349interface ParsedColor extends Partial<CSSValue> {
350 rgb?: string;
351 rgba?: string;
352 hex?: string;
353}
354export interface ParsedCSSValue {
355 property?: string;
356 value?: string;
357 parsed: ParsedColor;
358}
359interface NoneActionEntity {
360 type: 'pause';
361 duration: number;
362}
363interface PointerActionEntity {
364 type: 'pointerMove' | 'pointerDown' | 'pointerUp' | 'pointerCancel' | 'pause';
365 duration?: number;
366 x?: number;
367 y?: number;
368 button?: number;
369}
370interface KeyActionEntity {
371 type: 'keyUp' | 'keyDown';
372 duration?: number;
373 value?: string;
374}
375export interface Action {
376 id: string;
377 actions: (NoneActionEntity | PointerActionEntity | KeyActionEntity)[];
378 type?: 'pointer' | 'key';
379 parameters?: {
380 pointerType: 'mouse' | 'pen' | 'touch';
381 };
382}
383export interface ActionParameter {
384 actions: Action[];
385}
386export type ActionTypes = 'press' | 'longPress' | 'tap' | 'moveTo' | 'wait' | 'release';
387export interface TouchAction {
388 action: ActionTypes;
389 x?: number;
390 y?: number;
391 element?: WebdriverIO.Element;
392 ms?: number;
393}
394export type TouchActionParameter = string | string[] | TouchAction | TouchAction[];
395export type TouchActions = TouchActionParameter | TouchActionParameter[];
396export type Matcher = {
397 name: string;
398 args: Array<string | object>;
399 class?: string;
400};
401export type ReactSelectorOptions = {
402 props?: object;
403 state?: any[] | number | string | object | boolean;
404};
405export type MoveToOptions = {
406 xOffset?: number;
407 yOffset?: number;
408};
409export type DragAndDropOptions = {
410 duration?: number;
411};
412export type NewWindowOptions = {
413 windowName?: string;
414 windowFeatures?: string;
415};
416export type ClickOptions = {
417 button: Button | ButtonNames;
418 x: number;
419 y: number;
420 skipRelease: boolean;
421};
422export type WaitForOptions = {
423 timeout?: number;
424 interval?: number;
425 timeoutMsg?: string;
426 reverse?: boolean;
427 withinViewport?: boolean;
428};
429export type WaitUntilOptions = {
430 timeout?: number;
431 timeoutMsg?: string;
432 interval?: number;
433};
434export type DragAndDropCoordinate = {
435 x: number;
436 y: number;
437};
438export interface AttachOptions extends Omit<WebDriverAttachOptions, 'capabilities'> {
439 options?: Options.WebdriverIO;
440 capabilities?: WebDriverAttachOptions['capabilities'];
441 requestedCapabilities?: WebDriverAttachOptions['capabilities'];
442}
443export type ThrottlePreset = 'offline' | 'GPRS' | 'Regular2G' | 'Good2G' | 'Regular3G' | 'Good3G' | 'Regular4G' | 'DSL' | 'WiFi' | 'online';
444export interface CustomThrottle {
445 offline: boolean;
446 downloadThroughput: number;
447 uploadThroughput: number;
448 latency: number;
449}
450export type ThrottleOptions = ThrottlePreset | CustomThrottle;
451export interface ExtendedElementReference {
452 'element-6066-11e4-a52e-4f735466cecf': string;
453 locator: remote.BrowsingContextLocator;
454}
455export type SupportedScopes = 'geolocation' | 'userAgent' | 'colorScheme' | 'onLine' | 'clock' | 'device';
456export type RestoreMap = Map<SupportedScopes, (() => Promise<any>)[]>;
457declare global {
458 namespace WebdriverIO {
459 /**
460 * WebdriverIO browser object
461 * @see https://webdriver.io/docs/api/browser
462 */
463 interface Browser extends Omit<BrowserBase, 'on' | 'once'>, BidiEventHandler, BidiHandler, ProtocolCommands, BrowserCommandsType {
464 }
465 /**
466 * WebdriverIO element object
467 * @see https://webdriver.io/docs/api/element
468 */
469 interface Element extends ElementBase, ProtocolCommands, ElementCommandsType {
470 }
471 /**
472 * WebdriverIO element array
473 * When fetching elements via `$$`, `custom$$` or `shadow$$` commands an array of elements
474 * is returns. This array has extended prototype properties to provide information about
475 * the parent element, selector and properties of the fetched elements. This is useful to
476 * e.g. re-fetch the set in case no elements got returned.
477 */
478 interface ElementArray extends ElementArrayExport {
479 }
480 /**
481 * WebdriverIO multiremote browser object
482 * A multiremote browser instance is a property on the global WebdriverIO browser object that
483 * allows to control multiple browser instances at once. It can be represented as `Record<string, WebdriverIO.Browser>`
484 * where `string` is the capability name defined in the WebdriverIO options.
485 *
486 * @see https://webdriver.io/docs/multiremote/
487 */
488 interface MultiRemoteBrowser extends MultiRemoteBrowserType {
489 }
490 /**
491 * WebdriverIO multiremote browser object
492 * A multiremote browser instance is a property on the global WebdriverIO browser object that
493 * allows to control multiple browser instances at once. It can be represented as `Record<string, WebdriverIO.Element>`
494 * where `string` is the capability name defined in the WebdriverIO options.
495 *
496 * @see https://webdriver.io/docs/multiremote/
497 */
498 interface MultiRemoteElement extends MultiRemoteElementType {
499 }
500 /**
501 * WebdriverIO Mock object
502 * The mock object is an object that represents a network mock and contains information about
503 * requests that were matching given url and filterOptions. It can be received using the mock command.
504 *
505 * @see https://webdriver.io/docs/api/mock
506 */
507 interface Mock extends WebDriverInterception {
508 }
509 /**
510 * WebdriverIO Dialog object
511 * The dialog object represents a user prompt that was triggered by the browser. It contains
512 * information about the message, type and default value of the prompt.
513 * It can be received using the `on('dialog')` event.
514 *
515 * @see https://webdriver.io/docs/api/dialog
516 */
517 interface Dialog extends DialogImport {
518 }
519 }
520}
521//# sourceMappingURL=types.d.ts.map
\No newline at end of file