@appium/base-driver 9.3.3 → 9.3.5

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.
Files changed (91) hide show
  1. package/build/lib/basedriver/capabilities.d.ts +59 -36
  2. package/build/lib/basedriver/capabilities.d.ts.map +1 -1
  3. package/build/lib/basedriver/capabilities.js +57 -45
  4. package/build/lib/basedriver/capabilities.js.map +1 -1
  5. package/build/lib/basedriver/commands/event.d.ts +1 -1
  6. package/build/lib/basedriver/commands/event.d.ts.map +1 -1
  7. package/build/lib/basedriver/commands/event.js.map +1 -1
  8. package/build/lib/basedriver/commands/execute.d.ts +1 -1
  9. package/build/lib/basedriver/commands/execute.d.ts.map +1 -1
  10. package/build/lib/basedriver/commands/execute.js.map +1 -1
  11. package/build/lib/basedriver/commands/find.d.ts +1 -1
  12. package/build/lib/basedriver/commands/find.d.ts.map +1 -1
  13. package/build/lib/basedriver/commands/find.js.map +1 -1
  14. package/build/lib/basedriver/commands/index.d.ts +7 -7
  15. package/build/lib/basedriver/commands/index.d.ts.map +1 -1
  16. package/build/lib/basedriver/commands/index.js +7 -21
  17. package/build/lib/basedriver/commands/index.js.map +1 -1
  18. package/build/lib/basedriver/commands/log.d.ts +1 -1
  19. package/build/lib/basedriver/commands/log.d.ts.map +1 -1
  20. package/build/lib/basedriver/commands/log.js.map +1 -1
  21. package/build/lib/basedriver/commands/mixin.d.ts +4 -4
  22. package/build/lib/basedriver/commands/mixin.d.ts.map +1 -1
  23. package/build/lib/basedriver/commands/mixin.js +5 -4
  24. package/build/lib/basedriver/commands/mixin.js.map +1 -1
  25. package/build/lib/basedriver/commands/session.d.ts +1 -1
  26. package/build/lib/basedriver/commands/session.d.ts.map +1 -1
  27. package/build/lib/basedriver/commands/session.js +1 -4
  28. package/build/lib/basedriver/commands/session.js.map +1 -1
  29. package/build/lib/basedriver/commands/settings.d.ts +1 -1
  30. package/build/lib/basedriver/commands/settings.d.ts.map +1 -1
  31. package/build/lib/basedriver/commands/settings.js.map +1 -1
  32. package/build/lib/basedriver/commands/timeout.d.ts +1 -1
  33. package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
  34. package/build/lib/basedriver/commands/timeout.js +1 -4
  35. package/build/lib/basedriver/commands/timeout.js.map +1 -1
  36. package/build/lib/basedriver/core.d.ts +13 -17
  37. package/build/lib/basedriver/core.d.ts.map +1 -1
  38. package/build/lib/basedriver/core.js +32 -20
  39. package/build/lib/basedriver/core.js.map +1 -1
  40. package/build/lib/basedriver/device-settings.d.ts +11 -11
  41. package/build/lib/basedriver/device-settings.d.ts.map +1 -1
  42. package/build/lib/basedriver/device-settings.js +7 -8
  43. package/build/lib/basedriver/device-settings.js.map +1 -1
  44. package/build/lib/basedriver/driver.d.ts +23 -108
  45. package/build/lib/basedriver/driver.d.ts.map +1 -1
  46. package/build/lib/basedriver/driver.js +21 -126
  47. package/build/lib/basedriver/driver.js.map +1 -1
  48. package/build/lib/basedriver/helpers.d.ts +21 -98
  49. package/build/lib/basedriver/helpers.d.ts.map +1 -1
  50. package/build/lib/basedriver/helpers.js +178 -182
  51. package/build/lib/basedriver/helpers.js.map +1 -1
  52. package/build/lib/express/server.d.ts +3 -3
  53. package/build/lib/express/server.d.ts.map +1 -1
  54. package/build/lib/express/server.js +4 -2
  55. package/build/lib/express/server.js.map +1 -1
  56. package/build/lib/express/websocket.d.ts +5 -44
  57. package/build/lib/express/websocket.d.ts.map +1 -1
  58. package/build/lib/express/websocket.js +10 -39
  59. package/build/lib/express/websocket.js.map +1 -1
  60. package/build/lib/helpers/capabilities.d.ts +2 -2
  61. package/build/lib/helpers/capabilities.d.ts.map +1 -1
  62. package/build/lib/helpers/capabilities.js +2 -3
  63. package/build/lib/helpers/capabilities.js.map +1 -1
  64. package/build/lib/protocol/protocol.d.ts +1 -1
  65. package/build/lib/protocol/protocol.d.ts.map +1 -1
  66. package/build/lib/protocol/protocol.js +10 -2
  67. package/build/lib/protocol/protocol.js.map +1 -1
  68. package/build/lib/protocol/routes.d.ts +1 -0
  69. package/build/lib/protocol/routes.d.ts.map +1 -1
  70. package/build/lib/protocol/routes.js +12 -10
  71. package/build/lib/protocol/routes.js.map +1 -1
  72. package/lib/basedriver/capabilities.js +70 -56
  73. package/lib/basedriver/commands/event.ts +3 -2
  74. package/lib/basedriver/commands/execute.ts +2 -1
  75. package/lib/basedriver/commands/find.ts +1 -0
  76. package/lib/basedriver/commands/index.ts +7 -7
  77. package/lib/basedriver/commands/log.ts +2 -4
  78. package/lib/basedriver/commands/mixin.ts +5 -4
  79. package/lib/basedriver/commands/session.ts +9 -7
  80. package/lib/basedriver/commands/settings.ts +1 -0
  81. package/lib/basedriver/commands/timeout.ts +17 -17
  82. package/lib/basedriver/core.js +11 -25
  83. package/lib/basedriver/device-settings.js +9 -11
  84. package/lib/basedriver/{driver.js → driver.ts} +69 -175
  85. package/lib/basedriver/helpers.js +214 -212
  86. package/lib/express/server.js +4 -2
  87. package/lib/express/websocket.js +10 -39
  88. package/lib/helpers/capabilities.js +2 -3
  89. package/lib/protocol/protocol.js +11 -2
  90. package/lib/protocol/routes.js +12 -13
  91. package/package.json +10 -6
