1- /// <reference types="webdriverio/webdriverio-core-v5 "/>
1+ /// <reference types="webdriverio/webdriverio-core"/>
22
3- type $ = ( selector : string | Function ) => Promise < WebdriverIOAsync . Element > ;
4- type $$ = ( selector : string | Function ) => Promise < WebdriverIOAsync . ElementArray > ;
5-
6- // Element commands that should be wrapper with Promise
7- type ElementPromise = Omit < WebdriverIO . Element ,
8- 'addCommand'
9- | '$'
10- | '$$'
11- | 'selector'
12- | 'elementId'
13- | 'element-6066-11e4-a52e-4f735466cecf'
14- | 'ELEMENT'
15- | 'index'
16- | 'parent'
17- | 'dragAndDrop'
18- | 'touchAction'
19- > ;
20-
21- // Methods which return async element(s) so non-async equivalents cannot just be promise-wrapped
22- interface AsyncSelectors {
23- $ : $ ;
24- $$ : $$ ;
25- }
26-
27- // Element commands wrapper with Promise
28- type ElementAsync = {
29- [ K in keyof ElementPromise ] :
30- ( ...args : Parameters < ElementPromise [ K ] > ) => Promise < ReturnType < ElementPromise [ K ] > > ;
31- } & AsyncSelectors ;
32-
33- // Element commands that should not be wrapper with promise
34- type ElementStatic = Pick < WebdriverIO . Element ,
35- 'addCommand'
36- | 'selector'
37- | 'elementId'
38- | 'element-6066-11e4-a52e-4f735466cecf'
39- | 'ELEMENT'
40- | 'index'
41- | 'parent'
42- > ;
43-
44- // Browser commands that should be wrapper with Promise
45- type BrowserPromise = Omit < WebdriverIO . Browser , 'addCommand' | 'overwriteCommand' | 'options' | 'config' | '$' | '$$' | 'touchAction' > ;
46-
47- // Browser commands wrapper with Promise
48- type BrowserAsync = {
49- [ K in keyof BrowserPromise ] :
50- ( ...args : Parameters < BrowserPromise [ K ] > ) => Promise < ReturnType < BrowserPromise [ K ] > > ;
51- } & AsyncSelectors ;
52-
53- // Browser commands that should not be wrapper with promise
54- type BrowserStatic = Pick < WebdriverIO . Browser , 'addCommand' | 'overwriteCommand' | 'options' | 'config' > ;
55-
56- // Properties of TouchAction which are similar in sync and async mode
57- type TouchActionSync = Omit < WebdriverIO . TouchAction , 'element' >
58-
59- declare namespace WebdriverIOAsync {
3+ declare namespace WebdriverIO {
604 function remote (
61- options ?: WebdriverIO . RemoteOptions ,
5+ options ?: RemoteOptions ,
626 modifier ?: ( ...args : any [ ] ) => any
637 ) : BrowserObject ;
648
@@ -67,57 +11,59 @@ declare namespace WebdriverIOAsync {
6711 ) : BrowserObject ;
6812
6913 function multiremote (
70- options : WebdriverIO . MultiRemoteOptions
14+ options : MultiRemoteOptions
7115 ) : BrowserObject ;
72- interface TouchAction extends TouchActionSync {
73- element ?: Element
74- }
75- type TouchActions = string | TouchAction | TouchAction [ ] ;
76- interface Browser extends BrowserAsync , BrowserStatic {
16+
17+ interface Browser {
18+ /**
19+ * waits until the condition is fulfilled with a truthy value
20+ */
7721 waitUntil (
7822 condition : ( ) => Promise < boolean > ,
7923 timeout ?: number ,
8024 timeoutMsg ?: string ,
8125 interval ?: number
8226 ) : Promise < boolean > ;
8327
84- // there is no way to wrap generic functions, like `<T>(arg: T) => T`
85- // have to declare explicitly for sync and async typings.
86- // https://github.com/microsoft/TypeScript/issues/5453
28+ /**
29+ * execute any async action within your test spec
30+ */
8731 call : < T > ( callback : ( ...args : any [ ] ) => Promise < T > ) => Promise < T > ;
32+
33+ /**
34+ * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
35+ * The executed script is assumed to be synchronous and the result of evaluating the script is returned to
36+ * the client.
37+ */
8838 execute : < T > ( script : string | ( ( ...arguments : any [ ] ) => T ) , ...arguments : any [ ] ) => Promise < T > ;
8939
90- // also there is no way to add callback as last parameter after `...args`.
40+ // there is no way to add callback as last parameter after `...args`.
9141 // https://github.com/Microsoft/TypeScript/issues/1360
9242 // executeAsync: <T>(script: string | ((...arguments: any[], callback: (result: T) => void) => void), ...arguments: any[]) => Promise<T>;
43+ /**
44+ * Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
45+ * The executed script is assumed to be asynchronous and must signal that is done by invoking
46+ * the provided callback, which is always provided as the final argument to the function. The value
47+ * to this callback will be returned to the client.
48+ */
9349 executeAsync : ( script : string | ( ( ...arguments : any [ ] ) => void ) , ...arguments : any [ ] ) => Promise < any > ;
94- touchAction ( action : TouchActions ) : Promise < void > ;
95- }
96-
97- interface Element extends ElementAsync , ElementStatic {
98- dragAndDrop ( target : Element , duration ?: number ) : Promise < void > ;
99- touchAction ( action : TouchActions ) : Promise < void > ;
10050 }
101- interface ElementArray extends Array < Element > {
102- selector : string | Function ;
103- parent : Element | BrowserObject ;
104- foundWith : string ;
105- props : any [ ] ;
106- }
107-
108- interface Config { }
10951
110- interface BrowserObject extends WebDriver . ClientOptions , WebDriver . ClientAsync , WebdriverIOAsync . Browser { }
52+ interface BrowserObject extends WebDriver . ClientOptions , WebDriver . ClientAsync , Browser { }
11153}
11254
113- declare namespace WebdriverIO {
114- interface BrowserObject extends WebdriverIOAsync . BrowserObject { }
115- }
55+ declare var browser : WebdriverIO . BrowserObject ;
56+
57+ /**
58+ * find a single element on the page.
59+ */
60+ declare var $ : ( selector : string | Function ) => Promise < WebdriverIO . Element > ;
11661
117- declare var browser : WebdriverIOAsync . BrowserObject ;
118- declare var $ : $ ;
119- declare var $$ : $$ ;
62+ /**
63+ * find multiple elements on the page.
64+ */
65+ declare var $$ : ( selector : string | Function ) => Promise < WebdriverIO . ElementArray > ;
12066
12167declare module "webdriverio" {
122- export = WebdriverIOAsync
68+ export = WebdriverIO
12369}
0 commit comments