webdriver 7.20.6 → 8.0.0-alpha.213
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -15
- package/build/bidi.d.ts +15 -0
- package/build/bidi.d.ts.map +1 -0
- package/build/bidi.js +77 -0
- package/build/cjs/index.d.ts +2 -0
- package/build/cjs/index.d.ts.map +1 -0
- package/build/cjs/index.js +28 -0
- package/build/cjs/package.json +3 -0
- package/build/command.d.ts +9 -4
- package/build/command.d.ts.map +1 -1
- package/build/command.js +25 -20
- package/build/constants.js +2 -5
- package/build/index.d.ts +4 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +41 -53
- package/build/request/browser.d.ts +3 -3
- package/build/request/browser.d.ts.map +1 -1
- package/build/request/browser.js +7 -13
- package/build/request/factory.d.ts +4 -4
- package/build/request/factory.d.ts.map +1 -1
- package/build/request/factory.js +12 -21
- package/build/request/index.d.ts +3 -3
- package/build/request/index.d.ts.map +1 -1
- package/build/request/index.js +22 -30
- package/build/request/node.d.ts +3 -3
- package/build/request/node.d.ts.map +1 -1
- package/build/request/node.js +11 -40
- package/build/types.d.ts +1 -1
- package/build/types.d.ts.map +1 -1
- package/build/types.js +1 -2
- package/build/utils.d.ts +2 -2
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +38 -50
- package/package.json +27 -14
package/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
WebDriver
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
-
> A lightweight, non-opinionated implementation of the [WebDriver
|
|
4
|
+
> A lightweight, non-opinionated implementation of the [WebDriver](https://w3c.github.io/webdriver/webdriver-spec.html) and [WebDriver BiDi](https://w3c.github.io/webdriver-bidi/) specification including mobile commands supported by [Appium](http://appium.io/)
|
|
5
5
|
|
|
6
6
|
There are [tons](https://github.com/christian-bromann/awesome-selenium#javascript) of Selenium and WebDriver binding implementations in the Node.js world. Every one of them have an opinionated API and recommended way to use. This binding is the most non-opinionated you will find as it just represents the [WebDriver specification](https://w3c.github.io/webdriver/webdriver-spec.html) and doesn't come with any extra or higher level abstraction. It is lightweight and comes with support for the [WebDriver specification](https://w3c.github.io/webdriver/webdriver-spec.html) and Appium's [Mobile JSONWire Protocol](https://github.com/appium/appium-base-driver/blob/master/docs/mjsonwp/protocol-methods.md).
|
|
7
7
|
|
|
8
8
|
The package supports the following protocols:
|
|
9
9
|
|
|
10
10
|
- [WebDriver](https://w3c.github.io/webdriver/)
|
|
11
|
+
- [WebDriver Bidi](https://w3c.github.io/webdriver-bidi/)
|
|
11
12
|
- [Appium](http://appium.io/)
|
|
12
13
|
- [Chromium](http://chromedriver.chromium.org/) (additional Chromedriver specific commands)
|
|
13
14
|
- [Selenium](https://www.selenium.dev/) (additional Selenium WebDriver specific commands)
|
|
@@ -25,31 +26,57 @@ To install this package from NPM run:
|
|
|
25
26
|
npm i webdriver
|
|
26
27
|
```
|
|
27
28
|
|
|
28
|
-
## Example
|
|
29
|
+
## WebDriver Example
|
|
29
30
|
|
|
30
31
|
The following example demonstrates a simple Google Search scenario:
|
|
31
32
|
|
|
32
33
|
```js
|
|
33
34
|
import WebDriver from 'webdriver';
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
36
|
+
const client = await WebDriver.newSession({
|
|
37
|
+
path: '/',
|
|
38
|
+
capabilities: { browserName: 'firefox' }
|
|
39
|
+
})
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
await client.navigateTo('https://www.google.com/ncr')
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const searchInput = await client.findElement('css selector', '#lst-ib')
|
|
44
|
+
await client.elementSendKeys(searchInput['element-6066-11e4-a52e-4f735466cecf'], 'WebDriver')
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
const searchBtn = await client.findElement('css selector', 'input[value="Google Search"]')
|
|
47
|
+
await client.elementClick(searchBtn['element-6066-11e4-a52e-4f735466cecf'])
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
console.log(await client.getTitle()) // outputs "WebDriver - Google Search"
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
await client.deleteSession()
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## WebDriver Bidi Example
|
|
55
|
+
|
|
56
|
+
To connect to the WebDriver Bidi protocol you have to send along a `webSocketUrl` flag to tell the browser driver to opt-in to the protocol:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import WebDriver from './packages/webdriver/build/index.js'
|
|
60
|
+
|
|
61
|
+
const browser = await WebDriver.newSession({
|
|
62
|
+
capabilities: {
|
|
63
|
+
webSocketUrl: true,
|
|
64
|
+
browserName: 'firefox'
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
await browser.send({
|
|
69
|
+
method: 'session.subscribe',
|
|
70
|
+
params: { events: ['log.entryAdded'] }
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* returns: {"method":"log.entryAdded","params":{"type":"console","method":"log","realm":null,"args":[{"type":"string","value":"Hello Bidi"}],"level":"info","text":"Hello Bidi","timestamp":1657282076037}}
|
|
75
|
+
*/
|
|
76
|
+
browser.on('message', (data) => console.log('received %s', data))
|
|
77
|
+
|
|
78
|
+
await browser.executeScript('console.log("Hello Bidi")', [])
|
|
79
|
+
await browser.deleteSession()
|
|
53
80
|
```
|
|
54
81
|
|
|
55
82
|
# Configuration
|
package/build/bidi.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'node:events';
|
|
3
|
+
import WebSocket from 'ws';
|
|
4
|
+
import { BidiRequest, BidiResponse } from '@wdio/protocols';
|
|
5
|
+
export declare class BidiHandler extends EventEmitter {
|
|
6
|
+
#private;
|
|
7
|
+
private _webSocketUrl;
|
|
8
|
+
constructor(_webSocketUrl: string);
|
|
9
|
+
connect(): Promise<void>;
|
|
10
|
+
get socket(): WebSocket;
|
|
11
|
+
get isConnected(): boolean;
|
|
12
|
+
send(params: BidiRequest): Promise<BidiResponse>;
|
|
13
|
+
sendAsync(params: BidiRequest): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=bidi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bidi.d.ts","sourceRoot":"","sources":["../src/bidi.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,SAAS,MAAM,IAAI,CAAA;AAE1B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAK3D,qBAAa,WAAY,SAAQ,YAAY;;IAK5B,OAAO,CAAC,aAAa;gBAAb,aAAa,EAAE,MAAM;IAMnC,OAAO;IAOd,IAAI,MAAM,cAET;IAED,IAAI,WAAW,YAEd;IAEM,IAAI,CAAE,MAAM,EAAE,WAAW;IA6BzB,SAAS,CAAE,MAAM,EAAE,WAAW;CAQxC"}
|
package/build/bidi.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _BidiHandler_id, _BidiHandler_ws, _BidiHandler_isConnected;
|
|
13
|
+
import { EventEmitter } from 'node:events';
|
|
14
|
+
import WebSocket from 'ws';
|
|
15
|
+
import logger from '@wdio/logger';
|
|
16
|
+
const log = logger('webdriver:BidiHandler');
|
|
17
|
+
const RESPONSE_TIMEOUT = 1000 * 60;
|
|
18
|
+
export class BidiHandler extends EventEmitter {
|
|
19
|
+
constructor(_webSocketUrl) {
|
|
20
|
+
super();
|
|
21
|
+
this._webSocketUrl = _webSocketUrl;
|
|
22
|
+
_BidiHandler_id.set(this, 0);
|
|
23
|
+
_BidiHandler_ws.set(this, void 0);
|
|
24
|
+
_BidiHandler_isConnected.set(this, false);
|
|
25
|
+
log.info(`Connect to webSocketUrl ${this._webSocketUrl}`);
|
|
26
|
+
__classPrivateFieldSet(this, _BidiHandler_ws, new WebSocket(this._webSocketUrl), "f");
|
|
27
|
+
}
|
|
28
|
+
connect() {
|
|
29
|
+
return new Promise((resolve) => __classPrivateFieldGet(this, _BidiHandler_ws, "f").on('open', () => {
|
|
30
|
+
__classPrivateFieldSet(this, _BidiHandler_isConnected, true, "f");
|
|
31
|
+
resolve();
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
get socket() {
|
|
35
|
+
return __classPrivateFieldGet(this, _BidiHandler_ws, "f");
|
|
36
|
+
}
|
|
37
|
+
get isConnected() {
|
|
38
|
+
return __classPrivateFieldGet(this, _BidiHandler_isConnected, "f");
|
|
39
|
+
}
|
|
40
|
+
send(params) {
|
|
41
|
+
var _a;
|
|
42
|
+
if (!__classPrivateFieldGet(this, _BidiHandler_isConnected, "f")) {
|
|
43
|
+
throw new Error('No connection to WebDriver Bidi was established');
|
|
44
|
+
}
|
|
45
|
+
const id = __classPrivateFieldSet(this, _BidiHandler_id, (_a = __classPrivateFieldGet(this, _BidiHandler_id, "f"), ++_a), "f");
|
|
46
|
+
__classPrivateFieldGet(this, _BidiHandler_ws, "f").send(JSON.stringify({ id, ...params }));
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
const t = setTimeout(() => {
|
|
49
|
+
reject(new Error(`Request with id ${id} timed out`));
|
|
50
|
+
h.off('message', listener);
|
|
51
|
+
}, RESPONSE_TIMEOUT);
|
|
52
|
+
const listener = (data) => {
|
|
53
|
+
try {
|
|
54
|
+
const payload = JSON.parse(data.toString());
|
|
55
|
+
if (payload.id === id) {
|
|
56
|
+
clearTimeout(t);
|
|
57
|
+
h.off('message', listener);
|
|
58
|
+
resolve(payload);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
log.error(`Failed parse message: ${err.message}`);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const h = __classPrivateFieldGet(this, _BidiHandler_ws, "f").on('message', listener);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
sendAsync(params) {
|
|
69
|
+
var _a;
|
|
70
|
+
if (!__classPrivateFieldGet(this, _BidiHandler_isConnected, "f")) {
|
|
71
|
+
throw new Error('No connection to WebDriver Bidi was established');
|
|
72
|
+
}
|
|
73
|
+
const id = __classPrivateFieldSet(this, _BidiHandler_id, (_a = __classPrivateFieldGet(this, _BidiHandler_id, "f"), ++_a), "f");
|
|
74
|
+
__classPrivateFieldGet(this, _BidiHandler_ws, "f").send(JSON.stringify({ id, ...params }));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
_BidiHandler_id = new WeakMap(), _BidiHandler_ws = new WeakMap(), _BidiHandler_isConnected = new WeakMap();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cjs/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module.exports = class WebDriver {
|
|
2
|
+
static async newSession(options, modifier, userPrototype = {}, customCommandWrapper) {
|
|
3
|
+
const WebDriver = (await import('../index.js')).default;
|
|
4
|
+
return WebDriver.newSession(options, modifier, userPrototype, customCommandWrapper);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* allows user to attach to existing sessions
|
|
8
|
+
*/
|
|
9
|
+
static async attachToSession(options, modifier, userPrototype = {}, commandWrapper) {
|
|
10
|
+
const WebDriver = (await import('../index.js')).default;
|
|
11
|
+
return WebDriver.attachToSession(options, modifier, userPrototype, commandWrapper);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Changes The instance session id and browser capabilities for the new session
|
|
15
|
+
* directly into the passed in browser object
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} instance the object we get from a new browser session.
|
|
18
|
+
* @returns {string} the new session id of the browser
|
|
19
|
+
*/
|
|
20
|
+
static async reloadSession(instance) {
|
|
21
|
+
const WebDriver = (await import('../index.js')).default;
|
|
22
|
+
return WebDriver.reloadSession(instance);
|
|
23
|
+
}
|
|
24
|
+
static get WebDriver() {
|
|
25
|
+
return WebDriver;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
package/build/command.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type { CommandEndpoint } from '@wdio/protocols';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import type { CommandEndpoint, BidiResponse } from '@wdio/protocols';
|
|
2
|
+
import { BidiHandler } from './bidi.js';
|
|
3
|
+
import type { WebDriverResponse } from './request';
|
|
4
|
+
import type { BaseClient } from './types';
|
|
5
|
+
interface BaseClientWithEventHandler extends BaseClient {
|
|
6
|
+
eventMiddleware: BidiHandler;
|
|
7
|
+
}
|
|
8
|
+
export default function (method: string, endpointUri: string, commandInfo: CommandEndpoint, doubleEncodeVariables?: boolean): (this: BaseClientWithEventHandler, ...args: any[]) => Promise<WebDriverResponse | BidiResponse | void>;
|
|
9
|
+
export {};
|
|
5
10
|
//# sourceMappingURL=command.d.ts.map
|
package/build/command.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAGpE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAKzC,UAAU,0BAA2B,SAAQ,UAAU;IACnD,eAAe,EAAE,WAAW,CAAA;CAC/B;AAED,MAAM,CAAC,OAAO,WACV,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,eAAe,EAC5B,qBAAqB,UAAQ,UAIgB,0BAA0B,WAAW,GAAG,EAAE,KAAG,QAAQ,iBAAiB,GAAG,YAAY,GAAG,IAAI,CAAC,CAuG7I"}
|
package/build/command.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const utils_1 = require("@wdio/utils");
|
|
8
|
-
const factory_1 = __importDefault(require("./request/factory"));
|
|
9
|
-
const log = (0, logger_1.default)('webdriver');
|
|
10
|
-
function default_1(method, endpointUri, commandInfo, doubleEncodeVariables = false) {
|
|
1
|
+
import logger from '@wdio/logger';
|
|
2
|
+
import { commandCallStructure, isValidParameter, getArgumentType } from '@wdio/utils';
|
|
3
|
+
import RequestFactory from './request/factory.js';
|
|
4
|
+
const log = logger('webdriver');
|
|
5
|
+
const BIDI_COMMANDS = ['send', 'sendAsync'];
|
|
6
|
+
export default function (method, endpointUri, commandInfo, doubleEncodeVariables = false) {
|
|
11
7
|
const { command, ref, parameters, variables = [], isHubCommand = false } = commandInfo;
|
|
12
|
-
return function protocolCommand(...args) {
|
|
8
|
+
return async function protocolCommand(...args) {
|
|
13
9
|
let endpoint = endpointUri; // clone endpointUri in case we change it
|
|
14
10
|
const commandParams = [...variables.map((v) => Object.assign(v, {
|
|
15
11
|
/**
|
|
@@ -40,7 +36,7 @@ function default_1(method, endpointUri, commandInfo, doubleEncodeVariables = fal
|
|
|
40
36
|
for (const [it, arg] of Object.entries(args)) {
|
|
41
37
|
const i = parseInt(it, 10);
|
|
42
38
|
const commandParam = commandParams[i];
|
|
43
|
-
if (!
|
|
39
|
+
if (!isValidParameter(arg, commandParam.type)) {
|
|
44
40
|
/**
|
|
45
41
|
* ignore if argument is not required
|
|
46
42
|
*/
|
|
@@ -48,8 +44,8 @@ function default_1(method, endpointUri, commandInfo, doubleEncodeVariables = fal
|
|
|
48
44
|
continue;
|
|
49
45
|
}
|
|
50
46
|
const actual = commandParam.type.endsWith('[]')
|
|
51
|
-
? `(${(Array.isArray(arg) ? arg : [arg]).map((a) =>
|
|
52
|
-
:
|
|
47
|
+
? `(${(Array.isArray(arg) ? arg : [arg]).map((a) => getArgumentType(a))})[]`
|
|
48
|
+
: getArgumentType(arg);
|
|
53
49
|
throw new Error(`Malformed type for "${commandParam.name}" parameter of command ${command}\n` +
|
|
54
50
|
`Expected: ${commandParam.type}\n` +
|
|
55
51
|
`Actual: ${actual}` +
|
|
@@ -68,22 +64,31 @@ function default_1(method, endpointUri, commandInfo, doubleEncodeVariables = fal
|
|
|
68
64
|
*/
|
|
69
65
|
body[commandParams[i].name] = arg;
|
|
70
66
|
}
|
|
71
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Handle Bidi calls
|
|
69
|
+
*/
|
|
70
|
+
if (this.sessionId && BIDI_COMMANDS.includes(command)) {
|
|
71
|
+
if (!this.eventMiddleware) {
|
|
72
|
+
throw new Error('Your WebDriver session doesn\'t support WebDriver Bidi');
|
|
73
|
+
}
|
|
74
|
+
return this.eventMiddleware[command](body.params);
|
|
75
|
+
}
|
|
76
|
+
const request = await RequestFactory.getInstance(method, endpoint, body, isHubCommand);
|
|
72
77
|
request.on('performance', (...args) => this.emit('request.performance', ...args));
|
|
73
78
|
this.emit('command', { method, endpoint, body });
|
|
74
|
-
log.info('COMMAND',
|
|
79
|
+
log.info('COMMAND', commandCallStructure(command, args));
|
|
75
80
|
return request.makeRequest(this.options, this.sessionId).then((result) => {
|
|
76
81
|
if (result.value != null) {
|
|
77
82
|
log.info('RESULT', /screenshot|recording/i.test(command)
|
|
78
83
|
&& typeof result.value === 'string' && result.value.length > 64
|
|
79
|
-
? `${result.value.
|
|
84
|
+
? `${result.value.slice(0, 61)}...`
|
|
85
|
+
: result.value);
|
|
80
86
|
}
|
|
81
87
|
this.emit('result', { method, endpoint, body, result });
|
|
82
|
-
if (command === 'deleteSession') {
|
|
83
|
-
|
|
88
|
+
if (command === 'deleteSession' && !process.env.WDIO_WORKER_ID) {
|
|
89
|
+
logger.clearLogger();
|
|
84
90
|
}
|
|
85
91
|
return result.value;
|
|
86
92
|
});
|
|
87
93
|
};
|
|
88
94
|
}
|
|
89
|
-
exports.default = default_1;
|
package/build/constants.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REG_EXPS = exports.DEFAULTS = void 0;
|
|
4
|
-
exports.DEFAULTS = {
|
|
1
|
+
export const DEFAULTS = {
|
|
5
2
|
/**
|
|
6
3
|
* protocol of automation driver
|
|
7
4
|
*/
|
|
@@ -139,7 +136,7 @@ exports.DEFAULTS = {
|
|
|
139
136
|
default: true
|
|
140
137
|
}
|
|
141
138
|
};
|
|
142
|
-
|
|
139
|
+
export const REG_EXPS = {
|
|
143
140
|
commandName: /.*\/session\/[0-9a-f-]+\/(.*)/,
|
|
144
141
|
execFn: /return \(([\s\S]*)\)\.apply\(null, arguments\)/
|
|
145
142
|
};
|
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Options } from '@wdio/types';
|
|
2
|
-
import command from './command';
|
|
3
|
-
import { DEFAULTS } from './constants';
|
|
4
|
-
import { getPrototype } from './utils';
|
|
2
|
+
import command from './command.js';
|
|
3
|
+
import { DEFAULTS } from './constants.js';
|
|
4
|
+
import { getPrototype } from './utils.js';
|
|
5
5
|
import type { Client, AttachOptions } from './types';
|
|
6
6
|
export default class WebDriver {
|
|
7
7
|
static newSession(options: Options.WebDriver, modifier?: (...args: any[]) => any, userPrototype?: {}, customCommandWrapper?: (...args: any[]) => any): Promise<Client>;
|
|
@@ -23,5 +23,5 @@ export default class WebDriver {
|
|
|
23
23
|
* Helper methods consumed by webdriverio package
|
|
24
24
|
*/
|
|
25
25
|
export { getPrototype, DEFAULTS, command };
|
|
26
|
-
export * from './types';
|
|
26
|
+
export * from './types.js';
|
|
27
27
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAA;AAExD,OAAO,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,aAAa,CAAA;AAExD,OAAO,OAAO,MAAM,cAAc,CAAA;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EACoB,YAAY,EACtC,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAgB,MAAM,SAAS,CAAA;AAIlE,MAAM,CAAC,OAAO,OAAO,SAAS;WACb,UAAU,CACnB,OAAO,EAAE,OAAO,CAAC,SAAS,EAC1B,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAClC,aAAa,KAAK,EAClB,oBAAoB,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAC/C,OAAO,CAAC,MAAM,CAAC;IAoDlB;;OAEG;IACH,MAAM,CAAC,eAAe,CAClB,OAAO,CAAC,EAAE,aAAa,EACvB,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAClC,aAAa,KAAK,EAClB,cAAc,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GACzC,MAAM;IAwBT;;;;;;MAME;WACW,aAAa,CAAE,QAAQ,EAAE,MAAM;IAW5C,MAAM,KAAK,SAAS,qBAEnB;CACJ;AAED;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;AAC1C,cAAc,YAAY,CAAA"}
|
package/build/index.js
CHANGED
|
@@ -1,55 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.command = exports.DEFAULTS = exports.getPrototype = void 0;
|
|
21
|
-
const path_1 = __importDefault(require("path"));
|
|
22
|
-
const logger_1 = __importDefault(require("@wdio/logger"));
|
|
23
|
-
const utils_1 = require("@wdio/utils");
|
|
24
|
-
const config_1 = require("@wdio/config");
|
|
25
|
-
const command_1 = __importDefault(require("./command"));
|
|
26
|
-
exports.command = command_1.default;
|
|
27
|
-
const constants_1 = require("./constants");
|
|
28
|
-
Object.defineProperty(exports, "DEFAULTS", { enumerable: true, get: function () { return constants_1.DEFAULTS; } });
|
|
29
|
-
const utils_2 = require("./utils");
|
|
30
|
-
Object.defineProperty(exports, "getPrototype", { enumerable: true, get: function () { return utils_2.getPrototype; } });
|
|
31
|
-
const log = (0, logger_1.default)('webdriver');
|
|
32
|
-
class WebDriver {
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import logger from '@wdio/logger';
|
|
3
|
+
import { webdriverMonad, sessionEnvironmentDetector } from '@wdio/utils';
|
|
4
|
+
import { validateConfig } from '@wdio/config';
|
|
5
|
+
import command from './command.js';
|
|
6
|
+
import { BidiHandler } from './bidi.js';
|
|
7
|
+
import { DEFAULTS } from './constants.js';
|
|
8
|
+
import { startWebDriverSession, getPrototype, getEnvironmentVars, setupDirectConnect } from './utils.js';
|
|
9
|
+
const log = logger('webdriver');
|
|
10
|
+
export default class WebDriver {
|
|
33
11
|
static async newSession(options, modifier, userPrototype = {}, customCommandWrapper) {
|
|
34
|
-
const params =
|
|
12
|
+
const params = validateConfig(DEFAULTS, options);
|
|
35
13
|
if (!options.logLevels || !options.logLevels.webdriver) {
|
|
36
|
-
|
|
14
|
+
logger.setLevel('webdriver', params.logLevel);
|
|
37
15
|
}
|
|
38
16
|
/**
|
|
39
17
|
* Store all log events in a file
|
|
40
18
|
*/
|
|
41
19
|
if (params.outputDir && !process.env.WDIO_LOG_PATH) {
|
|
42
|
-
process.env.WDIO_LOG_PATH =
|
|
20
|
+
process.env.WDIO_LOG_PATH = path.join(params.outputDir, 'wdio.log');
|
|
43
21
|
}
|
|
44
22
|
log.info('Initiate new session using the WebDriver protocol');
|
|
45
23
|
const requestedCapabilities = { ...params.capabilities };
|
|
46
|
-
const { sessionId, capabilities } = await
|
|
47
|
-
const environment =
|
|
48
|
-
const environmentPrototype =
|
|
49
|
-
const protocolCommands =
|
|
24
|
+
const { sessionId, capabilities } = await startWebDriverSession(params);
|
|
25
|
+
const environment = sessionEnvironmentDetector({ capabilities, requestedCapabilities });
|
|
26
|
+
const environmentPrototype = getEnvironmentVars(environment);
|
|
27
|
+
const protocolCommands = getPrototype(environment);
|
|
50
28
|
const prototype = { ...protocolCommands, ...environmentPrototype, ...userPrototype };
|
|
51
|
-
const monad =
|
|
52
|
-
|
|
29
|
+
const monad = webdriverMonad({ ...params, requestedCapabilities }, modifier, prototype);
|
|
30
|
+
let handler;
|
|
31
|
+
if (capabilities.webSocketUrl) {
|
|
32
|
+
log.info(`Register BiDi handler for session with id ${sessionId}`);
|
|
33
|
+
const socketUrl = capabilities.webSocketUrl.replace('localhost', '127.0.0.1');
|
|
34
|
+
handler = new BidiHandler(socketUrl);
|
|
35
|
+
await handler.connect();
|
|
36
|
+
}
|
|
37
|
+
const client = monad(sessionId, customCommandWrapper, handler);
|
|
53
38
|
/**
|
|
54
39
|
* if the server responded with direct connect information, update the
|
|
55
40
|
* client options to speak directly to the appium host instead of a load
|
|
@@ -58,7 +43,7 @@ class WebDriver {
|
|
|
58
43
|
* behavior in the first place.
|
|
59
44
|
*/
|
|
60
45
|
if (params.enableDirectConnect) {
|
|
61
|
-
|
|
46
|
+
setupDirectConnect(client);
|
|
62
47
|
}
|
|
63
48
|
return client;
|
|
64
49
|
}
|
|
@@ -71,18 +56,18 @@ class WebDriver {
|
|
|
71
56
|
}
|
|
72
57
|
// logLevel can be undefined in watch mode when SIGINT is called
|
|
73
58
|
if (options.logLevel) {
|
|
74
|
-
|
|
59
|
+
logger.setLevel('webdriver', options.logLevel);
|
|
75
60
|
}
|
|
76
61
|
options.capabilities = options.capabilities || {};
|
|
77
62
|
options.isW3C = options.isW3C === false ? false : true;
|
|
78
|
-
options.protocol = options.protocol ||
|
|
79
|
-
options.hostname = options.hostname ||
|
|
80
|
-
options.port = options.port ||
|
|
81
|
-
options.path = options.path ||
|
|
82
|
-
const environmentPrototype =
|
|
83
|
-
const protocolCommands =
|
|
63
|
+
options.protocol = options.protocol || DEFAULTS.protocol.default;
|
|
64
|
+
options.hostname = options.hostname || DEFAULTS.hostname.default;
|
|
65
|
+
options.port = options.port || DEFAULTS.port.default;
|
|
66
|
+
options.path = options.path || DEFAULTS.path.default;
|
|
67
|
+
const environmentPrototype = getEnvironmentVars(options);
|
|
68
|
+
const protocolCommands = getPrototype(options);
|
|
84
69
|
const prototype = { ...protocolCommands, ...environmentPrototype, ...userPrototype };
|
|
85
|
-
const monad =
|
|
70
|
+
const monad = webdriverMonad(options, modifier, prototype);
|
|
86
71
|
return monad(options.sessionId, commandWrapper);
|
|
87
72
|
}
|
|
88
73
|
/**
|
|
@@ -97,7 +82,7 @@ class WebDriver {
|
|
|
97
82
|
...instance.options,
|
|
98
83
|
capabilities: instance.requestedCapabilities
|
|
99
84
|
};
|
|
100
|
-
const { sessionId, capabilities } = await
|
|
85
|
+
const { sessionId, capabilities } = await startWebDriverSession(params);
|
|
101
86
|
instance.sessionId = sessionId;
|
|
102
87
|
instance.capabilities = capabilities;
|
|
103
88
|
return sessionId;
|
|
@@ -106,5 +91,8 @@ class WebDriver {
|
|
|
106
91
|
return WebDriver;
|
|
107
92
|
}
|
|
108
93
|
}
|
|
109
|
-
|
|
110
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Helper methods consumed by webdriverio package
|
|
96
|
+
*/
|
|
97
|
+
export { getPrototype, DEFAULTS, command };
|
|
98
|
+
export * from './types.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Options } from '@wdio/types';
|
|
2
|
-
import WebDriverRequest from './index';
|
|
1
|
+
import type { Options } from '@wdio/types';
|
|
2
|
+
import WebDriverRequest from './index.js';
|
|
3
3
|
declare type RequestLibOptions = Options.RequestLibOptions;
|
|
4
4
|
declare type RequestOptions = Omit<Options.WebDriver, 'capabilities'>;
|
|
5
5
|
export default class BrowserRequest extends WebDriverRequest {
|
|
6
6
|
constructor(method: string, endpoint: string, body?: Record<string, unknown>, isHubCommand?: boolean);
|
|
7
|
-
protected _createOptions(options: RequestOptions, sessionId?: string): RequestLibOptions
|
|
7
|
+
protected _createOptions(options: RequestOptions, sessionId?: string): Promise<RequestLibOptions>;
|
|
8
8
|
protected _libRequest(url: URL, options: RequestLibOptions): Promise<{
|
|
9
9
|
statusCode: number;
|
|
10
10
|
body: unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/request/browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/request/browser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,gBAAgB,MAAM,YAAY,CAAA;AAEzC,aAAK,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAA;AAClD,aAAK,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;AAU7D,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,gBAAgB;gBAE3C,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAE,OAAe;cAI5F,cAAc,CAAE,OAAO,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;cAIxF,WAAW,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,iBAAiB;;;;IA+BjE,SAAS,CAAC,kBAAkB,IAAI,MAAM;CAGzC"}
|
package/build/request/browser.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const logger_1 = __importDefault(require("@wdio/logger"));
|
|
7
|
-
const index_1 = __importDefault(require("./index"));
|
|
8
|
-
const ky_1 = __importDefault(require("ky"));
|
|
9
|
-
const log = (0, logger_1.default)('webdriver');
|
|
1
|
+
import ky from 'ky';
|
|
2
|
+
import logger from '@wdio/logger';
|
|
3
|
+
import WebDriverRequest from './index.js';
|
|
4
|
+
const log = logger('webdriver');
|
|
10
5
|
const UNSUPPORTED_OPTS = [
|
|
11
6
|
'agent',
|
|
12
7
|
'responseType',
|
|
13
8
|
'searchParams',
|
|
14
9
|
];
|
|
15
|
-
class BrowserRequest extends
|
|
10
|
+
export default class BrowserRequest extends WebDriverRequest {
|
|
16
11
|
constructor(method, endpoint, body, isHubCommand = false) {
|
|
17
12
|
super(method, endpoint, body, isHubCommand);
|
|
18
13
|
}
|
|
19
|
-
_createOptions(options, sessionId) {
|
|
14
|
+
async _createOptions(options, sessionId) {
|
|
20
15
|
return super._createOptions(options, sessionId, true);
|
|
21
16
|
}
|
|
22
17
|
async _libRequest(url, options) {
|
|
@@ -38,7 +33,7 @@ class BrowserRequest extends index_1.default {
|
|
|
38
33
|
Authorization: `Basic ${encodedAuth}`
|
|
39
34
|
};
|
|
40
35
|
}
|
|
41
|
-
const res = await (
|
|
36
|
+
const res = await ky(url, kyOptions);
|
|
42
37
|
return {
|
|
43
38
|
statusCode: res.status,
|
|
44
39
|
body: await res.json(),
|
|
@@ -48,4 +43,3 @@ class BrowserRequest extends index_1.default {
|
|
|
48
43
|
return performance.now();
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
|
-
exports.default = BrowserRequest;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import type { URL as URLType } from 'node:url';
|
|
3
|
+
import WebDriverRequest from './index.js';
|
|
4
4
|
export default class RequestFactory {
|
|
5
|
-
static getInstance(method: string, endpoint: string, body?: Record<string, unknown>, isHubCommand?: boolean): WebDriverRequest
|
|
5
|
+
static getInstance(method: string, endpoint: string, body?: Record<string, unknown>, isHubCommand?: boolean): Promise<WebDriverRequest>;
|
|
6
6
|
}
|
|
7
7
|
export declare class URLFactory {
|
|
8
|
-
static getInstance(uri: string): URLType
|
|
8
|
+
static getInstance(uri: string): Promise<URLType>;
|
|
9
9
|
}
|
|
10
10
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/request/factory.ts"],"names":[],"mappings":";AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/request/factory.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,UAAU,CAAA;AAI9C,OAAO,gBAAgB,MAAM,YAAY,CAAA;AAOzC,MAAM,CAAC,OAAO,OAAO,cAAc;WAClB,WAAW,CACpB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,YAAY,GAAE,OAAe,GAC9B,OAAO,CAAC,gBAAgB,CAAC;CAS/B;AAED,qBAAa,UAAU;WACN,WAAW,CAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAO3D"}
|