@@ -1,6 +1,3 @@
1
- /* eslint-disable require-await */
2
- /* eslint-disable no-unused-vars */
3
-
4
1
  import {validateCaps, processCapabilities} from './capabilities';
5
2
  import {DriverCore} from './core';
6
3
  import {util} from '@appium/support';
@@ -9,7 +6,21 @@ import _ from 'lodash';
9
6
  import {fixCaps, isW3cCaps} from '../helpers/capabilities';
10
7
  import {DELETE_SESSION_COMMAND, determineProtocol, errors} from '../protocol';
11
8
  import helpers from './helpers';
12
- import {BASE_DESIRED_CAP_CONSTRAINTS} from '@appium/types';
9
+ import {
10
+ AppiumServer,
11
+ BaseDriverCapConstraints,
12
+ BASE_DESIRED_CAP_CONSTRAINTS,
13
+ Capabilities,
14
+ Constraints,
15
+ DefaultCreateSessionResult,
16
+ Driver,
17
+ DriverCaps,
18
+ DriverData,
19
+ DriverOpts,
20
+ ServerArgs,
21
+ StringRecord,
22
+ W3CDriverCaps,
23
+ } from '@appium/types';
13
24
 
14
25
  const EVENT_SESSION_INIT = 'newSessionRequested';
15
26
  const EVENT_SESSION_START = 'newSessionStarted';
@@ -17,56 +28,31 @@ const EVENT_SESSION_QUIT_START = 'quitSessionRequested';
17
28
  const EVENT_SESSION_QUIT_DONE = 'quitSessionFinished';
18
29
  const ON_UNEXPECTED_SHUTDOWN_EVENT = 'onUnexpectedShutdown';
19
30
 
