UNPKG

47.2 kBTypeScriptView Raw
1// -------------------- ATTENTION --------------------
2// Do not edit this file as it gets auto-generated!
3// For edits modify /scripts/templates/*.tpl.d.ts
4// Check CONTRIBUTING.md for more details.
5// --------------------------------------------------
6//
7/// <reference types="node"/>
8/// <reference types="webdriver"/>
9
10// See https://github.com/DefinitelyTyped/DefinitelyTyped/issues/24419
11interface Element { }
12interface Node { }
13interface NodeListOf<TNode = Node> { }
14
15declare namespace WebdriverIO {
16 type LocationParam = 'x' | 'y';
17
18 interface LocationReturn {
19 x: number,
20 y: number
21 }
22
23 type SizeParam = 'width' | 'height';
24
25 interface SizeReturn {
26 width: number,
27 height: number
28 }
29
30 interface CSSProperty {
31 property: string;
32 value: any;
33 parsed?: {
34 // other
35 unit?: string;
36 // font-family
37 value?: any;
38 string: string;
39 // color
40 hex?: string;
41 alpha?: number;
42 type?: string;
43 rgba?: string
44 }
45 }
46
47 type JsonPrimitive = string | number | boolean | null;
48 type JsonObject = { [x: string]: JsonPrimitive | JsonObject | JsonArray };
49 type JsonArray = Array<JsonPrimitive | JsonObject | JsonArray>;
50 type JsonCompatible = JsonObject | JsonArray;
51
52 interface MultiRemoteCapabilities {
53 [instanceName: string]: {
54 capabilities: WebDriver.DesiredCapabilities;
55 };
56 }
57
58 interface ServiceOption {
59 [key: string]: any;
60 }
61 type ServiceEntry = string | HookFunctions | [string, ServiceOption] | object
62
63 interface Options {
64 /**
65 * Define the protocol you want to use for your browser automation.
66 * Currently only [`webdriver`](https://www.npmjs.com/package/webdriver) and
67 * [`devtools`](https://www.npmjs.com/package/devtools) are supported,
68 * as these are the main browser automation technologies available.
69 */
70 automationProtocol?: string;
71 runner?: string;
72 /**
73 * Your cloud service username (only works for Sauce Labs, Browserstack, TestingBot,
74 * CrossBrowserTesting or LambdaTest accounts). If set, WebdriverIO will automatically
75 * set connection options for you.
76 */
77 user?: string;
78 /**
79 * Your cloud service access key or secret key (only works for Sauce Labs, Browserstack,
80 * TestingBot, CrossBrowserTesting or LambdaTest accounts). If set, WebdriverIO will
81 * automatically set connection options for you.
82 */
83 key?: string;
84 /**
85 * If running on Sauce Labs, you can choose to run tests between different datacenters:
86 * US or EU. To change your region to EU, add region: 'eu' to your config.
87 */
88 region?: string;
89 /**
90 * Sauce Labs provides a headless offering that allows you to run Chrome and Firefox tests headless.
91 */
92 headless?: string;
93 /**
94 * Define specs for test execution.
95 */
96 specs?: string[];
97 /**
98 * Exclude specs from test execution.
99 */
100 exclude?: string[];
101 /**
102 * Files to watch when running `wdio` with the `--watch` flag.
103 */
104 filesToWatch?: string[],
105 /**
106 * An object describing various of suites, which you can then specify
107 * with the --suite option on the wdio CLI.
108 */
109 suites?: object;
110 /**
111 * Maximum number of total parallel running workers.
112 */
113 maxInstances?: number;
114 /**
115 * Maximum number of total parallel running workers per capability.
116 */
117 maxInstancesPerCapability?: number;
118 capabilities?: WebDriver.DesiredCapabilities[] | MultiRemoteCapabilities;
119 /**
120 * Directory to store all testrunner log files (including reporter logs and wdio logs).
121 * If not set, all logs are streamed to stdout. Since most reporters are made to log to
122 * stdout, it is recommended to only use this option for specific reporters where it
123 * makes more sense to push report into a file (like the junit reporter, for example).
124 *
125 * When running in standalone mode, the only log generated by WebdriverIO will be the wdio log.
126 */
127 outputDir?: string;
128 /**
129 * Shorten url command calls by setting a base URL.
130 */
131 baseUrl?: string;
132 /**
133 * If you want your test run to stop after a specific number of test failures, use bail.
134 * (It defaults to 0, which runs all tests no matter what.) Note: Please be aware that
135 * when using a third party test runner (such as Mocha), additional configuration might
136 * be required.
137 */
138 bail?: number;
139 /**
140 * The number of retry attempts for an entire specfile when it fails as a whole.
141 */
142 specFileRetries?: number;
143 readonly specFileRetryAttempts?: number;
144 /**
145 * Delay in seconds between the spec file retry attempts
146 */
147 specFileRetriesDelay?: number;
148 /**
149 * Default timeout for all `waitFor*` commands. (Note the lowercase f in the option name.)
150 * This timeout only affects commands starting with `waitFor*` and their default wait time.
151 */
152 waitforTimeout?: number;
153 /**
154 * Default interval for all `waitFor*` commands to check if an expected state (e.g.,
155 * visibility) has been changed.
156 */
157 waitforInterval?: number;
158 /**
159 * Defines the test framework to be used by the WDIO testrunner.
160 */
161 framework?: string;
162 /**
163 * List of reporters to use. A reporter can be either a string, or an array of
164 * `['reporterName', { <reporter options> }]` where the first element is a string
165 * with the reporter name and the second element an object with reporter options.
166 */
167 reporters?: (string | object)[];
168 /**
169 * Determines in which interval the reporter should check if they are synchronised
170 * if they report their logs asynchronously (e.g. if logs are streamed to a 3rd
171 * party vendor).
172 */
173 reporterSyncInterval?: number;
174 /**
175 * Determines the maximum time reporters have to finish uploading all their logs
176 * until an error is being thrown by the testrunner.
177 */
178 reporterSyncTimeout?: number;
179 /**
180 * Services take over a specific job you don't want to take care of. They enhance
181 * your test setup with almost no effort.
182 */
183 services?: ServiceEntry[];
184 /**
185 * Node arguments to specify when launching child processes.
186 */
187 execArgv?: string[];
188 }
189
190 interface RemoteOptions extends WebDriver.Options, Omit<Options, 'capabilities'> { }
191
192 interface MultiRemoteOptions {
193 [instanceName: string]: WebDriver.DesiredCapabilities;
194 }
195
196 interface Suite {}
197 interface Test {}
198
199 interface Results {
200 finished: number,
201 passed: number,
202 failed: number
203 }
204
205 interface HookFunctions {
206 /**
207 * Gets executed once before all workers get launched.
208 * @param config wdio configuration object
209 * @param capabilities list of capabilities details
210 */
211 onPrepare?(
212 config: Config,
213 capabilities: WebDriver.DesiredCapabilities[]
214 ): void;
215
216 /**
217 * Gets executed before a worker process is spawned and can be used to initialise specific service
218 * for that worker as well as modify runtime environments in an async fashion.
219 * @param cid capability id (e.g 0-0)
220 * @param caps object containing capabilities for session that will be spawn in the worker
221 * @param specs specs to be run in the worker process
222 * @param args object that will be merged with the main configuration once worker is initialised
223 * @param execArgv list of string arguments passed to the worker process
224 */
225 onWorkerStart?(
226 cid: string,
227 caps: WebDriver.DesiredCapabilities,
228 specs: string[],
229 args: Config,
230 execArgv: string[]
231 ): void;
232
233 /**
234 * Gets executed after all workers got shut down and the process is about to exit. An error
235 * thrown in the onComplete hook will result in the test run failing.
236 * @param exitCode runner exit code
237 * @param config wdio configuration object
238 * @param capabilities list of capabilities details
239 * @param results test results
240 */
241 onComplete?(
242 exitCode: number,
243 config: Config,
244 capabilities: WebDriver.DesiredCapabilities,
245 results: Results
246 ): void;
247
248 /**
249 * Gets executed when a refresh happens.
250 * @param oldSessionId session id of old session
251 * @param newSessionId session id of new session
252 */
253 onReload?(
254 oldSessionId: string,
255 newSessionId: string
256 ): void;
257
258 /**
259 * Gets executed before test execution begins. At this point you can access to all global
260 * variables like `browser`. It is the perfect place to define custom commands.
261 * @param capabilities list of capabilities details
262 * @param specs specs to be run in the worker process
263 */
264 before?(
265 capabilities: WebDriver.DesiredCapabilities,
266 specs: string[]
267 ): void;
268
269 /**
270 * Runs before a WebdriverIO command gets executed.
271 * @param commandName command name
272 * @param args arguments that command would receive
273 */
274 beforeCommand?(
275 commandName: string,
276 args: any[]
277 ): void;
278
279 /**
280 * Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
281 * beforeEach in Mocha). `stepData` and `world` are Cucumber framework specific properties.
282 * @param test details to current running test (or step in Cucumber)
283 * @param context context to current running test
284 * @param stepData Cucumber step data
285 * @param world Cucumber world
286 */
287 beforeHook?(test: any, context: any, stepData?: any, world?: any): void;
288
289 /**
290 * Gets executed just before initialising the webdriver session and test framework. It allows you
291 * to manipulate configurations depending on the capability or spec.
292 * @param config wdio configuration object
293 * @param capabilities list of capabilities details
294 * @param specs list of spec file paths that are to be run
295 */
296 beforeSession?(
297 config: Config,
298 capabilities: WebDriver.DesiredCapabilities,
299 specs: string[]
300 ): void;
301
302 /**
303 * Hook that gets executed before the suite starts.
304 * @param suite suite details
305 */
306 beforeSuite?(suite: Suite): void;
307
308 /**
309 * Function to be executed before a test (in Mocha/Jasmine) starts.
310 * @param test details to current running test (or step in Cucumber)
311 * @param context context to current running test
312 */
313 beforeTest?(test: Test, context: any): void;
314
315 /**
316 * Hook that gets executed _after_ a hook within the suite ends (e.g. runs after calling
317 * afterEach in Mocha). `stepData` and `world` are Cucumber framework specific.
318 * @param test details to current running test (or step in Cucumber)
319 * @param context context to current running test
320 * @param result test result
321 * @param stepData Cucumber step data
322 * @param world Cucumber world
323 */
324 afterHook?(test: any, context: any, result: {
325 error?: any,
326 result?: any,
327 passed: boolean,
328 duration: number,
329 retries: { limit: number, attempts: number }
330 }, stepData?: any, world?: any): void;
331
332 /**
333 * Gets executed after all tests are done. You still have access to all global variables from
334 * the test.
335 * @param result number of total failing tests
336 * @param capabilities list of capabilities details
337 * @param specs list of spec file paths that are to be run
338 */
339 after?(
340 result: number,
341 capabilities: WebDriver.DesiredCapabilities,
342 specs: string[]
343 ): void;
344
345 /**
346 * Runs after a WebdriverIO command gets executed
347 * @param commandName command name
348 * @param args arguments that command would receive
349 * @param result result of the command
350 * @param error error in case something went wrong
351 */
352 afterCommand?(
353 commandName: string,
354 args: any[],
355 result: any,
356 error?: Error
357 ): void;
358
359 /**
360 * Gets executed right after terminating the webdriver session.
361 * @param config wdio configuration object
362 * @param capabilities list of capabilities details
363 * @param specs list of spec file paths that are to be run
364 */
365 afterSession?(
366 config: Config,
367 capabilities: WebDriver.DesiredCapabilities,
368 specs: string[]
369 ): void;
370
371 /**
372 * Hook that gets executed after the suite has ended
373 * @param suite suite details
374 */
375 afterSuite?(suite: Suite): void;
376
377 /**
378 * Function to be executed after a test (in Mocha/Jasmine) ends.
379 * @param test details to current running test (or step in Cucumber)
380 * @param context context to current running test
381 * @param result test result
382 */
383 afterTest?(test: Test, context: any, result: {
384 error?: any,
385 result?: any,
386 passed: boolean,
387 duration: number,
388 retries: { limit: number, attempts: number }
389 }): void;
390 }
391 type _HooksArray = {
392 [K in keyof Pick<HookFunctions, "onPrepare" | "onWorkerStart" | "onComplete" | "before" | "after" | "beforeSession" | "afterSession">]: HookFunctions[K] | Array<HookFunctions[K]>;
393 };
394 type _Hooks = Omit<HookFunctions, "onPrepare" | "onWorkerStart" | "onComplete" | "before" | "after" | "beforeSession" | "afterSession">;
395 interface Hooks extends _HooksArray, _Hooks { }
396
397 type ActionTypes = 'press' | 'longPress' | 'tap' | 'moveTo' | 'wait' | 'release';
398 interface TouchAction {
399 action: ActionTypes,
400 x?: number,
401 y?: number,
402 element?: Element,
403 ms?: number
404 }
405 type TouchActions = string | TouchAction | TouchAction[];
406
407 type WaitForOptions = {
408 timeout?: number,
409 interval?: number,
410 timeoutMsg?: string,
411 reverse?: boolean,
412 }
413
414 type Matcher = {
415 name: string,
416 args: Array<string | object>
417 class?: string
418 }
419
420 type ReactSelectorOptions = {
421 props?: object,
422 state?: any[] | number | string | object | boolean
423 }
424
425 type MoveToOptions = {
426 xOffset?: number,
427 yOffset?: number
428 }
429
430 type DragAndDropOptions = {
431 duration?: number
432 }
433
434 type NewWindowOptions = {
435 windowName?: string,
436 windowFeatures?: string
437 }
438
439 type ClickOptions = {
440 button?: number | string,
441 x?: number,
442 y?: number
443 }
444
445 type WaitUntilOptions = {
446 timeout?: number,
447 timeoutMsg?: string,
448 interval?: number
449 }
450
451 type DragAndDropCoordinate = {
452 x: number,
453 y: number
454 }
455
456 /**
457 * HTTP request data. (copied from the puppeteer-core package as there is currently
458 * no way to access these types otherwise)
459 */
460 type ResourcePriority = 'VeryLow' | 'Low' | 'Medium' | 'High' | 'VeryHigh';
461 type MixedContentType = 'blockable' | 'optionally-blockable' | 'none';
462 type ReferrerPolicy = 'unsafe-url' | 'no-referrer-when-downgrade' | 'no-referrer' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin';
463 interface Request {
464 /**
465 * Request URL (without fragment).
466 */
467 url: string;
468 /**
469 * Fragment of the requested URL starting with hash, if present.
470 */
471 urlFragment?: string;
472 /**
473 * HTTP request method.
474 */
475 method: string;
476 /**
477 * HTTP request headers.
478 */
479 headers: Record<string, string>;
480 /**
481 * HTTP POST request data.
482 */
483 postData?: string;
484 /**
485 * True when the request has POST data. Note that postData might still be omitted when this flag is true when the data is too long.
486 */
487 hasPostData?: boolean;
488 /**
489 * The mixed content type of the request.
490 */
491 mixedContentType?: MixedContentType;
492 /**
493 * Priority of the resource request at the time request is sent.
494 */
495 initialPriority: ResourcePriority;
496 /**
497 * The referrer policy of the request, as defined in https://www.w3.org/TR/referrer-policy/
498 */
499 referrerPolicy: ReferrerPolicy;
500 /**
501 * Whether is loaded via link preload.
502 */
503 isLinkPreload?: boolean;
504 }
505
506 interface Matches extends Request {
507 /**
508 * body response of actual resource
509 */
510 body: string | JsonCompatible
511 /**
512 * HTTP response headers.
513 */
514 responseHeaders: Record<string, string>;
515 /**
516 * HTTP response status code.
517 */
518 statusCode: number;
519 }
520
521 type PuppeteerBrowser = Partial<import('puppeteer').Browser>;
522 type CDPSession = Partial<import('puppeteer').CDPSession>;
523 type MockOverwriteFunction = (request: Matches, client: CDPSession) => Promise<string | Record<string, any>>;
524 type MockOverwrite = string | Record<string, any> | MockOverwriteFunction;
525
526 type MockResponseParams = {
527 statusCode?: number,
528 headers?: Record<string, string>
529 }
530
531 type MockFilterOptions = {
532 method?: string | ((method: string) => boolean),
533 headers?: Record<string, string> | ((headers: Record<string, string>) => boolean),
534 responseHeaders?: Record<string, string> | ((headers: Record<string, string>) => boolean),
535 statusCode?: number | ((statusCode: number) => boolean),
536 postData?: string | ((payload: string | undefined) => boolean)
537 }
538
539 type ErrorCode = 'Failed' | 'Aborted' | 'TimedOut' | 'AccessDenied' | 'ConnectionClosed' | 'ConnectionReset' | 'ConnectionRefused' | 'ConnectionAborted' | 'ConnectionFailed' | 'NameNotResolved' | 'InternetDisconnected' | 'AddressUnreachable' | 'BlockedByClient' | 'BlockedByResponse'
540
541 type ThrottlePreset = 'offline' | 'GPRS' | 'Regular2G' | 'Good2G' | 'Regular3G' | 'Good3G' | 'Regular4G' | 'DSL' | 'WiFi' | 'online'
542 interface CustomThrottle {
543 offline: boolean,
544 downloadThroughput: number,
545 uploadThroughput: number,
546 latency: number
547 }
548 type ThrottleOptions = ThrottlePreset | CustomThrottle
549
550 type AddCommandFn<IsElement extends boolean = false> = (this: IsElement extends true ? Element : BrowserObject, ...args: any[]) => any
551 type OverwriteCommandFn<ElementKey extends keyof Element, BrowserKey extends keyof BrowserObject, IsElement extends boolean = false> = (this: IsElement extends true ? Element : BrowserObject, origCommand: IsElement extends true ? Element[ElementKey] : BrowserObject[BrowserKey], ...args: any[]) => any
552
553 interface Element {
554 selector: string;
555 elementId: string;
556
557 /**
558 * w3c
559 */
560 "element-6066-11e4-a52e-4f735466cecf"?: string;
561
562 /**
563 * jsonwp
564 */
565 ELEMENT?: string;
566
567 /**
568 * index in array of elements
569 * only applicable if the element found with `$$` command
570 */
571 index?: number;
572
573 /**
574 * WebdriverIO.Element or WebdriverIO.BrowserObject
575 */
576 parent: Element | WebdriverIO.BrowserObject;
577
578 /**
579 * add command to `element` scope
580 */
581 addCommand(
582 name: string,
583 func: AddCommandFn<false>
584 ): void;
585
586 /**
587 * The `$$` command is a short way to call the [`findElements`](/docs/api/webdriver.html#findelements) command in order
588 * to fetch multiple elements on the page similar to the `$$` command from the browser scope. The difference when calling
589 * it from an element scope is that the driver will look within the children of that element.
590 */
591 $$(
592 selector: string | Function | Matcher
593 ): Promise<ElementArray>;
594
595 /**
596 * The `$` command is a short way to call the [`findElement`](/docs/api/webdriver.html#findelement) command in order
597 * to fetch a single element on the page similar to the `$` command from the browser scope. The difference when calling
598 * it from an element scope is that the driver will look within the children of that element. You can also pass in an object as selector
599 * where the object contains a property `element-6066-11e4-a52e-4f735466cecf` with the value of a reference
600 * to an element. The command will then transform the reference to an extended WebdriverIO element.
601 */
602 $(
603 selector: string | Function | Matcher
604 ): Promise<Element>;
605
606 /**
607 * Add a value to an object found by given selector. You can also use unicode
608 * characters like Left arrow or Back space. WebdriverIO will take care of
609 * translating them into unicode characters. You’ll find all supported characters
610 * [here](https://w3c.github.io/webdriver/webdriver-spec.html#keyboard-actions).
611 * To do that, the value has to correspond to a key from the table. It can be disabled
612 * by setting `translateToUnicode` optional parameter to false.
613 */
614 addValue(
615 value: string | number | boolean | object | any[],
616 options?: AddValueOptions
617 ): Promise<void>;
618
619 /**
620 * Clear a `<textarea>` or text `<input>` element’s value. Make sure you can interact with the
621 * element before using this command. You can't clear an input element that is disabled or in
622 * readonly mode.
623 */
624 clearValue(): Promise<void>;
625
626 /**
627 * Click on an element.
628 */
629 click(
630 options?: ClickOptions
631 ): Promise<void>;
632
633 /**
634 * The `customs$$` allows you to use a custom strategy declared by using `browser.addLocatorStrategy`
635 */
636 custom$$(
637 strategyName: string,
638 strategyArguments: any
639 ): Promise<ElementArray>;
640
641 /**
642 * The `custom$` allows you to use a custom strategy declared by using `browser.addLocatorStrategy`
643 */
644 custom$(
645 strategyName: string,
646 strategyArguments: any
647 ): Promise<Element>;
648
649 /**
650 * Double-click on an element.
651 */
652 doubleClick(): Promise<void>;
653
654 /**
655 * Drag an item to a destination element or position.
656 */
657 dragAndDrop(
658 target: Element | DragAndDropCoordinate,
659 options?: DragAndDropOptions
660 ): Promise<void>;
661
662 /**
663 * Get an attribute from a DOM-element based on the attribute name.
664 */
665 getAttribute(
666 attributeName: string
667 ): Promise<string>;
668
669 /**
670 * Get a css property from a DOM-element selected by given selector. The return value
671 * is formatted to be testable. Colors gets parsed via [rgb2hex](https://www.npmjs.org/package/rgb2hex)
672 * and all other properties get parsed via [css-value](https://www.npmjs.org/package/css-value).
673 */
674 getCSSProperty(
675 cssProperty: string
676 ): Promise<CSSProperty>;
677
678 /**
679 * Get source code of specified DOM element by selector.
680 */
681 getHTML(
682 includeSelectorTag?: boolean
683 ): Promise<string>;
684
685 /**
686 * Determine an element’s location on the page.
687 */
688 getLocation(
689 prop: LocationParam
690 ): Promise<number>;
691
692 /**
693 * Determine an element’s location on the page.
694 */
695 getLocation(): Promise<LocationReturn>;
696
697 /**
698 * The Get Element Property command will return the result of getting a property of an element.
699 */
700 getProperty(
701 property: string
702 ): Promise<object | string | boolean | number>;
703
704 /**
705 * Get the width and height for an DOM-element.
706 */
707 getSize(
708 prop: SizeParam
709 ): Promise<number>;
710
711 /**
712 * Get the width and height for an DOM-element.
713 */
714 getSize(): Promise<SizeReturn>;
715
716 /**
717 * Get tag name of a DOM-element.
718 */
719 getTagName(): Promise<string>;
720
721 /**
722 * Get the text content from a DOM-element. Make sure the element
723 * you want to request the text from [is interactable](http://www.w3.org/TR/webdriver/#interactable)
724 * otherwise you will get an empty string as return value. If the element is disabled or not
725 * visible and you still want to receive the text content use [getHTML](https://webdriver.io/docs/api/element/getHTML.html)
726 * as a workaround.
727 */
728 getText(): Promise<string>;
729
730 /**
731 * Get the value of a `<textarea>`, `<select>` or text `<input>` found by given selector.
732 * If multiple elements are found via the given selector, an array of values is returned instead.
733 * For input with checkbox or radio type use isSelected.
734 */
735 getValue(): Promise<string>;
736
737 /**
738 * Return true if the selected DOM-element:
739 * - exists;
740 * - is visible;
741 * - is within viewport (if not try scroll to it);
742 * - its center is not overlapped with another element;
743 * - is not disabled.
744 */
745 isClickable(): Promise<boolean>;
746
747 /**
748 * Return true if the selected DOM-element is displayed.
749 */
750 isDisplayed(): Promise<boolean>;
751
752 /**
753 * Return true if the selected DOM-element found by given selector is partially visible and within the viewport.
754 */
755 isDisplayedInViewport(): Promise<boolean>;
756
757 /**
758 * Return true or false if the selected DOM-element is enabled.
759 */
760 isEnabled(): Promise<boolean>;
761
762 /**
763 * Return true if the selected element matches with the provided one.
764 */
765 isEqual(
766 el: Element
767 ): Promise<boolean>;
768
769 /**
770 * Returns true if element exists in the DOM
771 */
772 isExisting(): Promise<boolean>;
773
774 /**
775 * Return true or false if the selected DOM-element currently has focus. If the selector matches
776 * multiple elements, it will return true if one of the elements has focus.
777 */
778 isFocused(): Promise<boolean>;
779
780 /**
781 * Will return true or false whether or not an `<option>` or `<input>` element of type
782 * checkbox or radio is currently selected.
783 */
784 isSelected(): Promise<boolean>;
785
786 /**
787 * Move the mouse by an offset of the specified element. If no element is specified,
788 * the move is relative to the current mouse cursor. If an element is provided but
789 * no offset, the mouse will be moved to the center of the element. If the element
790 * is not visible, it will be scrolled into view.
791 */
792 moveTo(
793 options?: MoveToOptions
794 ): Promise<void>;
795
796 /**
797 * The `react$$` command is a useful command to query multiple React Components
798 * by their actual name and filter them by props and state.
799 */
800 react$$(
801 selector: string,
802 options?: ReactSelectorOptions
803 ): Promise<ElementArray>;
804
805 /**
806 * The `react$` command is a useful command to query React Components by their
807 * actual name and filter them by props and state.
808 */
809 react$(
810 selector: string,
811 options?: ReactSelectorOptions
812 ): Promise<Element>;
813
814 /**
815 * Save a screenshot of an element to a PNG file on your OS.
816 */
817 saveScreenshot(
818 filename: string
819 ): Promise<Buffer>;
820
821 /**
822 * Scroll element into viewport ([MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)).
823 */
824 scrollIntoView(
825 scrollIntoViewOptions?: object | boolean
826 ): Promise<void>;
827
828 /**
829 * Select option with a specific value.
830 */
831 selectByAttribute(
832 attribute: string,
833 value: string
834 ): Promise<void>;
835
836 /**
837 * Select option with a specific index.
838 */
839 selectByIndex(
840 index: number
841 ): Promise<void>;
842
843 /**
844 * Select option with displayed text matching the argument.
845 */
846 selectByVisibleText(
847 text: string
848 ): Promise<void>;
849
850 /**
851 * Send a sequence of key strokes to an element (clears value before). If the element
852 * doesn't need to be cleared first then use addValue. You can also use
853 * unicode characters like Left arrow or Back space. WebdriverIO will take care of
854 * translating them into unicode characters. You’ll find all supported characters
855 * [here](https://w3c.github.io/webdriver/webdriver-spec.html#keyboard-actions).
856 * To do that, the value has to correspond to a key from the table. It can be disabled
857 * by setting `translateToUnicode` optional parameter to false.
858 */
859 setValue(
860 value: string | number | boolean | object | any[],
861 options?: AddValueOptions
862 ): Promise<void>;
863
864 /**
865 * Access elements inside a given element's shadowRoot
866 */
867 shadow$$(
868 selector: string | Function
869 ): Promise<ElementArray>;
870
871 /**
872 * Access an element inside a given element's shadowRoot
873 */
874 shadow$(
875 selector: string | Function
876 ): Promise<Element>;
877
878 /**
879 * The Touch Action API provides the basis of all gestures that can be automated in Appium.
880 * It is currently only available to native apps and can not be used to interact with webapps.
881 * At its core is the ability to chain together _ad hoc_ individual actions, which will then be
882 * applied to an element in the application on the device. The basic actions that can be used are:
883 */
884 touchAction(
885 action: TouchActions
886 ): Promise<void>;
887
888 /**
889 * Wait for an element for the provided amount of
890 * milliseconds to be clickable or not clickable.
891 */
892 waitForClickable(
893 options?: WaitForOptions
894 ): Promise<boolean>;
895
896 /**
897 * Wait for an element for the provided amount of
898 * milliseconds to be displayed or not displayed.
899 */
900 waitForDisplayed(
901 options?: WaitForOptions
902 ): Promise<boolean>;
903
904 /**
905 * Wait for an element (selected by css selector) for the provided amount of
906 * milliseconds to be (dis/en)abled. If multiple elements get queried by given
907 * selector, it returns true if at least one element is (dis/en)abled.
908 */
909 waitForEnabled(
910 options?: WaitForOptions
911 ): Promise<boolean>;
912
913 /**
914 * Wait for an element for the provided amount of
915 * milliseconds to be present within the DOM. Returns true if the selector
916 * matches at least one element that exists in the DOM, otherwise throws an
917 * error. If the reverse flag is true, the command will instead return true
918 * if the selector does not match any elements.
919 */
920 waitForExist(
921 options?: WaitForOptions
922 ): Promise<boolean>;
923
924 /**
925 * This wait command is your universal weapon if you want to wait on something. It expects a condition
926 * and waits until that condition is fulfilled with a truthy value. If you use the WDIO testrunner the
927 * commands within the condition are getting executed synchronously like in your test.
928 */
929 waitUntil(
930 condition: () => Promise<Boolean>,
931 options?: WaitUntilOptions
932 ): Promise<boolean>;
933 }
934
935 interface Mock {
936 /**
937 * list of requests made by the browser to that mock
938 */
939 calls: Matches[];
940
941
942 /**
943 * > This is a __beta__ feature. Please give us feedback and file [an issue](https://github.com/webdriverio/webdriverio/issues/new/choose) if certain scenarions don't work as expected!
944 */
945 abort(
946 errorCode: ErrorCode
947 ): Promise<void>;
948
949 /**
950 * > This is a __beta__ feature. Please give us feedback and file [an issue](https://github.com/webdriverio/webdriverio/issues/new/choose) if certain scenarions don't work as expected!
951 */
952 abortOnce(
953 errorCode: ErrorCode
954 ): Promise<void>;
955
956 /**
957 * > This is a __beta__ feature. Please give us feedback and file [an issue](https://github.com/webdriverio/webdriverio/issues/new/choose) if certain scenarions don't work as expected!
958 */
959 clear(): Promise<void>;
960
961 /**
962 * > This is a __beta__ feature. Please give us feedback and file [an issue](https://github.com/webdriverio/webdriverio/issues/new/choose) if certain scenarions don't work as expected!
963 */
964 respond(
965 overwrites: MockOverwrite,
966 params?: MockResponseParams
967 ): Promise<void>;
968
969 /**
970 * > This is a __beta__ feature. Please give us feedback and file [an issue](https://github.com/webdriverio/webdriverio/issues/new/choose) if certain scenarions don't work as expected!
971 */
972 respondOnce(
973 overwrites: MockOverwrite,
974 params?: MockResponseParams
975 ): Promise<void>;
976
977 /**
978 * > This is a __beta__ feature. Please give us feedback and file [an issue](https://github.com/webdriverio/webdriverio/issues/new/choose) if certain scenarions don't work as expected!
979 */
980 restore(): Promise<void>;
981 }
982
983 interface ElementArray extends Array<Element> {
984 selector: string | Function;
985 parent: Element | WebdriverIO.BrowserObject;
986 foundWith: string;
987 props: any[];
988 }
989
990 interface Timeouts {
991 implicit?: number,
992 pageLoad?: number,
993 script?: number
994 }
995
996 interface Browser extends WebDriver.BaseClient {
997 config: Config;
998 options: RemoteOptions;
999
1000 /**
1001 * add command to `browser` or `element` scope
1002 */
1003 addCommand<IsElement extends boolean = false>(
1004 name: string,
1005 func: AddCommandFn<IsElement>,
1006 attachToElement?: IsElement
1007 ): void;
1008
1009 /**
1010 * overwrite `browser` or `element` command
1011 */
1012 overwriteCommand<ElementKey extends keyof Element, BrowserKey extends keyof BrowserObject, IsElement extends boolean = false>(
1013 name: IsElement extends true ? ElementKey : BrowserKey,
1014 func: OverwriteCommandFn<ElementKey, BrowserKey, IsElement>,
1015 attachToElement?: IsElement
1016 ): void;
1017
1018 /**
1019 * create custom selector
1020 */
1021 addLocatorStrategy(
1022 name: string,
1023 func: (elementFetchingMethod: (selector: string) => any) => void
1024 ): void
1025
1026 /**
1027 * The `$$` command is a short way to call the [`findElements`](/docs/api/webdriver.html#findelements) command in order
1028 * to fetch multiple elements on the page. It returns an array with element results that will have an
1029 * extended prototype to call action commands without passing in a selector. However if you still pass
1030 * in a selector it will look for that element first and call the action on that element.
1031 */
1032 $$(
1033 selector: string | Function
1034 ): Promise<ElementArray>;
1035
1036 /**
1037 * The `$` command is a short way to call the [`findElement`](/docs/api/webdriver.html#findelement) command in order
1038 * to fetch a single element on the page. It returns an object that with an extended prototype to call
1039 * action commands without passing in a selector. However if you still pass in a selector it will look
1040 * for that element first and call the action on that element. You can also pass in an object as selector
1041 * where the object contains a property `element-6066-11e4-a52e-4f735466cecf` with the value of a reference
1042 * to an element. The command will then transform the reference to an extended WebdriverIO element.
1043 */
1044 $(
1045 selector: string | Function | object
1046 ): Promise<Element>;
1047
1048 /**
1049 * The `customs$$` allows you to use a custom strategy declared by using `browser.addLocatorStrategy`
1050 */
1051 custom$$(
1052 strategyName: string,
1053 strategyArguments: any
1054 ): Promise<ElementArray>;
1055
1056 /**
1057 * The `custom$` allows you to use a custom strategy declared by using `browser.addLocatorStrategy`
1058 */
1059 custom$(
1060 strategyName: string,
1061 strategyArguments: any
1062 ): Promise<Element>;
1063
1064 /**
1065 * This command helps you to debug your integration tests. It stops the running browser and gives
1066 * you time to jump into it and check the state of your application (e.g. using dev tools).
1067 * Your terminal transforms into a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)
1068 * interface that will allow you to try out certain commands, find elements and test actions on
1069 * them.
1070 */
1071 debug(): Promise<void>;
1072
1073 /**
1074 * Delete cookies visible to the current page. By providing a cookie name it just removes the single cookie or more when multiple names are passed.
1075 */
1076 deleteCookies(
1077 names?: string | string[]
1078 ): Promise<void>;
1079
1080 /**
1081 * Retrieve a [cookie](https://w3c.github.io/webdriver/webdriver-spec.html#cookies)
1082 * visible to the current page. You can query a specific cookie by providing the cookie name or
1083 * retrieve all.
1084 */
1085 getCookies(
1086 names?: string[] | string
1087 ): Promise<WebDriver.Cookie[]>;
1088
1089 /**
1090 * Get the [Puppeteer Browser instance](https://pptr.dev/#?product=Puppeteer&version=v5.1.0&show=api-class-browser)
1091 * to run commands with Puppeteer. Note that all Puppeteer commands are
1092 * asynchronous by default so in order to interchange between sync and async
1093 * execution make sure to wrap your Puppeteer calls within a `browser.call`
1094 * commands as shown in the example.
1095 */
1096 getPuppeteer(): Promise<PuppeteerBrowser>;
1097
1098 /**
1099 * Returns browser window size (and position for drivers with W3C support).
1100 */
1101 getWindowSize(): Promise<WebDriver.RectReturn>;
1102
1103 /**
1104 * Send a sequence of key strokes to the active element. You can also use characters like
1105 * "Left arrow" or "Back space". WebdriverIO will take care of translating them into unicode
1106 * characters. You’ll find all supported characters [here](https://w3c.github.io/webdriver/webdriver-spec.html#keyboard-actions).
1107 * To do that, the value has to correspond to a key from the table.
1108 */
1109 keys(
1110 value: string | string[]
1111 ): Promise<void>;
1112
1113 /**
1114 * > This is a __beta__ feature. Please give us feedback and file [an issue](https://github.com/webdriverio/webdriverio/issues/new/choose) if certain scenarios don't work as expected!
1115 */
1116 mock(
1117 url: string,
1118 filterOptions?: MockFilterOptions
1119 ): Promise<Mock>;
1120
1121 /**
1122 * Open new window in browser. This command is the equivalent function to `window.open()`. This command does not
1123 * work in mobile environments.
1124 */
1125 newWindow(
1126 url: string,
1127 options?: NewWindowOptions
1128 ): Promise<string>;
1129
1130 /**
1131 * Pauses execution for a specific amount of time. It is recommended to not use this command to wait for an
1132 * element to show up. In order to avoid flaky test results it is better to use commands like
1133 * [`waitForExist`](/docs/api/element/waitForExist.html) or other waitFor* commands.
1134 */
1135 pause(
1136 milliseconds: number
1137 ): Promise<void>;
1138
1139 /**
1140 * The `react$$` command is a useful command to query multiple React Components
1141 * by their actual name and filter them by props and state.
1142 */
1143 react$$(
1144 selector: string,
1145 options?: ReactSelectorOptions
1146 ): Promise<ElementArray>;
1147
1148 /**
1149 * The `react$` command is a useful command to query React Components by their
1150 * actual name and filter them by props and state.
1151 */
1152 react$(
1153 selector: string,
1154 options?: ReactSelectorOptions
1155 ): Promise<Element>;
1156
1157 /**
1158 * Creates a new Selenium session with your current capabilities. This is useful if you
1159 * test highly stateful application where you need to clean the browser session between
1160 * the tests in your spec file to avoid creating hundreds of single test files with WDIO.
1161 * Be careful though, this command affects your test time tremendously since spawning
1162 * new Selenium sessions is very time consuming especially when using cloud services.
1163 */
1164 reloadSession(): Promise<void>;
1165
1166 /**
1167 * Appium only. Save a video started by startRecordingScreen command to file.
1168 * See [Appium docs](http://appium.io/docs/en/commands/device/recording-screen/start-recording-screen/)
1169 */
1170 saveRecordingScreen(
1171 filepath: string
1172 ): Promise<Buffer>;
1173
1174 /**
1175 * Save a screenshot of the current browsing context to a PNG file on your OS. Be aware that
1176 * some browser drivers take screenshots of the whole document (e.g. Geckodriver with Firefox)
1177 * and others only of the current viewport (e.g. Chromedriver with Chrome).
1178 */
1179 saveScreenshot(
1180 filepath: string
1181 ): Promise<Buffer>;
1182
1183 /**
1184 * Sets one or more [cookies](https://w3c.github.io/webdriver/#cookies) for the current page. Make sure you are
1185 * on the page that should receive the cookie. You can't set a cookie for an arbitrary page without
1186 * being on that page.
1187 */
1188 setCookies(
1189 cookie: WebDriver.Cookie[] | WebDriver.Cookie
1190 ): Promise<void>;
1191
1192 /**
1193 * Sets the timeouts associated with the current session, timeout durations control such
1194 * behaviour as timeouts on script injection, document navigation, and element retrieval.
1195 * For more information and examples, see [timeouts guide](https://webdriver.io/docs/timeouts.html#selenium-timeouts).
1196 */
1197 setTimeout(
1198 timeouts: Timeouts
1199 ): Promise<void>;
1200
1201 /**
1202 * Resizes browser window outer size according to provided width and height.
1203 */
1204 setWindowSize(
1205 width: number,
1206 height: number
1207 ): Promise<null | object>;
1208
1209 /**
1210 * Switch focus to a particular tab / window.
1211 */
1212 switchWindow(
1213 urlOrTitleToMatch: string | RegExp
1214 ): Promise<void>;
1215
1216 /**
1217 * Throttle the network capabilities of the browser. This can help to
1218 * emulate certain scenarios where a user loses their internet connection
1219 * and your app needs to address that.
1220 */
1221 throttle(
1222 params: ThrottleOptions
1223 ): Promise<void>;
1224
1225 /**
1226 * The Touch Action API provides the basis of all gestures that can be automated in Appium.
1227 * It is currently only available to native apps and can not be used to interact with webapps.
1228 * At its core is the ability to chain together _ad hoc_ individual actions, which will then be
1229 * applied to an element in the application on the device. The basic actions that can be used are:
1230 */
1231 touchAction(
1232 action: TouchActions
1233 ): Promise<void>;
1234
1235 /**
1236 * Uploads a file to the Selenium Standalone server or other browser driver
1237 * (e.g. Chromedriver) by using the [`file`](docs/api/selenium.html#file) command.
1238 * _Note:_ that this command is only supported if you use a Selenium Hub or
1239 * Chromedriver directly.
1240 */
1241 uploadFile(
1242 localPath: string
1243 ): Promise<string>;
1244
1245 /**
1246 * Protocol binding to load the URL of the browser. If a baseUrl is
1247 * specified in the config, it will be prepended to the url parameter using
1248 * node's url.resolve() method.
1249 */
1250 url(
1251 url?: string
1252 ): Promise<void>;
1253
1254 /**
1255 * This wait command is your universal weapon if you want to wait on something. It expects a condition
1256 * and waits until that condition is fulfilled with a truthy value. If you use the WDIO testrunner the
1257 * commands within the condition are getting executed synchronously like in your test.
1258 */
1259 waitUntil(
1260 condition: () => Promise<Boolean>,
1261 options?: WaitUntilOptions
1262 ): Promise<boolean>;
1263 }
1264
1265 interface Config extends Options, Omit<WebDriver.Options, "capabilities">, Hooks {}
1266
1267 interface AddValueOptions {
1268 translateToUnicode?: boolean
1269 }
1270}