-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecute.ts
More file actions
28 lines (24 loc) · 853 Bytes
/
execute.ts
File metadata and controls
28 lines (24 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export async function execute<ReturnValue, InnerArguments extends unknown[]>(
browser: WebdriverIO.Browser,
script: string | ((...innerArgs: InnerArguments) => ReturnValue),
...args: InnerArguments
): Promise<ReturnValue | undefined> {
/**
* parameter check
*/
if (typeof script !== 'string' && typeof script !== 'function') {
throw new Error('Expecting script to be type of "string" or "function"');
}
if (!browser) {
throw new Error('WDIO browser is not yet initialised');
}
const scriptString = typeof script === 'function' ? script.toString() : script;
const returnValue = await browser.execute(
function executeWithinElectron(script: string, ...args) {
return window.wdioElectron.execute(script, args);
},
scriptString,
...args,
);
return (returnValue as ReturnValue) ?? undefined;
}