20
- /**
21
- * @implements {SessionHandler<C>}
22
- * @template {Constraints} C
23
- * @template {StringRecord} [CArgs=StringRecord]
24
- * @implements {Driver<C, CArgs>}
25
- * @extends {DriverCore<C>}
26
- */
27
- export class BaseDriver extends DriverCore {
28
- /**
29
- * @type {CArgs & ServerArgs}
30
- */
31
- cliArgs;
32
-
33
- /**
34
- * @type {Capabilities<C>}
35
- */
36
- caps;
37
-
38
- /**
39
- * @type {W3CCapabilities<C>}
40
- */
41
- originalCaps;
42
-
43
- /**
44
- * @type {C}
45
- */
46
- desiredCapConstraints;
47
-
48
- /**
49
- * @type {DriverOpts<C> & DriverOpts<BaseDriverCapConstraints>}
50
- */
51
- opts;
52
-
53
- /**
54
- *
55
- * @param {DriverOpts<C>} opts
56
- * @param {boolean} shouldValidateCaps
57
- */
58
- constructor(opts = /** @type {DriverOpts<C>} */ ({}), shouldValidateCaps = true) {
31
+ export class BaseDriver<
32
+ C extends Constraints,
33
+ CArgs extends StringRecord = StringRecord,
34
+ Settings extends StringRecord = StringRecord
35
+ >
36
+ extends DriverCore<C, Settings>
37
+ implements Driver<C, CArgs>
38
+ {
39
+ cliArgs: CArgs & ServerArgs;
40
+
41
+ caps: DriverCaps<C>;
42
+ originalCaps: W3CDriverCaps<C>;
43
+ desiredCapConstraints: C;
44
+ opts: DriverOpts<C>;
45
+ server?: AppiumServer;
46
+ serverHost?: string;
47
+ serverPort?: number;
48
+ serverPath?: string;
49
+
50
+ constructor(opts: DriverOpts<C>, shouldValidateCaps = true) {
59
51
  super(opts, shouldValidateCaps);
60
52
 
61
- /**
62
- * This must be assigned here because the declaration of {@linkcode BaseDriver.opts} above
63
- * blows away {@linkcode DriverCore.opts}.
64
- */
65
- this.opts = opts;
53
+ this.caps = {} as DriverCaps<C>;
66
54
 
67
- this.caps = {};
68
-
69
- this.cliArgs = /** @type {CArgs & ServerArgs} */ ({});
55
+ this.cliArgs = {} as CArgs & ServerArgs;
70
56
  }
71
57
 
72
58
  /**
@@ -75,25 +61,20 @@ export class BaseDriver extends DriverCore {
75
61
  * Subclasses _shouldn't_ need to use this. If you need to use this, please create
76
62
  * an issue:
77
63
  * @see https://github.com/appium/appium/issues/new
78
- * @type {Readonly<BaseDriverCapConstraints & C>}
79
- * @protected
80
64
  */
81
- get _desiredCapConstraints() {
65
+ protected get _desiredCapConstraints(): Readonly<BaseDriverCapConstraints & C> {
82
66
  return Object.freeze(_.merge({}, BASE_DESIRED_CAP_CONSTRAINTS, this.desiredCapConstraints));
83
67
  }
84
68
 
85
- // This is the main command handler for the driver. It wraps command
86
- // execution with timeout logic, checking that we have a valid session,
87
- // and ensuring that we execute commands one at a time. This method is called
88
- // by MJSONWP's express router.
89
69
  /**
90
- * @param {string} cmd
91
- * @param {...any} args
92
- * @returns {Promise<any>}
70
+ * This is the main command handler for the driver. It wraps command
71
+ * execution with timeout logic, checking that we have a valid session,
72
+ * and ensuring that we execute commands one at a time. This method is called
73
+ * by MJSONWP's express router.
93
74
  */
94
- async executeCommand(cmd, ...args) {
75
+ async executeCommand<T = unknown>(cmd: string, ...args: any[]): Promise<T> {
95
76
  // get start time for this command, and log in special cases
96
- let startTime = Date.now();
77
+ const startTime = Date.now();
97
78
 
98
79
  if (cmd === 'createSession') {
99
80
  // If creating a session determine if W3C or MJSONWP protocol was requested and remember the choice
@@ -161,12 +142,8 @@ export class BaseDriver extends DriverCore {
161
142
  return res;
162
143
  }
163
144
 
164
- /**
165
- *
166
- * @param {Error|import('../protocol/errors').NoSuchDriverError} err
167
- */
168
145
  async startUnexpectedShutdown(
169
- err = new errors.NoSuchDriverError('The driver was unexpectedly shut down!')
146
+ err: Error = new errors.NoSuchDriverError('The driver was unexpectedly shut down!')
170
147
  ) {
171
148
  this.eventEmitter.emit(ON_UNEXPECTED_SHUTDOWN_EVENT, err); // allow others to listen for this
172
149
  this.shutdownUnexpectedly = true;
@@ -200,14 +177,7 @@ export class BaseDriver extends DriverCore {
200
177
  }, this.newCommandTimeoutMs);
201
178
  }
202
179
 
203
- /**
204
- *
205
- * @param {import('@appium/types').AppiumServer} server
206
- * @param {string} host
207
- * @param {number} port
208
- * @param {string} path
209
- */
210
- assignServer(server, host, port, path) {
180
+ assignServer(server: AppiumServer, host: string, port: number, path: string) {
211
181
  this.server = server;
212
182
  this.serverHost = host;
213
183
  this.serverPort = port;
@@ -223,8 +193,8 @@ export class BaseDriver extends DriverCore {
223
193
  this.log.debug('Running generic full reset');
224
194
 
225
195
  // preserving state
226
- let currentConfig = {};
227
- for (let property of [
196
+ const currentConfig = {};
197
+ for (const property of [
228
198
  'implicitWaitMs',
229
199
  'newCommandTimeoutMs',
230
200
  'sessionId',
@@ -233,9 +203,6 @@ export class BaseDriver extends DriverCore {
233
203
  currentConfig[property] = this[property];
234
204
  }
235
205
 
236
- // We also need to preserve the unexpected shutdown, and make sure it is not cancelled during reset.
237
- this.resetOnUnexpectedShutdown = () => {};
238
-
239
206
  try {
240
207
  if (this.sessionId !== null) {
241
208
  await this.deleteSession(this.sessionId);
@@ -244,7 +211,7 @@ export class BaseDriver extends DriverCore {
244
211
  await this.createSession(this.originalCaps);
245
212
  } finally {
246
213
  // always restore state.
247
- for (let [key, value] of _.toPairs(currentConfig)) {
214
+ for (const [key, value] of _.toPairs(currentConfig)) {
248
215
  this[key] = value;
249
216
  }
250
217
  }
@@ -257,13 +224,14 @@ export class BaseDriver extends DriverCore {
257
224
  * Appium 2 has dropped the support of these, so now we only accept capability
258
225
  * objects in W3C format and thus allow any of the three arguments to represent
259
226
  * the latter.
260
- * @param {W3CCapabilities<C>} w3cCapabilities1
261
- * @param {W3CCapabilities<C>} [w3cCapabilities2]
262
- * @param {W3CCapabilities<C>} [w3cCapabilities]
263
- * @param {DriverData[]} [driverData]
264
- * @returns {Promise<[string,Capabilities<C>]>}
265
227
  */
266
- async createSession(w3cCapabilities1, w3cCapabilities2, w3cCapabilities, driverData) {
228
+ async createSession(
229
+ w3cCapabilities1: W3CDriverCaps<C>,
230
+ w3cCapabilities2?: W3CDriverCaps<C>,
231
+ w3cCapabilities?: W3CDriverCaps<C>,
232
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
233
+ driverData?: DriverData[]
234
+ ): Promise<DefaultCreateSessionResult<C>> {
267
235
  if (this.sessionId !== null) {
268
236
  throw new errors.SessionNotCreatedError(
269
237
  'Cannot create a new session while one is in progress'
@@ -289,15 +257,14 @@ export class BaseDriver extends DriverCore {
289
257
  `Creating session with W3C capabilities: ${JSON.stringify(originalCaps, null, 2)}`
290
258
  );
291
259
 
292
- /** @type {Capabilities<C>} */
293
- let caps;
260
+ let caps: DriverCaps<C>;
294
261
  try {
295
262
  caps = processCapabilities(
296
263
  originalCaps,
297
264
  this._desiredCapConstraints,
298
265
  this.shouldValidateCaps
299
- );
300
- caps = fixCaps(caps, this._desiredCapConstraints, this.log);
266
+ ) as DriverCaps<C>;
267
+ caps = fixCaps(caps, this._desiredCapConstraints, this.log) as DriverCaps<C>;
301
268
  } catch (e) {
302
269
  throw new errors.SessionNotCreatedError(e.message);
303
270
  }
@@ -334,7 +301,7 @@ export class BaseDriver extends DriverCore {
334
301
  }
335
302
 
336
303
  if (!_.isUndefined(this.caps.newCommandTimeout)) {
337
- this.newCommandTimeoutMs = /** @type {number} */ (this.caps.newCommandTimeout) * 1000;
304
+ this.newCommandTimeoutMs = (this.caps.newCommandTimeout as number) * 1000;
338
305
  }
339
306
 
340
307
  this._log.prefix = helpers.generateDriverLogPrefix(this, this.sessionId);
@@ -344,32 +311,23 @@ export class BaseDriver extends DriverCore {
344
311
  return [this.sessionId, caps];
345
312
  }
346
313
 
347
- /**
348
- *
349
- * @param {string} [sessionId]
350
- * @param {DriverData[]} [driverData]
351
- * @returns {Promise<void>}
352
- */
353
- async deleteSession(sessionId, driverData) {
314
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
315
+ async deleteSession(sessionId?: string | null) {
354
316
  await this.clearNewCommandTimeout();
355
317
  if (this.isCommandsQueueEnabled && this.commandsQueueGuard.isBusy()) {
356
318
  // simple hack to release pending commands if they exist
357
- // @ts-ignore
358
- for (const key of _.keys(this.commandsQueueGuard.queues)) {
359
- // @ts-ignore
360
- this.commandsQueueGuard.queues[key] = [];
319
+ // @ts-expect-error private API
320
+ const queues = this.commandsQueueGuard.queues;
321
+ for (const key of _.keys(queues)) {
322
+ queues[key] = [];
361
323
  }
362
324
  }
363
325
  this.sessionId = null;
364
326
  this._log.prefix = helpers.generateDriverLogPrefix(this);
365
327
  }
366
328
 
367
- /**
368
- *
369
- * @param {Capabilities<C>} caps
370
- */
371
- logExtraCaps(caps) {
372
- let extraCaps = _.difference(_.keys(caps), _.keys(this._desiredCapConstraints));
329
+ logExtraCaps(caps: Capabilities<C>) {
330
+ const extraCaps = _.difference(_.keys(caps), _.keys(this._desiredCapConstraints));
373
331
  if (extraCaps.length) {
374
332
  this.log.warn(
375
333
  `The following capabilities were provided, but are not ` + `recognized by Appium:`
@@ -380,12 +338,7 @@ export class BaseDriver extends DriverCore {
380
338
  }
381
339
  }
382
340
 
383
- /**
384
- *
385
- * @param {Capabilities<C>} caps
386
- * @returns {boolean}
387
- */
388
- validateDesiredCaps(caps) {
341
+ validateDesiredCaps(caps: any): caps is DriverCaps<C> {
389
342
  if (!this.shouldValidateCaps) {
390
343
  return true;
391
344
  }
@@ -407,65 +360,6 @@ export class BaseDriver extends DriverCore {
407
360
  }
408
361
  }
409
362
 
410
- // eslint-disable-next-line import/no-unresolved
411
363
  export * from './commands';
412
364
 
413
365
  export default BaseDriver;
414
-
415
- /**
416
- * @typedef {import('@appium/types').HTTPMethod} HTTPMethod
417
- * @typedef {import('@appium/types').DriverData} DriverData
418
- * @typedef {import('@appium/types').Constraints} Constraints
419
- * @typedef {import('@appium/types').Constraint} Constraint
420
- * @typedef {import('@appium/types').StringRecord} StringRecord
421
- * @typedef {import('@appium/types').BaseDriverCapConstraints} BaseDriverCapConstraints
422
- * @typedef {import('@appium/types').ServerArgs} ServerArgs
423
- */
424
-
425
- /**
426
- * @callback UpdateServerCallback
427
- * @param {import('express').Express} app - Express app
428
- * @param {import('@appium/types').AppiumServer} httpServer - HTTP server
429
- * @returns {import('type-fest').Promisable<void>}
430
- */
431
-
432
- /**
433
- * This is used to extend {@linkcode BaseDriver} by the mixins and also external drivers.
434
- * @template {Constraints} C
435
- * @template [Proto={}]
436
- * @template [Static={}]
437
- * @typedef {import('@appium/types').Class<BaseDriver<C> & Proto,import('@appium/types').DriverStatic & Static>} BaseDriverBase
438
- */
439
-
440
- /**
441
- * @template {Constraints} [C=BaseDriverCapConstraints]
442
- * @typedef {import('@appium/types').SessionHandler<[string, object],void, C>} SessionHandler
443
- */
444
-
445
- /**
446
- * @template {Constraints} [C=BaseDriverCapConstraints]
447
- * @template {StringRecord|void} [Extra=void]
448
- * @typedef {import('@appium/types').Capabilities<C, Extra>} Capabilities
449
- */
450
-
451
- /**
452
- * @template {Constraints} [C=BaseDriverCapConstraints]
453
- * @template {StringRecord|void} [Extra=void]
454
- * @typedef {import('@appium/types').W3CCapabilities<C, Extra>} W3CCapabilities
455
- */
456
-
457
- /**
458
- * @template {Constraints} [C=BaseDriverCapConstraints]
459
- * @template {StringRecord} [CArgs=StringRecord]
460
- * @typedef {import('@appium/types').Driver<C, CArgs>} Driver
461
- */
462
-
463
- /**
464
- * @template {Constraints} C
465
- * @typedef {import('@appium/types').ExternalDriver<C>} ExternalDriver
466
- */
467
-
468
- /**
469
- * @template {Constraints} C
470
- * @typedef {import('@appium/types').DriverOpts<C>} DriverOpts
471
- */