appium 2.2.3 → 2.4.0
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 +131 -158
- package/build/lib/appium.d.ts +76 -4
- package/build/lib/appium.d.ts.map +1 -1
- package/build/lib/appium.js +327 -1
- package/build/lib/appium.js.map +1 -1
- package/build/lib/cli/args.d.ts.map +1 -1
- package/build/lib/cli/args.js +24 -2
- package/build/lib/cli/args.js.map +1 -1
- package/build/lib/cli/driver-command.d.ts +16 -0
- package/build/lib/cli/driver-command.d.ts.map +1 -1
- package/build/lib/cli/driver-command.js +16 -0
- package/build/lib/cli/driver-command.js.map +1 -1
- package/build/lib/cli/extension-command.d.ts +26 -2
- package/build/lib/cli/extension-command.d.ts.map +1 -1
- package/build/lib/cli/extension-command.js +135 -4
- 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 +11 -7
- package/build/lib/cli/parser.js.map +1 -1
- package/build/lib/cli/plugin-command.d.ts +16 -0
- package/build/lib/cli/plugin-command.d.ts.map +1 -1
- package/build/lib/cli/plugin-command.js +16 -0
- package/build/lib/cli/plugin-command.js.map +1 -1
- package/build/lib/cli/utils.d.ts.map +1 -1
- package/build/lib/cli/utils.js +3 -4
- package/build/lib/cli/utils.js.map +1 -1
- package/build/lib/config-file.d.ts +1 -1
- package/build/lib/config.d.ts +8 -7
- package/build/lib/config.d.ts.map +1 -1
- package/build/lib/config.js +54 -64
- package/build/lib/config.js.map +1 -1
- package/build/lib/constants.d.ts +10 -0
- package/build/lib/constants.d.ts.map +1 -1
- package/build/lib/constants.js +11 -1
- package/build/lib/constants.js.map +1 -1
- package/build/lib/doctor/doctor.d.ts +55 -0
- package/build/lib/doctor/doctor.d.ts.map +1 -0
- package/build/lib/doctor/doctor.js +201 -0
- package/build/lib/doctor/doctor.js.map +1 -0
- package/build/lib/extension/driver-config.d.ts +2 -2
- package/build/lib/extension/driver-config.d.ts.map +1 -1
- package/build/lib/extension/driver-config.js +4 -4
- package/build/lib/extension/driver-config.js.map +1 -1
- package/build/lib/extension/extension-config.d.ts +10 -3
- package/build/lib/extension/extension-config.d.ts.map +1 -1
- package/build/lib/extension/extension-config.js +32 -14
- package/build/lib/extension/extension-config.js.map +1 -1
- package/build/lib/extension/index.d.ts +6 -4
- package/build/lib/extension/index.d.ts.map +1 -1
- package/build/lib/extension/index.js +74 -32
- package/build/lib/extension/index.js.map +1 -1
- package/build/lib/extension/manifest.js +1 -1
- package/build/lib/extension/manifest.js.map +1 -1
- package/build/lib/extension/plugin-config.js +1 -1
- package/build/lib/extension/plugin-config.js.map +1 -1
- package/build/lib/grid-register.d.ts.map +1 -1
- package/build/lib/grid-register.js +1 -2
- package/build/lib/grid-register.js.map +1 -1
- package/build/lib/main.d.ts +4 -0
- package/build/lib/main.d.ts.map +1 -1
- package/build/lib/main.js +31 -52
- package/build/lib/main.js.map +1 -1
- package/build/lib/schema/schema.d.ts +5 -0
- package/build/lib/schema/schema.d.ts.map +1 -1
- package/build/lib/schema/schema.js +7 -7
- package/build/lib/schema/schema.js.map +1 -1
- package/build/lib/utils.d.ts +3 -0
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js +2 -1
- package/build/lib/utils.js.map +1 -1
- package/build/types/cli.d.ts +1 -1
- package/build/types/cli.d.ts.map +1 -1
- package/lib/appium.js +388 -2
- package/lib/cli/args.js +27 -2
- package/lib/cli/driver-command.js +18 -0
- package/lib/cli/extension-command.js +160 -9
- package/lib/cli/parser.js +22 -8
- package/lib/cli/plugin-command.js +18 -0
- package/lib/cli/utils.js +5 -7
- package/lib/config.js +46 -65
- package/lib/constants.js +12 -0
- package/lib/doctor/doctor.js +209 -0
- package/lib/extension/driver-config.js +3 -3
- package/lib/extension/extension-config.js +33 -15
- package/lib/extension/index.js +80 -43
- package/lib/grid-register.js +1 -2
- package/lib/main.js +42 -61
- package/lib/utils.js +2 -1
- package/package.json +15 -18
- package/types/cli.ts +1 -1
package/lib/appium.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
2
|
import _ from 'lodash';
|
|
3
|
+
import B from 'bluebird';
|
|
3
4
|
import {getBuildInfo, updateBuildInfo, APPIUM_VER} from './config';
|
|
4
5
|
import {
|
|
5
6
|
BaseDriver,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
CREATE_SESSION_COMMAND,
|
|
10
11
|
DELETE_SESSION_COMMAND,
|
|
11
12
|
GET_STATUS_COMMAND,
|
|
13
|
+
MAX_LOG_BODY_LENGTH,
|
|
12
14
|
promoteAppiumOptions,
|
|
13
15
|
promoteAppiumOptionsForObject,
|
|
14
16
|
} from '@appium/base-driver';
|
|
@@ -16,7 +18,8 @@ import AsyncLock from 'async-lock';
|
|
|
16
18
|
import {parseCapsForInnerDriver, pullSettings, makeNonW3cCapsError} from './utils';
|
|
17
19
|
import {util, node, logger} from '@appium/support';
|
|
18
20
|
import {getDefaultsForExtension} from './schema';
|
|
19
|
-
import {DRIVER_TYPE} from './constants';
|
|
21
|
+
import {DRIVER_TYPE, BIDI_BASE_PATH, BIDI_EVENT_NAME} from './constants';
|
|
22
|
+
import WebSocket from 'ws';
|
|
20
23
|
|
|
21
24
|
const desiredCapabilityConstraints = /** @type {const} */ ({
|
|
22
25
|
automationName: {
|
|
@@ -83,6 +86,12 @@ class AppiumDriver extends DriverCore {
|
|
|
83
86
|
/** @type {AppiumServer} */
|
|
84
87
|
server;
|
|
85
88
|
|
|
89
|
+
/** @type {Record<string, import('ws').WebSocket[]>} */
|
|
90
|
+
bidiSockets;
|
|
91
|
+
|
|
92
|
+
/** @type {Record<string, import('ws').WebSocket>} */
|
|
93
|
+
bidiProxyClients;
|
|
94
|
+
|
|
86
95
|
/**
|
|
87
96
|
* @type {AppiumDriverConstraints}
|
|
88
97
|
* @readonly
|
|
@@ -113,6 +122,8 @@ class AppiumDriver extends DriverCore {
|
|
|
113
122
|
this.pluginClasses = new Map();
|
|
114
123
|
this.sessionPlugins = {};
|
|
115
124
|
this.sessionlessPlugins = [];
|
|
125
|
+
this.bidiSockets = {};
|
|
126
|
+
this.bidiProxyClients = {};
|
|
116
127
|
this.desiredCapConstraints = desiredCapabilityConstraints;
|
|
117
128
|
this._isShuttingDown = false;
|
|
118
129
|
|
|
@@ -241,6 +252,337 @@ class AppiumDriver extends DriverCore {
|
|
|
241
252
|
}
|
|
242
253
|
}
|
|
243
254
|
|
|
255
|
+
/**
|
|
256
|
+
* Initialize a new bidi connection and set up handlers
|
|
257
|
+
* @param {import('ws').WebSocket} ws The websocket connection object
|
|
258
|
+
* @param {import('http').IncomingMessage} req The connection pathname, which might include the session id
|
|
259
|
+
*/
|
|
260
|
+
onBidiConnection(ws, req) {
|
|
261
|
+
// TODO put bidi-related functionality into a mixin/helper class
|
|
262
|
+
// wrap all of the handler logic with exception handling so if something blows up we can log
|
|
263
|
+
// and close the websocket
|
|
264
|
+
try {
|
|
265
|
+
const {bidiHandlerDriver, proxyClient, send, sendToProxy, logSocketErr} = this.initBidiSocket(
|
|
266
|
+
ws,
|
|
267
|
+
req,
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
this.initBidiSocketHandlers(
|
|
271
|
+
ws,
|
|
272
|
+
proxyClient,
|
|
273
|
+
send,
|
|
274
|
+
sendToProxy,
|
|
275
|
+
bidiHandlerDriver,
|
|
276
|
+
logSocketErr,
|
|
277
|
+
);
|
|
278
|
+
this.initBidiProxyHandlers(proxyClient, ws, send);
|
|
279
|
+
this.initBidiEventListeners(ws, bidiHandlerDriver, send);
|
|
280
|
+
} catch (err) {
|
|
281
|
+
this.log.error(err);
|
|
282
|
+
try {
|
|
283
|
+
ws.close();
|
|
284
|
+
} catch (ign) {}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Initialize a new bidi connection
|
|
290
|
+
* @param {import('ws').WebSocket} ws The websocket connection object
|
|
291
|
+
* @param {import('http').IncomingMessage} req The connection pathname, which might include the session id
|
|
292
|
+
*/
|
|
293
|
+
initBidiSocket(ws, req) {
|
|
294
|
+
let outOfBandErrorPrefix = '';
|
|
295
|
+
const pathname = req.url;
|
|
296
|
+
if (!pathname) {
|
|
297
|
+
throw new Error('Invalid connection request: pathname missing from request');
|
|
298
|
+
}
|
|
299
|
+
const bidiSessionRe = new RegExp(`${BIDI_BASE_PATH}/([^/]+)$`);
|
|
300
|
+
const bidiNoSessionRe = new RegExp(`${BIDI_BASE_PATH}/?$`);
|
|
301
|
+
const sessionMatch = bidiSessionRe.exec(pathname);
|
|
302
|
+
const noSessionMatch = bidiNoSessionRe.exec(pathname);
|
|
303
|
+
|
|
304
|
+
if (!sessionMatch && !noSessionMatch) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
`Got websocket connection for path ${pathname} but didn't know what to do with it. ` +
|
|
307
|
+
`Ignoring and will close the connection`,
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Let's figure out which driver is going to handle this socket connection. It's either going
|
|
312
|
+
// to be a driver matching a session id appended to the bidi base path, or this umbrella driver
|
|
313
|
+
// (if no session id is included in the bidi connection request)
|
|
314
|
+
|
|
315
|
+
/** @type {import('@appium/types').ExternalDriver | AppiumDriver} */
|
|
316
|
+
let bidiHandlerDriver;
|
|
317
|
+
|
|
318
|
+
/** @type {import('ws').WebSocket | null} */
|
|
319
|
+
let proxyClient = null;
|
|
320
|
+
|
|
321
|
+
if (sessionMatch) {
|
|
322
|
+
// If we found a session id, see if it matches an active session
|
|
323
|
+
const sessionId = sessionMatch[1];
|
|
324
|
+
bidiHandlerDriver = this.sessions[sessionId];
|
|
325
|
+
if (!bidiHandlerDriver) {
|
|
326
|
+
// The session ID sent in doesn't match an active session; just ignore this socket
|
|
327
|
+
// connection in that case
|
|
328
|
+
throw new Error(
|
|
329
|
+
`Got bidi connection request for session with id ${sessionId} which is closed ` +
|
|
330
|
+
`or does not exist. Closing the socket connection.`,
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
const driverName = bidiHandlerDriver.constructor.name;
|
|
334
|
+
outOfBandErrorPrefix = `[session ${sessionId}] `;
|
|
335
|
+
this.log.info(`Bidi websocket connection made for session ${sessionId}`);
|
|
336
|
+
// store this socket connection for later removal on session deletion. theoretically there
|
|
337
|
+
// can be multiple sockets per session
|
|
338
|
+
if (!this.bidiSockets[sessionId]) {
|
|
339
|
+
this.bidiSockets[sessionId] = [];
|
|
340
|
+
}
|
|
341
|
+
this.bidiSockets[sessionId].push(ws);
|
|
342
|
+
|
|
343
|
+
const bidiProxyUrl = bidiHandlerDriver.bidiProxyUrl;
|
|
344
|
+
if (bidiProxyUrl) {
|
|
345
|
+
try {
|
|
346
|
+
new URL(bidiProxyUrl);
|
|
347
|
+
} catch (ign) {
|
|
348
|
+
throw new Error(
|
|
349
|
+
`Got request for ${driverName} to proxy bidi connections to upstream socket with ` +
|
|
350
|
+
`url ${bidiProxyUrl}, but this was not a valid url`,
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
this.log.info(`Bidi connection for ${driverName} will be proxied to ${bidiProxyUrl}`);
|
|
354
|
+
proxyClient = new WebSocket(bidiProxyUrl);
|
|
355
|
+
this.bidiProxyClients[sessionId] = proxyClient;
|
|
356
|
+
}
|
|
357
|
+
} else {
|
|
358
|
+
this.log.info('Bidi websocket connection made to main server');
|
|
359
|
+
// no need to store the socket connection if it's to the main server since it will just
|
|
360
|
+
// stay open as long as the server itself is and will close when the server closes.
|
|
361
|
+
bidiHandlerDriver = this; // eslint-disable-line @typescript-eslint/no-this-alias
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const logSocketErr = (/** @type {Error} */ err) =>
|
|
365
|
+
this.log.error(`${outOfBandErrorPrefix}${err}`);
|
|
366
|
+
|
|
367
|
+
// This is a function which wraps the 'send' method on a web socket for two reasons:
|
|
368
|
+
// 1. Make it async-await friendly
|
|
369
|
+
// 2. Do some logging if there's a send error
|
|
370
|
+
const sendFactory = (/** @type {import('ws').WebSocket} */ socket) => {
|
|
371
|
+
const socketSend = B.promisify(socket.send, {context: socket});
|
|
372
|
+
return async (/** @type {string|Buffer} */ data) => {
|
|
373
|
+
try {
|
|
374
|
+
await socketSend(data);
|
|
375
|
+
} catch (err) {
|
|
376
|
+
logSocketErr(err);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// Construct our send method for sending messages to the client
|
|
382
|
+
const send = sendFactory(ws);
|
|
383
|
+
|
|
384
|
+
// Construct a conditional send method for proxying messages from the client to an upstream
|
|
385
|
+
// bidi socket server (e.g. on a browser)
|
|
386
|
+
const sendToProxy = proxyClient ? sendFactory(proxyClient) : null;
|
|
387
|
+
|
|
388
|
+
return {bidiHandlerDriver, proxyClient, send, sendToProxy, logSocketErr};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Set up handlers on upstream bidi socket we are proxying to/from
|
|
393
|
+
*
|
|
394
|
+
* @param {import('ws').WebSocket | null} proxyClient - the websocket connection to/from the
|
|
395
|
+
* upstream socket (the one we're proxying to/from)
|
|
396
|
+
* @param {import('ws').WebSocket} ws - the websocket connection to/from the client
|
|
397
|
+
* @param {(data: string | Buffer) => Promise<void>} send - a method used to send data to the
|
|
398
|
+
* client
|
|
399
|
+
*/
|
|
400
|
+
initBidiProxyHandlers(proxyClient, ws, send) {
|
|
401
|
+
// Set up handlers for events that might come from the upstream bidi socket connection if
|
|
402
|
+
// we're in proxy mode
|
|
403
|
+
if (proxyClient) {
|
|
404
|
+
// Here we're receiving a message from the upstream socket server. We want to pass it on to
|
|
405
|
+
// the client
|
|
406
|
+
proxyClient.on('message', async (/** @type {Buffer|string} */ data) => {
|
|
407
|
+
const logData = _.truncate(data.toString('utf8'), {length: MAX_LOG_BODY_LENGTH});
|
|
408
|
+
this.log.debug(
|
|
409
|
+
`<-- BIDI Received data from proxied bidi socket, sending to client. Data: ${logData}`,
|
|
410
|
+
);
|
|
411
|
+
await send(data);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// If the upstream socket server closes the connection, should close the connection to the
|
|
415
|
+
// client as well
|
|
416
|
+
proxyClient.on('close', (code, reason) => {
|
|
417
|
+
this.log.debug(
|
|
418
|
+
`Upstream bidi socket closed connection (code ${code}, reason: '${reason}'). ` +
|
|
419
|
+
`Closing proxy connection to client`,
|
|
420
|
+
);
|
|
421
|
+
ws.close(code, reason);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
proxyClient.on('error', (err) => {
|
|
425
|
+
this.log.error(`Got error on upstream bidi socket connection: ${err}`);
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Set up handlers on the bidi socket connection to the client
|
|
432
|
+
*
|
|
433
|
+
* @param {import('ws').WebSocket} ws - the websocket connection to/from the client
|
|
434
|
+
* @param {import('ws').WebSocket | null} proxyClient - the websocket connection to/from the
|
|
435
|
+
* upstream socket (the one we're proxying to/from, if we're proxying)
|
|
436
|
+
* @param {(data: string | Buffer) => Promise<void>} send - a method used to send data to the
|
|
437
|
+
* client
|
|
438
|
+
* @param {((data: string | Buffer) => Promise<void>) | null} sendToProxy - a method used to send data to the
|
|
439
|
+
* upstream socket
|
|
440
|
+
* @param {import('@appium/types').ExternalDriver | AppiumDriver} bidiHandlerDriver - the driver
|
|
441
|
+
* handling the bidi commands
|
|
442
|
+
* @param {(err: Error) => void} logSocketErr - a special prefixed logger
|
|
443
|
+
*/
|
|
444
|
+
initBidiSocketHandlers(ws, proxyClient, send, sendToProxy, bidiHandlerDriver, logSocketErr) {
|
|
445
|
+
ws.on('error', (err) => {
|
|
446
|
+
// Can't do much with random errors on the connection other than log them
|
|
447
|
+
logSocketErr(err);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
ws.on('open', () => {
|
|
451
|
+
this.log.info('Bidi websocket connection is now open');
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
// Now set up handlers for the various events that might happen on the websocket connection
|
|
455
|
+
// coming from the client
|
|
456
|
+
// First is incoming messages from the client
|
|
457
|
+
ws.on('message', async (/** @type {Buffer} */ data) => {
|
|
458
|
+
if (proxyClient) {
|
|
459
|
+
const logData = _.truncate(data.toString('utf8'), {length: MAX_LOG_BODY_LENGTH});
|
|
460
|
+
this.log.debug(
|
|
461
|
+
`--> BIDI Received data from client, sending to upstream bidi socket. Data: ${logData}`,
|
|
462
|
+
);
|
|
463
|
+
// if we're meant to proxy to an upstream bidi socket, just do that
|
|
464
|
+
// @ts-ignore sendToProxy is never null if proxyClient is truthy, but ts doesn't know
|
|
465
|
+
// that
|
|
466
|
+
await sendToProxy(data.toString('utf8'));
|
|
467
|
+
} else {
|
|
468
|
+
const res = await this.onBidiMessage(data, bidiHandlerDriver);
|
|
469
|
+
await send(JSON.stringify(res));
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// Next consider if the client closes the socket connection on us
|
|
474
|
+
ws.on('close', (code, reason) => {
|
|
475
|
+
// Not sure if we need to do anything here if the client closes the websocket connection.
|
|
476
|
+
// Probably if a session was started via the socket, and the socket closes, we should end the
|
|
477
|
+
// associated session to free up resources. But otherwise, for sockets attached to existing
|
|
478
|
+
// sessions, doing nothing is probably right.
|
|
479
|
+
this.log.debug(`Bidi socket connection closed (code ${code}, reason: '${reason}')`);
|
|
480
|
+
|
|
481
|
+
// If we're proxying, might as well close the upstream connection and clean it up
|
|
482
|
+
if (proxyClient) {
|
|
483
|
+
this.log.debug('Also closing bidi proxy socket connection');
|
|
484
|
+
proxyClient.close(code, reason);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Set up bidi event listeners
|
|
491
|
+
*
|
|
492
|
+
* @param {import('ws').WebSocket} ws - the websocket connection to/from the client
|
|
493
|
+
* @param {import('@appium/types').ExternalDriver | AppiumDriver} bidiHandlerDriver - the driver
|
|
494
|
+
* handling the bidi commands
|
|
495
|
+
* @param {(data: string | Buffer) => Promise<void>} send - a method used to send data to the
|
|
496
|
+
* client
|
|
497
|
+
*/
|
|
498
|
+
initBidiEventListeners(ws, bidiHandlerDriver, send) {
|
|
499
|
+
// If the driver emits a bidi event that should maybe get sent to the client, check to make
|
|
500
|
+
// sure the client is subscribed and then pass it on
|
|
501
|
+
let eventListener = async ({context, method, params}) => {
|
|
502
|
+
// if the driver didn't specify a context, use the empty context
|
|
503
|
+
if (!context) {
|
|
504
|
+
context = '';
|
|
505
|
+
}
|
|
506
|
+
if (!method || !params) {
|
|
507
|
+
throw new Error(
|
|
508
|
+
`Driver emitted a bidi event that was malformed. Require method and params keys ` +
|
|
509
|
+
`(with optional context). But instead received: ${JSON.stringify({
|
|
510
|
+
context,
|
|
511
|
+
method,
|
|
512
|
+
params,
|
|
513
|
+
})}`,
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
if (ws.readyState !== WebSocket.OPEN) {
|
|
517
|
+
// if the websocket is not still 'open', then we can ignore sending these events
|
|
518
|
+
if (ws.readyState > WebSocket.OPEN) {
|
|
519
|
+
// if the websocket is closed or closing, we can remove this listener as well to avoid
|
|
520
|
+
// leaks
|
|
521
|
+
bidiHandlerDriver.eventEmitter.removeListener(BIDI_EVENT_NAME, eventListener);
|
|
522
|
+
}
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
if (bidiHandlerDriver.bidiEventSubs[method]?.includes(context)) {
|
|
527
|
+
this.log.info(
|
|
528
|
+
`<-- BIDI EVENT ${method} (context: '${context}', params: ${JSON.stringify(params)})`,
|
|
529
|
+
);
|
|
530
|
+
// now we can send the event onto the socket
|
|
531
|
+
const ev = {type: 'event', context, method, params};
|
|
532
|
+
await send(JSON.stringify(ev));
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
bidiHandlerDriver.eventEmitter.on(BIDI_EVENT_NAME, eventListener);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* @param {Buffer} data
|
|
540
|
+
* @param {ExternalDriver | AppiumDriver} driver
|
|
541
|
+
*/
|
|
542
|
+
async onBidiMessage(data, driver) {
|
|
543
|
+
let resMessage, id, method, params;
|
|
544
|
+
const dataTruncated = _.truncate(data.toString(), {length: 100});
|
|
545
|
+
try {
|
|
546
|
+
try {
|
|
547
|
+
({id, method, params} = JSON.parse(data.toString('utf8')));
|
|
548
|
+
} catch (err) {
|
|
549
|
+
throw new errors.InvalidArgumentError(
|
|
550
|
+
`Could not parse Bidi command '${dataTruncated}': ${err.message}`,
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
driver.log.info(`--> BIDI message #${id}`);
|
|
554
|
+
if (!method) {
|
|
555
|
+
throw new errors.InvalidArgumentError(
|
|
556
|
+
`Missing method for BiDi operation in '${dataTruncated}'`,
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
if (!params) {
|
|
560
|
+
throw new errors.InvalidArgumentError(
|
|
561
|
+
`Missing params for BiDi operation in '${dataTruncated}`,
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
const result = await driver.executeBidiCommand(method, params);
|
|
565
|
+
// https://w3c.github.io/webdriver-bidi/#protocol-definition
|
|
566
|
+
resMessage = {
|
|
567
|
+
id,
|
|
568
|
+
type: 'success',
|
|
569
|
+
result,
|
|
570
|
+
};
|
|
571
|
+
} catch (err) {
|
|
572
|
+
resMessage = err.bidiErrObject(id);
|
|
573
|
+
}
|
|
574
|
+
driver.log.info(`<-- BIDI message #${id}`);
|
|
575
|
+
return resMessage;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Log a bidi server error
|
|
580
|
+
* @param {Error} err
|
|
581
|
+
*/
|
|
582
|
+
onBidiServerError(err) {
|
|
583
|
+
this.log.error(`Error from bidi websocket server: ${err}`);
|
|
584
|
+
}
|
|
585
|
+
|
|
244
586
|
/**
|
|
245
587
|
* Create a new session
|
|
246
588
|
* @param {W3CAppiumDriverCaps} jsonwpCaps JSONWP formatted desired capabilities
|
|
@@ -299,7 +641,7 @@ class AppiumDriver extends DriverCore {
|
|
|
299
641
|
driver: InnerDriver,
|
|
300
642
|
version: driverVersion,
|
|
301
643
|
driverName,
|
|
302
|
-
} = this.driverConfig.findMatchingDriver(desiredCaps);
|
|
644
|
+
} = await this.driverConfig.findMatchingDriver(desiredCaps);
|
|
303
645
|
this.printNewSessionAnnouncement(InnerDriver.name, driverVersion, InnerDriver.baseVersion);
|
|
304
646
|
|
|
305
647
|
if (this.args.sessionOverride) {
|
|
@@ -410,6 +752,21 @@ class AppiumDriver extends DriverCore {
|
|
|
410
752
|
);
|
|
411
753
|
await driverInstance.updateSettings(jwpSettings);
|
|
412
754
|
}
|
|
755
|
+
|
|
756
|
+
// if the user has asked for bidi support, and the driver says that it supports bidi,
|
|
757
|
+
// send our bidi url back to the user. The inner driver will need to have already saved any
|
|
758
|
+
// internal bidi urls it might want to proxy to, cause we are going to overwrite that
|
|
759
|
+
// information here!
|
|
760
|
+
if (dCaps.webSocketUrl && driverInstance.doesSupportBidi) {
|
|
761
|
+
const {address, port, basePath} = this.args;
|
|
762
|
+
const isUsingSsl = this.args.sslCertificatePath && this.args.sslKeyPath;
|
|
763
|
+
const scheme = isUsingSsl ? 'wss' : 'ws';
|
|
764
|
+
const bidiUrl = `${scheme}://${address}:${port}${basePath}${BIDI_BASE_PATH}/${innerSessionId}`;
|
|
765
|
+
// @ts-ignore webSocketUrl gets sent by the client as a boolean, but then it is supposed
|
|
766
|
+
// to come back from the server as a string. TODO figure out how to express this in our
|
|
767
|
+
// capability constraint system
|
|
768
|
+
dCaps.webSocketUrl = bidiUrl;
|
|
769
|
+
}
|
|
413
770
|
} catch (error) {
|
|
414
771
|
return {
|
|
415
772
|
protocol,
|
|
@@ -515,6 +872,9 @@ class AppiumDriver extends DriverCore {
|
|
|
515
872
|
// be in otherwise
|
|
516
873
|
delete this.sessions[sessionId];
|
|
517
874
|
delete this.sessionPlugins[sessionId];
|
|
875
|
+
|
|
876
|
+
this.cleanupBidiSockets(sessionId);
|
|
877
|
+
|
|
518
878
|
return dstSession;
|
|
519
879
|
});
|
|
520
880
|
// this may not be correct, but if `dstSession` was falsy, the call to `deleteSession()` would
|
|
@@ -535,6 +895,32 @@ class AppiumDriver extends DriverCore {
|
|
|
535
895
|
}
|
|
536
896
|
}
|
|
537
897
|
|
|
898
|
+
/**
|
|
899
|
+
* @param {string} sessionId
|
|
900
|
+
*/
|
|
901
|
+
cleanupBidiSockets(sessionId) {
|
|
902
|
+
// clean up any bidi sockets associated with session
|
|
903
|
+
if (this.bidiSockets[sessionId]) {
|
|
904
|
+
try {
|
|
905
|
+
this.log.debug(`Closing bidi socket(s) associated with session ${sessionId}`);
|
|
906
|
+
for (const ws of this.bidiSockets[sessionId]) {
|
|
907
|
+
// 1001 means server is going away
|
|
908
|
+
ws.close(1001, 'Appium session is closing');
|
|
909
|
+
}
|
|
910
|
+
} catch {}
|
|
911
|
+
delete this.bidiSockets[sessionId];
|
|
912
|
+
const proxyClient = this.bidiProxyClients[sessionId];
|
|
913
|
+
if (proxyClient) {
|
|
914
|
+
this.log.debug(`Also closing proxy connection to upstream bidi server`);
|
|
915
|
+
try {
|
|
916
|
+
// 1000 means normal closure, which seems correct when Appium is acting as the client
|
|
917
|
+
proxyClient.close(1000);
|
|
918
|
+
} catch {}
|
|
919
|
+
delete this.bidiProxyClients[sessionId];
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
538
924
|
async deleteAllSessions(opts = {}) {
|
|
539
925
|
const sessionsCount = _.size(this.sessions);
|
|
540
926
|
if (0 === sessionsCount) {
|
package/lib/cli/args.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
EXT_SUBCOMMAND_RUN,
|
|
8
8
|
EXT_SUBCOMMAND_UNINSTALL,
|
|
9
9
|
EXT_SUBCOMMAND_UPDATE,
|
|
10
|
+
EXT_SUBCOMMAND_DOCTOR,
|
|
10
11
|
} from '../constants';
|
|
11
12
|
import {INSTALL_TYPES} from '../extension/extension-config';
|
|
12
13
|
import {toParserArgs} from '../schema/cli-args';
|
|
@@ -49,6 +50,7 @@ const getExtensionArgs = _.memoize(function getExtensionArgs() {
|
|
|
49
50
|
[EXT_SUBCOMMAND_UNINSTALL]: makeUninstallArgs(type),
|
|
50
51
|
[EXT_SUBCOMMAND_UPDATE]: makeUpdateArgs(type),
|
|
51
52
|
[EXT_SUBCOMMAND_RUN]: makeRunArgs(type),
|
|
53
|
+
[EXT_SUBCOMMAND_DOCTOR]: makeDoctorArgs(type),
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
56
|
return /** @type {Record<ExtensionType, Record<import('appium/types').CliExtensionSubcommand,ArgumentDefinitions>>} */ (
|
|
@@ -156,7 +158,28 @@ function makeUninstallArgs(type) {
|
|
|
156
158
|
{
|
|
157
159
|
type: 'str',
|
|
158
160
|
help:
|
|
159
|
-
|
|
161
|
+
`Name of the ${type} to uninstall, for example: ` + type === DRIVER_TYPE
|
|
162
|
+
? DRIVER_EXAMPLE
|
|
163
|
+
: PLUGIN_EXAMPLE,
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
]);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Makes the opts for the `doctor` subcommand for each extension type
|
|
171
|
+
* @param {ExtensionType} type
|
|
172
|
+
* @returns {ArgumentDefinitions}
|
|
173
|
+
*/
|
|
174
|
+
function makeDoctorArgs(type) {
|
|
175
|
+
return new Map([
|
|
176
|
+
...globalExtensionArgs,
|
|
177
|
+
[
|
|
178
|
+
[type],
|
|
179
|
+
{
|
|
180
|
+
type: 'str',
|
|
181
|
+
help:
|
|
182
|
+
`Name of the ${type} to run doctor checks for, for example: ` + type === DRIVER_TYPE
|
|
160
183
|
? DRIVER_EXAMPLE
|
|
161
184
|
: PLUGIN_EXAMPLE,
|
|
162
185
|
},
|
|
@@ -222,10 +245,12 @@ function makeRunArgs(type) {
|
|
|
222
245
|
['scriptName'],
|
|
223
246
|
{
|
|
224
247
|
default: null,
|
|
248
|
+
nargs: '?',
|
|
225
249
|
type: 'str',
|
|
226
250
|
help:
|
|
227
251
|
`Name of the script to run from the ${type}. The script name must be a key ` +
|
|
228
|
-
`inside the "appium.scripts" field inside the ${type}'s "package.json" file
|
|
252
|
+
`inside the "appium.scripts" field inside the ${type}'s "package.json" file. ` +
|
|
253
|
+
`If not provided then all available script names are going to be listed.`,
|
|
229
254
|
},
|
|
230
255
|
],
|
|
231
256
|
]);
|
|
@@ -66,6 +66,18 @@ export default class DriverCliCommand extends ExtensionCliCommand {
|
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Runs doctor checks for the given driver
|
|
71
|
+
*
|
|
72
|
+
* @param {DriverDoctorOptions} opts
|
|
73
|
+
* @returns {Promise<import('@appium/types').IDoctorCheck[]>}
|
|
74
|
+
*/
|
|
75
|
+
async doctor({driver}) {
|
|
76
|
+
return await super._doctor({
|
|
77
|
+
installSpec: driver,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
69
81
|
/**
|
|
70
82
|
*
|
|
71
83
|
* @param {import('./extension-command').ExtensionArgs} opts
|
|
@@ -151,3 +163,9 @@ export default class DriverCliCommand extends ExtensionCliCommand {
|
|
|
151
163
|
* @property {string} scriptName - name of the script to run
|
|
152
164
|
* @property {string[]} [extraArgs] - arguments to pass to the script
|
|
153
165
|
*/
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Options for {@linkcode DriverCliCommand.doctor}.
|
|
169
|
+
* @typedef DriverDoctorOptions
|
|
170
|
+
* @property {string} driver - name of the driver to run doctor checks for
|
|
171
|
+
*/
|