appium 2.13.1 → 2.14.1
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/build/lib/appium.d.ts +4 -64
- package/build/lib/appium.d.ts.map +1 -1
- package/build/lib/appium.js +48 -316
- package/build/lib/appium.js.map +1 -1
- package/build/lib/bidi.d.ts +32 -0
- package/build/lib/bidi.d.ts.map +1 -0
- package/build/lib/bidi.js +348 -0
- package/build/lib/bidi.js.map +1 -0
- package/build/lib/cli/args.d.ts.map +1 -1
- package/build/lib/cli/args.js +21 -31
- package/build/lib/cli/args.js.map +1 -1
- package/build/lib/cli/extension-command.d.ts.map +1 -1
- package/build/lib/cli/extension-command.js +38 -5
- package/build/lib/cli/extension-command.js.map +1 -1
- package/build/lib/cli/parser.d.ts.map +1 -1
- package/build/lib/cli/parser.js +26 -15
- package/build/lib/cli/parser.js.map +1 -1
- package/build/lib/cli/utils.d.ts.map +1 -1
- package/build/lib/cli/utils.js +3 -1
- package/build/lib/cli/utils.js.map +1 -1
- package/build/lib/config.js +42 -9
- package/build/lib/config.js.map +1 -1
- package/build/lib/extension/extension-config.d.ts +7 -0
- package/build/lib/extension/extension-config.d.ts.map +1 -1
- package/build/lib/extension/extension-config.js +42 -11
- package/build/lib/extension/extension-config.js.map +1 -1
- package/build/lib/extension/manifest.js +2 -2
- package/build/lib/extension/manifest.js.map +1 -1
- package/build/lib/schema/schema.js +3 -3
- package/build/lib/schema/schema.js.map +1 -1
- package/build/lib/utils.js +1 -2
- package/build/lib/utils.js.map +1 -1
- package/lib/appium.js +18 -377
- package/lib/bidi.ts +436 -0
- package/lib/cli/args.js +22 -32
- package/lib/cli/extension-command.js +4 -4
- package/lib/cli/parser.js +33 -17
- package/lib/cli/utils.js +3 -1
- package/lib/config.js +7 -7
- package/lib/extension/extension-config.js +49 -11
- package/lib/extension/manifest.js +2 -2
- package/lib/schema/schema.js +2 -2
- package/lib/utils.js +2 -2
- package/package.json +11 -11
- package/scripts/autoinstall-extensions.js +5 -5
package/build/lib/appium.d.ts
CHANGED
|
@@ -131,69 +131,6 @@ export class AppiumDriver extends DriverCore<{
|
|
|
131
131
|
* @returns {StringRecord|undefined} Arguments object. If none, `undefined`
|
|
132
132
|
*/
|
|
133
133
|
getCliArgsForDriver(extName: string): StringRecord | undefined;
|
|
134
|
-
/**
|
|
135
|
-
* Initialize a new bidi connection and set up handlers
|
|
136
|
-
* @param {import('ws').WebSocket} ws The websocket connection object
|
|
137
|
-
* @param {import('http').IncomingMessage} req The connection pathname, which might include the session id
|
|
138
|
-
*/
|
|
139
|
-
onBidiConnection(ws: import("ws").WebSocket, req: import("http").IncomingMessage): void;
|
|
140
|
-
/**
|
|
141
|
-
* Initialize a new bidi connection
|
|
142
|
-
* @param {import('ws').WebSocket} ws The websocket connection object
|
|
143
|
-
* @param {import('http').IncomingMessage} req The connection pathname, which might include the session id
|
|
144
|
-
*/
|
|
145
|
-
initBidiSocket(ws: import("ws").WebSocket, req: import("http").IncomingMessage): {
|
|
146
|
-
bidiHandlerDriver: AppiumDriver | import("@appium/types").ExternalDriver<import("@appium/types").Constraints, string, import("@appium/types").StringRecord, import("@appium/types").StringRecord, import("@appium/types").DefaultCreateSessionResult<import("@appium/types").Constraints>, void, import("@appium/types").StringRecord>;
|
|
147
|
-
proxyClient: WebSocket.WebSocket | null;
|
|
148
|
-
send: (data: string | Buffer) => Promise<void>;
|
|
149
|
-
sendToProxy: ((data: string | Buffer) => Promise<void>) | null;
|
|
150
|
-
logSocketErr: (err: Error) => void;
|
|
151
|
-
};
|
|
152
|
-
/**
|
|
153
|
-
* Set up handlers on upstream bidi socket we are proxying to/from
|
|
154
|
-
*
|
|
155
|
-
* @param {import('ws').WebSocket | null} proxyClient - the websocket connection to/from the
|
|
156
|
-
* upstream socket (the one we're proxying to/from)
|
|
157
|
-
* @param {import('ws').WebSocket} ws - the websocket connection to/from the client
|
|
158
|
-
* @param {(data: string | Buffer) => Promise<void>} send - a method used to send data to the
|
|
159
|
-
* client
|
|
160
|
-
*/
|
|
161
|
-
initBidiProxyHandlers(proxyClient: import("ws").WebSocket | null, ws: import("ws").WebSocket, send: (data: string | Buffer) => Promise<void>): void;
|
|
162
|
-
/**
|
|
163
|
-
* Set up handlers on the bidi socket connection to the client
|
|
164
|
-
*
|
|
165
|
-
* @param {import('ws').WebSocket} ws - the websocket connection to/from the client
|
|
166
|
-
* @param {import('ws').WebSocket | null} proxyClient - the websocket connection to/from the
|
|
167
|
-
* upstream socket (the one we're proxying to/from, if we're proxying)
|
|
168
|
-
* @param {(data: string | Buffer) => Promise<void>} send - a method used to send data to the
|
|
169
|
-
* client
|
|
170
|
-
* @param {((data: string | Buffer) => Promise<void>) | null} sendToProxy - a method used to send data to the
|
|
171
|
-
* upstream socket
|
|
172
|
-
* @param {import('@appium/types').ExternalDriver | AppiumDriver} bidiHandlerDriver - the driver
|
|
173
|
-
* handling the bidi commands
|
|
174
|
-
* @param {(err: Error) => void} logSocketErr - a special prefixed logger
|
|
175
|
-
*/
|
|
176
|
-
initBidiSocketHandlers(ws: import("ws").WebSocket, proxyClient: import("ws").WebSocket | null, send: (data: string | Buffer) => Promise<void>, sendToProxy: ((data: string | Buffer) => Promise<void>) | null, bidiHandlerDriver: import("@appium/types").ExternalDriver | AppiumDriver, logSocketErr: (err: Error) => void): void;
|
|
177
|
-
/**
|
|
178
|
-
* Set up bidi event listeners
|
|
179
|
-
*
|
|
180
|
-
* @param {import('ws').WebSocket} ws - the websocket connection to/from the client
|
|
181
|
-
* @param {import('@appium/types').ExternalDriver | AppiumDriver} bidiHandlerDriver - the driver
|
|
182
|
-
* handling the bidi commands
|
|
183
|
-
* @param {(data: string | Buffer) => Promise<void>} send - a method used to send data to the
|
|
184
|
-
* client
|
|
185
|
-
*/
|
|
186
|
-
initBidiEventListeners(ws: import("ws").WebSocket, bidiHandlerDriver: import("@appium/types").ExternalDriver | AppiumDriver, send: (data: string | Buffer) => Promise<void>): void;
|
|
187
|
-
/**
|
|
188
|
-
* @param {Buffer} data
|
|
189
|
-
* @param {ExternalDriver | AppiumDriver} driver
|
|
190
|
-
*/
|
|
191
|
-
onBidiMessage(data: Buffer, driver: ExternalDriver | AppiumDriver): Promise<any>;
|
|
192
|
-
/**
|
|
193
|
-
* Log a bidi server error
|
|
194
|
-
* @param {Error} err
|
|
195
|
-
*/
|
|
196
|
-
onBidiServerError(err: Error): void;
|
|
197
134
|
/**
|
|
198
135
|
* Create a new session
|
|
199
136
|
* @param {W3CAppiumDriverCaps} jsonwpCaps JSONWP formatted desired capabilities
|
|
@@ -289,6 +226,9 @@ export class AppiumDriver extends DriverCore<{
|
|
|
289
226
|
}>;
|
|
290
227
|
proxyActive(sessionId: any): boolean;
|
|
291
228
|
canProxy(sessionId: any): boolean;
|
|
229
|
+
onBidiConnection: typeof bidiHelpers.onBidiConnection;
|
|
230
|
+
onBidiMessage: typeof bidiHelpers.onBidiMessage;
|
|
231
|
+
onBidiServerError: typeof bidiHelpers.onBidiServerError;
|
|
292
232
|
}
|
|
293
233
|
declare namespace desiredCapabilityConstraints {
|
|
294
234
|
namespace automationName {
|
|
@@ -303,6 +243,6 @@ declare namespace desiredCapabilityConstraints {
|
|
|
303
243
|
}
|
|
304
244
|
}
|
|
305
245
|
import { DriverCore } from '@appium/base-driver';
|
|
306
|
-
import
|
|
246
|
+
import * as bidiHelpers from './bidi';
|
|
307
247
|
export {};
|
|
308
248
|
//# sourceMappingURL=appium.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appium.d.ts","sourceRoot":"","sources":["../../lib/appium.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"appium.d.ts","sourceRoot":"","sources":["../../lib/appium.js"],"names":[],"mappings":"AAk7BA;;;GAGG;AACH;IAME,cAOC;IAZD;;OAEG;IACH,MAFU,QAAQ,CAAC,MAAM,CAAC,CAEgB;CAU3C;yBAKY,OAAO,eAAe,EAAE,UAAU;yBAClC,OAAO,eAAe,EAAE,UAAU;0BACl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8BAHY,MAAM,OAAA,SAejB;IAED;;;;;;;;;OASG;IACH,wBAJW,MAAM,cACL,MAAM,OAAA,SASjB;IAED;;;OAGG;IACH,yBAFa,MAAM,EAAE,CAWpB;IAED;;;;;OAKG;IACH,oBAJW,MAAM,WACF,GAAG,EAAA,GACL,OAAO,CAAC;QAAC,KAAK,EAAE,GAAG,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAC,GAAG,OAAO,WAAW,EAAE,eAAe,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,CAAC,CA2J1I;IAED;;;;;;;YAyBC;IAED;;;aAoBC;IAED;;;;;;;OAwBC;IAED,qCAGC;IAYD,kCAGC;IAED,sDAAgD;IAChD,gDAA0C;IAC1C,wDAAkD;CACnD;;;;;;;;;;;;;2BA95BM,qBAAqB;6BAWC,QAAQ"}
|
package/build/lib/appium.js
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
exports.AppiumDriver = exports.NoDriverProxyCommandError = void 0;
|
|
7
|
-
/* eslint-disable no-unused-vars */
|
|
8
40
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
-
const bluebird_1 = __importDefault(require("bluebird"));
|
|
10
41
|
const config_1 = require("./config");
|
|
11
42
|
const base_driver_1 = require("@appium/base-driver");
|
|
12
43
|
const async_lock_1 = __importDefault(require("async-lock"));
|
|
@@ -14,11 +45,7 @@ const utils_1 = require("./utils");
|
|
|
14
45
|
const support_1 = require("@appium/support");
|
|
15
46
|
const schema_1 = require("./schema");
|
|
16
47
|
const constants_1 = require("./constants");
|
|
17
|
-
const
|
|
18
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
19
|
-
const MIN_WS_CODE_VAL = 1000;
|
|
20
|
-
const MAX_WS_CODE_VAL = 1015;
|
|
21
|
-
const WS_FALLBACK_CODE = 1011; // server encountered an error while fulfilling request
|
|
48
|
+
const bidiHelpers = __importStar(require("./bidi"));
|
|
22
49
|
const desiredCapabilityConstraints = /** @type {const} */ ({
|
|
23
50
|
automationName: {
|
|
24
51
|
presence: true,
|
|
@@ -47,6 +74,9 @@ class AppiumDriver extends base_driver_1.DriverCore {
|
|
|
47
74
|
process.env.APPIUM_TMP_DIR = opts.tmpDir;
|
|
48
75
|
}
|
|
49
76
|
super(opts);
|
|
77
|
+
this.onBidiConnection = bidiHelpers.onBidiConnection;
|
|
78
|
+
this.onBidiMessage = bidiHelpers.onBidiMessage;
|
|
79
|
+
this.onBidiServerError = bidiHelpers.onBidiServerError;
|
|
50
80
|
this.args = { ...opts };
|
|
51
81
|
this.sessions = {};
|
|
52
82
|
this.pendingDrivers = {};
|
|
@@ -92,7 +122,6 @@ class AppiumDriver extends base_driver_1.DriverCore {
|
|
|
92
122
|
driverForSession(sessionId) {
|
|
93
123
|
return this.sessions[sessionId];
|
|
94
124
|
}
|
|
95
|
-
// eslint-disable-next-line require-await
|
|
96
125
|
async getStatus() {
|
|
97
126
|
// https://www.w3.org/TR/webdriver/#dfn-status
|
|
98
127
|
const statusObj = this._isShuttingDown
|
|
@@ -166,294 +195,6 @@ class AppiumDriver extends base_driver_1.DriverCore {
|
|
|
166
195
|
}
|
|
167
196
|
}
|
|
168
197
|
}
|
|
169
|
-
/**
|
|
170
|
-
* Initialize a new bidi connection and set up handlers
|
|
171
|
-
* @param {import('ws').WebSocket} ws The websocket connection object
|
|
172
|
-
* @param {import('http').IncomingMessage} req The connection pathname, which might include the session id
|
|
173
|
-
*/
|
|
174
|
-
onBidiConnection(ws, req) {
|
|
175
|
-
// TODO put bidi-related functionality into a mixin/helper class
|
|
176
|
-
// wrap all of the handler logic with exception handling so if something blows up we can log
|
|
177
|
-
// and close the websocket
|
|
178
|
-
try {
|
|
179
|
-
const { bidiHandlerDriver, proxyClient, send, sendToProxy, logSocketErr } = this.initBidiSocket(ws, req);
|
|
180
|
-
this.initBidiSocketHandlers(ws, proxyClient, send, sendToProxy, bidiHandlerDriver, logSocketErr);
|
|
181
|
-
this.initBidiProxyHandlers(proxyClient, ws, send);
|
|
182
|
-
this.initBidiEventListeners(ws, bidiHandlerDriver, send);
|
|
183
|
-
}
|
|
184
|
-
catch (err) {
|
|
185
|
-
this.log.error(err);
|
|
186
|
-
try {
|
|
187
|
-
ws.close();
|
|
188
|
-
}
|
|
189
|
-
catch (ign) { }
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Initialize a new bidi connection
|
|
194
|
-
* @param {import('ws').WebSocket} ws The websocket connection object
|
|
195
|
-
* @param {import('http').IncomingMessage} req The connection pathname, which might include the session id
|
|
196
|
-
*/
|
|
197
|
-
initBidiSocket(ws, req) {
|
|
198
|
-
let outOfBandErrorPrefix = '';
|
|
199
|
-
const pathname = req.url;
|
|
200
|
-
if (!pathname) {
|
|
201
|
-
throw new Error('Invalid connection request: pathname missing from request');
|
|
202
|
-
}
|
|
203
|
-
const bidiSessionRe = new RegExp(`${constants_1.BIDI_BASE_PATH}/([^/]+)$`);
|
|
204
|
-
const bidiNoSessionRe = new RegExp(`${constants_1.BIDI_BASE_PATH}/?$`);
|
|
205
|
-
const sessionMatch = bidiSessionRe.exec(pathname);
|
|
206
|
-
const noSessionMatch = bidiNoSessionRe.exec(pathname);
|
|
207
|
-
if (!sessionMatch && !noSessionMatch) {
|
|
208
|
-
throw new Error(`Got websocket connection for path ${pathname} but didn't know what to do with it. ` +
|
|
209
|
-
`Ignoring and will close the connection`);
|
|
210
|
-
}
|
|
211
|
-
// Let's figure out which driver is going to handle this socket connection. It's either going
|
|
212
|
-
// to be a driver matching a session id appended to the bidi base path, or this umbrella driver
|
|
213
|
-
// (if no session id is included in the bidi connection request)
|
|
214
|
-
/** @type {import('@appium/types').ExternalDriver | AppiumDriver} */
|
|
215
|
-
let bidiHandlerDriver;
|
|
216
|
-
/** @type {import('ws').WebSocket | null} */
|
|
217
|
-
let proxyClient = null;
|
|
218
|
-
if (sessionMatch) {
|
|
219
|
-
// If we found a session id, see if it matches an active session
|
|
220
|
-
const sessionId = sessionMatch[1];
|
|
221
|
-
bidiHandlerDriver = this.sessions[sessionId];
|
|
222
|
-
if (!bidiHandlerDriver) {
|
|
223
|
-
// The session ID sent in doesn't match an active session; just ignore this socket
|
|
224
|
-
// connection in that case
|
|
225
|
-
throw new Error(`Got bidi connection request for session with id ${sessionId} which is closed ` +
|
|
226
|
-
`or does not exist. Closing the socket connection.`);
|
|
227
|
-
}
|
|
228
|
-
const driverName = bidiHandlerDriver.constructor.name;
|
|
229
|
-
outOfBandErrorPrefix = `[session ${sessionId}] `;
|
|
230
|
-
this.log.info(`Bidi websocket connection made for session ${sessionId}`);
|
|
231
|
-
// store this socket connection for later removal on session deletion. theoretically there
|
|
232
|
-
// can be multiple sockets per session
|
|
233
|
-
if (!this.bidiSockets[sessionId]) {
|
|
234
|
-
this.bidiSockets[sessionId] = [];
|
|
235
|
-
}
|
|
236
|
-
this.bidiSockets[sessionId].push(ws);
|
|
237
|
-
const bidiProxyUrl = bidiHandlerDriver.bidiProxyUrl;
|
|
238
|
-
if (bidiProxyUrl) {
|
|
239
|
-
try {
|
|
240
|
-
new URL(bidiProxyUrl);
|
|
241
|
-
}
|
|
242
|
-
catch (ign) {
|
|
243
|
-
throw new Error(`Got request for ${driverName} to proxy bidi connections to upstream socket with ` +
|
|
244
|
-
`url ${bidiProxyUrl}, but this was not a valid url`);
|
|
245
|
-
}
|
|
246
|
-
this.log.info(`Bidi connection for ${driverName} will be proxied to ${bidiProxyUrl}`);
|
|
247
|
-
proxyClient = new ws_1.default(bidiProxyUrl);
|
|
248
|
-
this.bidiProxyClients[sessionId] = proxyClient;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
this.log.info('Bidi websocket connection made to main server');
|
|
253
|
-
// no need to store the socket connection if it's to the main server since it will just
|
|
254
|
-
// stay open as long as the server itself is and will close when the server closes.
|
|
255
|
-
bidiHandlerDriver = this; // eslint-disable-line @typescript-eslint/no-this-alias
|
|
256
|
-
}
|
|
257
|
-
const logSocketErr = (/** @type {Error} */ err) => this.log.error(`${outOfBandErrorPrefix}${err}`);
|
|
258
|
-
// This is a function which wraps the 'send' method on a web socket for two reasons:
|
|
259
|
-
// 1. Make it async-await friendly
|
|
260
|
-
// 2. Do some logging if there's a send error
|
|
261
|
-
const sendFactory = (/** @type {import('ws').WebSocket} */ socket) => {
|
|
262
|
-
const socketSend = bluebird_1.default.promisify(socket.send, { context: socket });
|
|
263
|
-
return async (/** @type {string|Buffer} */ data) => {
|
|
264
|
-
try {
|
|
265
|
-
await socketSend(data);
|
|
266
|
-
}
|
|
267
|
-
catch (err) {
|
|
268
|
-
logSocketErr(err);
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
};
|
|
272
|
-
// Construct our send method for sending messages to the client
|
|
273
|
-
const send = sendFactory(ws);
|
|
274
|
-
// Construct a conditional send method for proxying messages from the client to an upstream
|
|
275
|
-
// bidi socket server (e.g. on a browser)
|
|
276
|
-
const sendToProxy = proxyClient ? sendFactory(proxyClient) : null;
|
|
277
|
-
return { bidiHandlerDriver, proxyClient, send, sendToProxy, logSocketErr };
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Set up handlers on upstream bidi socket we are proxying to/from
|
|
281
|
-
*
|
|
282
|
-
* @param {import('ws').WebSocket | null} proxyClient - the websocket connection to/from the
|
|
283
|
-
* upstream socket (the one we're proxying to/from)
|
|
284
|
-
* @param {import('ws').WebSocket} ws - the websocket connection to/from the client
|
|
285
|
-
* @param {(data: string | Buffer) => Promise<void>} send - a method used to send data to the
|
|
286
|
-
* client
|
|
287
|
-
*/
|
|
288
|
-
initBidiProxyHandlers(proxyClient, ws, send) {
|
|
289
|
-
// Set up handlers for events that might come from the upstream bidi socket connection if
|
|
290
|
-
// we're in proxy mode
|
|
291
|
-
if (proxyClient) {
|
|
292
|
-
// Here we're receiving a message from the upstream socket server. We want to pass it on to
|
|
293
|
-
// the client
|
|
294
|
-
proxyClient.on('message', async (/** @type {Buffer|string} */ data) => {
|
|
295
|
-
const logData = lodash_1.default.truncate(data.toString('utf8'), { length: base_driver_1.MAX_LOG_BODY_LENGTH });
|
|
296
|
-
this.log.debug(`<-- BIDI Received data from proxied bidi socket, sending to client. Data: ${logData}`);
|
|
297
|
-
await send(data);
|
|
298
|
-
});
|
|
299
|
-
// If the upstream socket server closes the connection, should close the connection to the
|
|
300
|
-
// client as well
|
|
301
|
-
proxyClient.on('close', (code, reason) => {
|
|
302
|
-
this.log.debug(`Upstream bidi socket closed connection (code ${code}, reason: '${reason}'). ` +
|
|
303
|
-
`Closing proxy connection to client`);
|
|
304
|
-
if (!lodash_1.default.isNumber(code)) {
|
|
305
|
-
code = parseInt(code, 10);
|
|
306
|
-
}
|
|
307
|
-
if (lodash_1.default.isNaN(code) || code < MIN_WS_CODE_VAL || code > MAX_WS_CODE_VAL) {
|
|
308
|
-
this.log.warn(`Received code ${code} from upstream socket, but this is not a valid ` +
|
|
309
|
-
`websocket code. Rewriting to ${WS_FALLBACK_CODE} for ws compatibility`);
|
|
310
|
-
code = WS_FALLBACK_CODE;
|
|
311
|
-
}
|
|
312
|
-
ws.close(code, reason);
|
|
313
|
-
});
|
|
314
|
-
proxyClient.on('error', (err) => {
|
|
315
|
-
this.log.error(`Got error on upstream bidi socket connection: ${err}`);
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Set up handlers on the bidi socket connection to the client
|
|
321
|
-
*
|
|
322
|
-
* @param {import('ws').WebSocket} ws - the websocket connection to/from the client
|
|
323
|
-
* @param {import('ws').WebSocket | null} proxyClient - the websocket connection to/from the
|
|
324
|
-
* upstream socket (the one we're proxying to/from, if we're proxying)
|
|
325
|
-
* @param {(data: string | Buffer) => Promise<void>} send - a method used to send data to the
|
|
326
|
-
* client
|
|
327
|
-
* @param {((data: string | Buffer) => Promise<void>) | null} sendToProxy - a method used to send data to the
|
|
328
|
-
* upstream socket
|
|
329
|
-
* @param {import('@appium/types').ExternalDriver | AppiumDriver} bidiHandlerDriver - the driver
|
|
330
|
-
* handling the bidi commands
|
|
331
|
-
* @param {(err: Error) => void} logSocketErr - a special prefixed logger
|
|
332
|
-
*/
|
|
333
|
-
initBidiSocketHandlers(ws, proxyClient, send, sendToProxy, bidiHandlerDriver, logSocketErr) {
|
|
334
|
-
ws.on('error', (err) => {
|
|
335
|
-
// Can't do much with random errors on the connection other than log them
|
|
336
|
-
logSocketErr(err);
|
|
337
|
-
});
|
|
338
|
-
ws.on('open', () => {
|
|
339
|
-
this.log.info('Bidi websocket connection is now open');
|
|
340
|
-
});
|
|
341
|
-
// Now set up handlers for the various events that might happen on the websocket connection
|
|
342
|
-
// coming from the client
|
|
343
|
-
// First is incoming messages from the client
|
|
344
|
-
ws.on('message', async (/** @type {Buffer} */ data) => {
|
|
345
|
-
if (proxyClient) {
|
|
346
|
-
const logData = lodash_1.default.truncate(data.toString('utf8'), { length: base_driver_1.MAX_LOG_BODY_LENGTH });
|
|
347
|
-
this.log.debug(`--> BIDI Received data from client, sending to upstream bidi socket. Data: ${logData}`);
|
|
348
|
-
// if we're meant to proxy to an upstream bidi socket, just do that
|
|
349
|
-
// @ts-ignore sendToProxy is never null if proxyClient is truthy, but ts doesn't know
|
|
350
|
-
// that
|
|
351
|
-
await sendToProxy(data.toString('utf8'));
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
const res = await this.onBidiMessage(data, bidiHandlerDriver);
|
|
355
|
-
await send(JSON.stringify(res));
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
// Next consider if the client closes the socket connection on us
|
|
359
|
-
ws.on('close', (code, reason) => {
|
|
360
|
-
// Not sure if we need to do anything here if the client closes the websocket connection.
|
|
361
|
-
// Probably if a session was started via the socket, and the socket closes, we should end the
|
|
362
|
-
// associated session to free up resources. But otherwise, for sockets attached to existing
|
|
363
|
-
// sessions, doing nothing is probably right.
|
|
364
|
-
this.log.debug(`Bidi socket connection closed (code ${code}, reason: '${reason}')`);
|
|
365
|
-
// If we're proxying, might as well close the upstream connection and clean it up
|
|
366
|
-
if (proxyClient) {
|
|
367
|
-
this.log.debug('Also closing bidi proxy socket connection');
|
|
368
|
-
proxyClient.close(code, reason);
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Set up bidi event listeners
|
|
374
|
-
*
|
|
375
|
-
* @param {import('ws').WebSocket} ws - the websocket connection to/from the client
|
|
376
|
-
* @param {import('@appium/types').ExternalDriver | AppiumDriver} bidiHandlerDriver - the driver
|
|
377
|
-
* handling the bidi commands
|
|
378
|
-
* @param {(data: string | Buffer) => Promise<void>} send - a method used to send data to the
|
|
379
|
-
* client
|
|
380
|
-
*/
|
|
381
|
-
initBidiEventListeners(ws, bidiHandlerDriver, send) {
|
|
382
|
-
// If the driver emits a bidi event that should maybe get sent to the client, check to make
|
|
383
|
-
// sure the client is subscribed and then pass it on
|
|
384
|
-
let eventListener = async ({ context, method, params }) => {
|
|
385
|
-
// if the driver didn't specify a context, use the empty context
|
|
386
|
-
if (!context) {
|
|
387
|
-
context = '';
|
|
388
|
-
}
|
|
389
|
-
if (!method || !params) {
|
|
390
|
-
throw new Error(`Driver emitted a bidi event that was malformed. Require method and params keys ` +
|
|
391
|
-
`(with optional context). But instead received: ${JSON.stringify({
|
|
392
|
-
context,
|
|
393
|
-
method,
|
|
394
|
-
params,
|
|
395
|
-
})}`);
|
|
396
|
-
}
|
|
397
|
-
if (ws.readyState !== ws_1.default.OPEN) {
|
|
398
|
-
// if the websocket is not still 'open', then we can ignore sending these events
|
|
399
|
-
if (ws.readyState > ws_1.default.OPEN) {
|
|
400
|
-
// if the websocket is closed or closing, we can remove this listener as well to avoid
|
|
401
|
-
// leaks
|
|
402
|
-
bidiHandlerDriver.eventEmitter.removeListener(constants_1.BIDI_EVENT_NAME, eventListener);
|
|
403
|
-
}
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
if (bidiHandlerDriver.bidiEventSubs[method]?.includes(context)) {
|
|
407
|
-
this.log.info(`<-- BIDI EVENT ${method} (context: '${context}', params: ${JSON.stringify(params)})`);
|
|
408
|
-
// now we can send the event onto the socket
|
|
409
|
-
const ev = { type: 'event', context, method, params };
|
|
410
|
-
await send(JSON.stringify(ev));
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
bidiHandlerDriver.eventEmitter.on(constants_1.BIDI_EVENT_NAME, eventListener);
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* @param {Buffer} data
|
|
417
|
-
* @param {ExternalDriver | AppiumDriver} driver
|
|
418
|
-
*/
|
|
419
|
-
async onBidiMessage(data, driver) {
|
|
420
|
-
let resMessage, id, method, params;
|
|
421
|
-
const dataTruncated = lodash_1.default.truncate(data.toString(), { length: 100 });
|
|
422
|
-
try {
|
|
423
|
-
try {
|
|
424
|
-
({ id, method, params } = JSON.parse(data.toString('utf8')));
|
|
425
|
-
}
|
|
426
|
-
catch (err) {
|
|
427
|
-
throw new base_driver_1.errors.InvalidArgumentError(`Could not parse Bidi command '${dataTruncated}': ${err.message}`);
|
|
428
|
-
}
|
|
429
|
-
driver.log.info(`--> BIDI message #${id}`);
|
|
430
|
-
if (!method) {
|
|
431
|
-
throw new base_driver_1.errors.InvalidArgumentError(`Missing method for BiDi operation in '${dataTruncated}'`);
|
|
432
|
-
}
|
|
433
|
-
if (!params) {
|
|
434
|
-
throw new base_driver_1.errors.InvalidArgumentError(`Missing params for BiDi operation in '${dataTruncated}`);
|
|
435
|
-
}
|
|
436
|
-
const result = await driver.executeBidiCommand(method, params);
|
|
437
|
-
// https://w3c.github.io/webdriver-bidi/#protocol-definition
|
|
438
|
-
resMessage = {
|
|
439
|
-
id,
|
|
440
|
-
type: 'success',
|
|
441
|
-
result,
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
catch (err) {
|
|
445
|
-
resMessage = err.bidiErrObject(id);
|
|
446
|
-
}
|
|
447
|
-
driver.log.info(`<-- BIDI message #${id}`);
|
|
448
|
-
return resMessage;
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* Log a bidi server error
|
|
452
|
-
* @param {Error} err
|
|
453
|
-
*/
|
|
454
|
-
onBidiServerError(err) {
|
|
455
|
-
this.log.error(`Error from bidi websocket server: ${err}`);
|
|
456
|
-
}
|
|
457
198
|
/**
|
|
458
199
|
* Create a new session
|
|
459
200
|
* @param {W3CAppiumDriverCaps} jsonwpCaps JSONWP formatted desired capabilities
|
|
@@ -520,6 +261,11 @@ class AppiumDriver extends base_driver_1.DriverCore {
|
|
|
520
261
|
`enabled unless explicitly disabled by --deny-insecure`);
|
|
521
262
|
driverInstance.relaxedSecurityEnabled = true;
|
|
522
263
|
}
|
|
264
|
+
// We also want to assign any new Bidi Commands that the driver has specified, including all
|
|
265
|
+
// the standard bidi commands
|
|
266
|
+
if (lodash_1.default.isFunction(driverInstance.updateBidiCommands)) {
|
|
267
|
+
driverInstance.updateBidiCommands(InnerDriver.newBidiCommands ?? {});
|
|
268
|
+
}
|
|
523
269
|
if (!lodash_1.default.isEmpty(this.args.denyInsecure)) {
|
|
524
270
|
this.log.info('Explicitly preventing use of insecure features:');
|
|
525
271
|
this.args.denyInsecure.map((a) => this.log.info(` ${a}`));
|
|
@@ -587,7 +333,7 @@ class AppiumDriver extends base_driver_1.DriverCore {
|
|
|
587
333
|
if (dCaps.webSocketUrl && driverInstance.doesSupportBidi) {
|
|
588
334
|
const { address, port, basePath } = this.args;
|
|
589
335
|
const scheme = `ws${this.server.isSecure() ? 's' : ''}`;
|
|
590
|
-
const host = determineBiDiHost(address);
|
|
336
|
+
const host = bidiHelpers.determineBiDiHost(address);
|
|
591
337
|
const bidiUrl = `${scheme}://${host}:${port}${basePath}${constants_1.BIDI_BASE_PATH}/${innerSessionId}`;
|
|
592
338
|
this.log.info(`Upstream driver responded with webSocketUrl ${dCaps.webSocketUrl}, will rewrite to ` +
|
|
593
339
|
`${bidiUrl} for response to client`);
|
|
@@ -870,7 +616,9 @@ class AppiumDriver extends base_driver_1.DriverCore {
|
|
|
870
616
|
// if we're running with plugins, make sure we log that the default behavior is actually
|
|
871
617
|
// happening so we can tell when the plugin call chain is unwrapping to the default behavior
|
|
872
618
|
// if that's what happens
|
|
873
|
-
plugins.length
|
|
619
|
+
if (plugins.length) {
|
|
620
|
+
this.log.info(`Executing default handling behavior for command '${cmd}'`);
|
|
621
|
+
}
|
|
874
622
|
// if we make it here, we know that the default behavior is handled
|
|
875
623
|
cmdHandledBy.default = true;
|
|
876
624
|
if (reqForProxy) {
|
|
@@ -931,8 +679,9 @@ class AppiumDriver extends base_driver_1.DriverCore {
|
|
|
931
679
|
return res;
|
|
932
680
|
}
|
|
933
681
|
wrapCommandWithPlugins({ driver, cmd, args, next, cmdHandledBy, plugins }) {
|
|
934
|
-
plugins.length
|
|
682
|
+
if (plugins.length) {
|
|
935
683
|
this.log.info(`Plugins which can handle cmd '${cmd}': ${plugins.map((p) => p.name)}`);
|
|
684
|
+
}
|
|
936
685
|
// now we can go through each plugin and wrap `next` around its own handler, passing the *old*
|
|
937
686
|
// next in so that it can call it if it wants to
|
|
938
687
|
for (const plugin of plugins) {
|
|
@@ -1019,23 +768,6 @@ exports.AppiumDriver = AppiumDriver;
|
|
|
1019
768
|
function isAppiumDriverCommand(cmd) {
|
|
1020
769
|
return !(0, base_driver_1.isSessionCommand)(cmd) || cmd === base_driver_1.DELETE_SESSION_COMMAND;
|
|
1021
770
|
}
|
|
1022
|
-
/**
|
|
1023
|
-
* Clients cannot use broadcast addresses, like 0.0.0.0 or ::
|
|
1024
|
-
* to create connections. Thus we prefer a hostname if such
|
|
1025
|
-
* address is provided or the actual address of a non-local interface,
|
|
1026
|
-
* in case the host only has one such interface.
|
|
1027
|
-
*
|
|
1028
|
-
* @param {string} address
|
|
1029
|
-
* @returns {string}
|
|
1030
|
-
*/
|
|
1031
|
-
function determineBiDiHost(address) {
|
|
1032
|
-
if (!(0, utils_1.isBroadcastIp)(address)) {
|
|
1033
|
-
return address;
|
|
1034
|
-
}
|
|
1035
|
-
const nonLocalInterfaces = (0, utils_1.fetchInterfaces)(address === utils_1.V4_BROADCAST_IP ? 4 : 6)
|
|
1036
|
-
.filter((iface) => !iface.internal);
|
|
1037
|
-
return nonLocalInterfaces.length === 1 ? nonLocalInterfaces[0].address : node_os_1.default.hostname();
|
|
1038
|
-
}
|
|
1039
771
|
/**
|
|
1040
772
|
* Thrown when Appium tried to proxy a command using a driver's `proxyCommand` method but the
|
|
1041
773
|
* method did not exist
|