Skip to content

Commit b3db259

Browse files
Remove WebdriverIOAsync namespace (webdriverio#4720)
* get rid of WebdriverIOAsync interface * remove comment
1 parent 7ee9bc0 commit b3db259

File tree

5 files changed

+41
-173
lines changed

5 files changed

+41
-173
lines changed

packages/wdio-applitools-service/applitools-service.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/// <reference types="@applitools/visual-grid-client"/>
22

3-
declare module WebdriverIOAsync {
4-
interface Config extends ApplitoolsConfig {}
5-
interface Browser extends ApplitoolsBrowserAsync {}
6-
}
7-
83
declare module WebdriverIO {
94
interface Config extends ApplitoolsConfig {}
105
interface Browser extends ApplitoolsBrowser {}

packages/webdriverio/webdriverio-v6.d.ts

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 37 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,8 @@
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

12167
declare module "webdriverio" {
122-
export = WebdriverIOAsync
68+
export = WebdriverIO
12369
}

tests/typings/webdriverio/async.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async function bar() {
9191
await el5.scrollIntoView(false)
9292

9393
const selector$$: string | Function = elems.selector
94-
const parent$$: WebdriverIOAsync.Element | WebdriverIOAsync.BrowserObject = elems.parent
94+
const parent$$: WebdriverIO.Element | WebdriverIO.BrowserObject = elems.parent
9595

9696
// shadow$ shadow$$
9797
const el6 = await $('')
@@ -109,7 +109,7 @@ async function bar() {
109109

110110
// touchAction
111111
const ele = await $('')
112-
const touchAction: WebdriverIOAsync.TouchAction = {
112+
const touchAction: WebdriverIO.TouchAction = {
113113
action: "longPress",
114114
element: await $(''),
115115
ms: 0,
@@ -124,7 +124,7 @@ async function bar() {
124124
}
125125

126126
// selenium-standalone-service
127-
const config: WebdriverIOAsync.Config = {
127+
const config: WebdriverIO.Config = {
128128
skipSeleniumInstall: true,
129129
seleniumLogs: ''
130130
}

tests/typings/webdriverio/types/async.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
// module should be "webdriverio" if used within `ts` file instead of `d.ts`
6-
declare module WebdriverIOAsync {
6+
declare module WebdriverIO {
77
interface BrowserObject {
88
// multiremote
99
instances: ['myBrowserInstance']

0 commit comments

Comments
 (0)