@appium/base-driver 8.7.1 → 8.7.2

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 (84) hide show
  1. package/build/lib/basedriver/capabilities.d.ts +207 -42
  2. package/build/lib/basedriver/capabilities.d.ts.map +1 -1
  3. package/build/lib/basedriver/capabilities.js +39 -44
  4. package/build/lib/basedriver/capabilities.js.map +1 -0
  5. package/build/lib/basedriver/commands/event.js +3 -3
  6. package/build/lib/basedriver/commands/event.js.map +1 -0
  7. package/build/lib/basedriver/commands/execute.js +3 -3
  8. package/build/lib/basedriver/commands/execute.js.map +1 -0
  9. package/build/lib/basedriver/commands/find.js.map +1 -0
  10. package/build/lib/basedriver/commands/index.js.map +1 -0
  11. package/build/lib/basedriver/commands/log.js +3 -3
  12. package/build/lib/basedriver/commands/log.js.map +1 -0
  13. package/build/lib/basedriver/commands/session.js +3 -3
  14. package/build/lib/basedriver/commands/session.js.map +1 -0
  15. package/build/lib/basedriver/commands/settings.js.map +1 -0
  16. package/build/lib/basedriver/commands/timeout.js +3 -3
  17. package/build/lib/basedriver/commands/timeout.js.map +1 -0
  18. package/build/lib/basedriver/core.d.ts +171 -20
  19. package/build/lib/basedriver/core.d.ts.map +1 -1
  20. package/build/lib/basedriver/core.js +4 -6
  21. package/build/lib/basedriver/core.js.map +1 -0
  22. package/build/lib/basedriver/desired-caps.d.ts +0 -2
  23. package/build/lib/basedriver/desired-caps.d.ts.map +1 -1
  24. package/build/lib/basedriver/desired-caps.js +4 -53
  25. package/build/lib/basedriver/desired-caps.js.map +1 -0
  26. package/build/lib/basedriver/device-settings.js +3 -3
  27. package/build/lib/basedriver/device-settings.js.map +1 -0
  28. package/build/lib/basedriver/driver.d.ts +318 -28
  29. package/build/lib/basedriver/driver.d.ts.map +1 -1
  30. package/build/lib/basedriver/driver.js +23 -30
  31. package/build/lib/basedriver/driver.js.map +1 -0
  32. package/build/lib/basedriver/helpers.d.ts +1 -1
  33. package/build/lib/basedriver/helpers.d.ts.map +1 -1
  34. package/build/lib/basedriver/helpers.js +3 -3
  35. package/build/lib/basedriver/helpers.js.map +1 -0
  36. package/build/lib/basedriver/logger.js.map +1 -0
  37. package/build/lib/constants.js.map +1 -0
  38. package/build/lib/express/crash.js.map +1 -0
  39. package/build/lib/express/express-logging.js +3 -3
  40. package/build/lib/express/express-logging.js.map +1 -0
  41. package/build/lib/express/idempotency.js +3 -3
  42. package/build/lib/express/idempotency.js.map +1 -0
  43. package/build/lib/express/logger.js.map +1 -0
  44. package/build/lib/express/middleware.js +3 -3
  45. package/build/lib/express/middleware.js.map +1 -0
  46. package/build/lib/express/server.js +3 -3
  47. package/build/lib/express/server.js.map +1 -0
  48. package/build/lib/express/static.js +3 -3
  49. package/build/lib/express/static.js.map +1 -0
  50. package/build/lib/express/websocket.js +3 -3
  51. package/build/lib/express/websocket.js.map +1 -0
  52. package/build/lib/helpers/capabilities.d.ts +66 -5
  53. package/build/lib/helpers/capabilities.d.ts.map +1 -1
  54. package/build/lib/helpers/capabilities.js +7 -7
  55. package/build/lib/helpers/capabilities.js.map +1 -0
  56. package/build/lib/index.d.ts +1 -1
  57. package/build/lib/index.d.ts.map +1 -1
  58. package/build/lib/index.js +10 -3
  59. package/build/lib/index.js.map +1 -0
  60. package/build/lib/jsonwp-proxy/protocol-converter.js +3 -3
  61. package/build/lib/jsonwp-proxy/protocol-converter.js.map +1 -0
  62. package/build/lib/jsonwp-proxy/proxy.js +3 -3
  63. package/build/lib/jsonwp-proxy/proxy.js.map +1 -0
  64. package/build/lib/jsonwp-status/status.js +3 -3
  65. package/build/lib/jsonwp-status/status.js.map +1 -0
  66. package/build/lib/protocol/errors.js +3 -3
  67. package/build/lib/protocol/errors.js.map +1 -0
  68. package/build/lib/protocol/helpers.js +3 -3
  69. package/build/lib/protocol/helpers.js.map +1 -0
  70. package/build/lib/protocol/index.js.map +1 -0
  71. package/build/lib/protocol/protocol.js +3 -3
  72. package/build/lib/protocol/protocol.js.map +1 -0
  73. package/build/lib/protocol/routes.js +3 -3
  74. package/build/lib/protocol/routes.js.map +1 -0
  75. package/build/lib/protocol/validators.js +3 -3
  76. package/build/lib/protocol/validators.js.map +1 -0
  77. package/build/tsconfig.tsbuildinfo +1 -1
  78. package/lib/basedriver/capabilities.js +151 -93
  79. package/lib/basedriver/core.js +34 -18
  80. package/lib/basedriver/desired-caps.js +1 -53
  81. package/lib/basedriver/driver.js +98 -51
  82. package/lib/helpers/capabilities.js +19 -9
  83. package/lib/index.js +1 -0
  84. package/package.json +9 -10
@@ -16,7 +16,7 @@ import {fixCaps, isW3cCaps} from '../helpers/capabilities';
16
16
  import {DELETE_SESSION_COMMAND, determineProtocol, errors} from '../protocol';
17
17
  import {createBaseDriverClass} from './commands';
18
18
  import helpers from './helpers';
19
- import {desiredCapabilityConstraints} from './desired-caps';
19
+ import {BASE_DESIRED_CAP_CONSTRAINTS} from '@appium/types';
20
20
 
21
21
  const EVENT_SESSION_INIT = 'newSessionRequested';
22
22
  const EVENT_SESSION_START = 'newSessionStarted';
@@ -25,14 +25,52 @@ const EVENT_SESSION_QUIT_DONE = 'quitSessionFinished';
25
25
  const ON_UNEXPECTED_SHUTDOWN_EVENT = 'onUnexpectedShutdown';
26
26
 
27
27
  /**
28
- * @implements {SessionHandler}
28
+ * @implements {SessionHandler<C>}
29
+ * @template {Constraints} C
30
+ * @template {StringRecord} [A=StringRecord]
31
+ * @extends {DriverCore<C>}
29
32
  */
30
33
  export class BaseDriverCore extends DriverCore {
31
- _constraints = _.cloneDeep(desiredCapabilityConstraints);
32
-
33
- /** @type {Record<string,any>|undefined} */
34
+ /**
35
+ * @type {A & ServerArgs}
36
+ */
34
37
  cliArgs;
35
38
 
39
+ /**
40
+ * @type {Capabilities<C>}
41
+ */
42
+ caps;
43
+
44
+ /**
45
+ * @type {W3CCapabilities<C>}
46
+ */
47
+ originalCaps;
48
+
49
+ /**
50
+ * @type {C}
51
+ */
52
+ desiredCapConstraints;
53
+
54
+ /**
55
+ * @type {DriverOpts<C> & DriverOpts<BaseDriverCapConstraints>}
56
+ */
57
+ opts;
58
+
59
+ /**
60
+ * Contains the base constraints plus whatever the subclass wants to add.
61
+ *
62
+ * Subclasses _shouldn't_ need to use this. If you need to use this, please create
63
+ * an issue:
64
+ * @see https://github.com/appium/appium/issues/new
65
+ * @type {Readonly<BaseDriverCapConstraints & C>}
66
+ * @protected
67
+ */
68
+ get _desiredCapConstraints() {
69
+ return Object.freeze(_.merge({}, BASE_DESIRED_CAP_CONSTRAINTS, this.desiredCapConstraints));
70
+ }
71
+
72
+ static BASE_DESIRED_CAP_CONSTRAINTS = BASE_DESIRED_CAP_CONSTRAINTS;
73
+
36
74
  // This is the main command handler for the driver. It wraps command
37
75
  // execution with timeout logic, checking that we have a valid session,
38
76
  // and ensuring that we execute commands one at a time. This method is called
@@ -114,7 +152,7 @@ export class BaseDriverCore extends DriverCore {
114
152
 
115
153
  /**
116
154
  *
117
- * @param {Error} err
155
+ * @param {Error|import('../protocol/errors').NoSuchDriverError} err
118
156
  */
119
157
  async startUnexpectedShutdown(
120
158
  err = new errors.NoSuchDriverError('The driver was unexpectedly shut down!')
@@ -208,11 +246,11 @@ export class BaseDriverCore extends DriverCore {
208
246
  * Appium 2 has dropped the support of these, so now we only accept capability
209
247
  * objects in W3C format and thus allow any of the three arguments to represent
210
248
  * the latter.
211
- * @param {W3CCapabilities} w3cCapabilities1
212
- * @param {W3CCapabilities} [w3cCapabilities2]
213
- * @param {W3CCapabilities} [w3cCapabilities]
249
+ * @param {W3CCapabilities<C>} w3cCapabilities1
250
+ * @param {W3CCapabilities<C>} [w3cCapabilities2]
251
+ * @param {W3CCapabilities<C>} [w3cCapabilities]
214
252
  * @param {DriverData[]} [driverData]
215
- * @returns {Promise<[string,object]>}
253
+ * @returns {Promise<[string,Capabilities<C>]>}
216
254
  */
217
255
  async createSession(w3cCapabilities1, w3cCapabilities2, w3cCapabilities, driverData) {
218
256
  if (this.sessionId !== null) {
@@ -235,21 +273,26 @@ export class BaseDriverCore extends DriverCore {
235
273
 
236
274
  this.setProtocolW3C();
237
275
 
238
- this.originalCaps = _.cloneDeep(originalCaps);
276
+ this.originalCaps = originalCaps;
239
277
  this.log.debug(
240
278
  `Creating session with W3C capabilities: ${JSON.stringify(originalCaps, null, 2)}`
241
279
  );
242
280
 
281
+ /** @type {Capabilities<C>} */
243
282
  let caps;
244
283
  try {
245
- caps = processCapabilities(originalCaps, this.desiredCapConstraints, this.shouldValidateCaps);
284
+ caps = processCapabilities(
285
+ originalCaps,
286
+ this._desiredCapConstraints,
287
+ this.shouldValidateCaps
288
+ );
246
289
  if (caps[APPIUM_OPTS_CAP]) {
247
290
  this.log.debug(
248
291
  `Found ${PREFIXED_APPIUM_OPTS_CAP} capability present; will promote items inside to caps`
249
292
  );
250
293
  caps = promoteAppiumOptions(caps);
251
294
  }
252
- caps = fixCaps(caps, this.desiredCapConstraints, this.log);
295
+ caps = fixCaps(caps, this._desiredCapConstraints, this.log);
253
296
  } catch (e) {
254
297
  throw new errors.SessionNotCreatedError(e.message);
255
298
  }
@@ -258,10 +301,8 @@ export class BaseDriverCore extends DriverCore {
258
301
 
259
302
  this.sessionId = util.uuidV4();
260
303
  this.caps = caps;
261
- this.opts = _.cloneDeep(this.initialOpts);
262
-
263
304
  // merge caps onto opts so we don't need to worry about what's where
264
- Object.assign(this.opts, this.caps);
305
+ this.opts = {..._.cloneDeep(this.initialOpts), ...this.caps};
265
306
 
266
307
  // deal with resets
267
308
  // some people like to do weird things by setting noReset and fullReset
@@ -288,7 +329,7 @@ export class BaseDriverCore extends DriverCore {
288
329
  }
289
330
 
290
331
  if (!_.isUndefined(this.caps.newCommandTimeout)) {
291
- this.newCommandTimeoutMs = this.caps.newCommandTimeout * 1000;
332
+ this.newCommandTimeoutMs = /** @type {number} */ (this.caps.newCommandTimeout) * 1000;
292
333
  }
293
334
 
294
335
  this._log.prefix = helpers.generateDriverLogPrefix(this, this.sessionId);
@@ -323,7 +364,7 @@ export class BaseDriverCore extends DriverCore {
323
364
  * @param {Capabilities} caps
324
365
  */
325
366
  logExtraCaps(caps) {
326
- let extraCaps = _.difference(_.keys(caps), _.keys(this._constraints));
367
+ let extraCaps = _.difference(_.keys(caps), _.keys(this._desiredCapConstraints));
327
368
  if (extraCaps.length) {
328
369
  this.log.warn(
329
370
  `The following capabilities were provided, but are not ` + `recognized by Appium:`
@@ -336,7 +377,7 @@ export class BaseDriverCore extends DriverCore {
336
377
 
337
378
  /**
338
379
  *
339
- * @param {Capabilities} caps
380
+ * @param {Capabilities<C>} caps
340
381
  * @returns {boolean}
341
382
  */
342
383
  validateDesiredCaps(caps) {
@@ -345,7 +386,7 @@ export class BaseDriverCore extends DriverCore {
345
386
  }
346
387
 
347
388
  try {
348
- validateCaps(caps, this._constraints);
389
+ validateCaps(caps, this._desiredCapConstraints);
349
390
  } catch (e) {
350
391
  this.log.errorAndThrow(
351
392
  new errors.SessionNotCreatedError(
@@ -359,47 +400,25 @@ export class BaseDriverCore extends DriverCore {
359
400
 
360
401
  return true;
361
402
  }
362
-
363
- // we only want subclasses to ever extend the contraints
364
- set desiredCapConstraints(constraints) {
365
- this._constraints = Object.assign(this._constraints, constraints);
366
- // 'presence' means different things in different versions of the validator,
367
- // when we say 'true' we mean that it should not be able to be empty
368
- for (const [, value] of _.toPairs(this._constraints)) {
369
- if (value && value.presence === true) {
370
- value.presence = {
371
- allowEmpty: false,
372
- };
373
- }
374
- }
375
- }
376
-
377
- get desiredCapConstraints() {
378
- return this._constraints;
379
- }
380
403
  }
381
404
 
382
405
  /**
383
406
  * This ensures that all of the mixins correctly implement the interface described in {@linkcode Driver}.
384
- * @implements {Driver}
385
- */
386
- class _BaseDriver extends createBaseDriverClass(BaseDriverCore) {}
387
-
388
- /**
389
- * @type {import('@appium/types').DriverClass<Driver>}
407
+ * @template {Constraints} [C={}]
408
+ * @implements {Driver<C>}
390
409
  */
391
- const BaseDriver = _BaseDriver;
392
-
393
- export {BaseDriver};
410
+ export class BaseDriver extends createBaseDriverClass(BaseDriverCore) {}
394
411
  export default BaseDriver;
395
412
 
396
413
  /**
397
414
  * @typedef {import('@appium/types').HTTPMethod} HTTPMethod
398
- * @typedef {import('@appium/types').Driver} Driver
399
415
  * @typedef {import('@appium/types').ExternalDriver} ExternalDriver
400
- * @typedef {import('@appium/types').Capabilities} Capabilities
401
- * @typedef {import('@appium/types').W3CCapabilities} W3CCapabilities
402
416
  * @typedef {import('@appium/types').DriverData} DriverData
417
+ * @typedef {import('@appium/types').Constraints} Constraints
418
+ * @typedef {import('@appium/types').Constraint} Constraint
419
+ * @typedef {import('@appium/types').StringRecord} StringRecord
420
+ * @typedef {import('@appium/types').BaseDriverCapConstraints} BaseDriverCapConstraints
421
+ * @typedef {import('@appium/types').ServerArgs} ServerArgs
403
422
  */
404
423
 
405
424
  /**
@@ -417,5 +436,33 @@ export default BaseDriver;
417
436
  */
418
437
 
419
438
  /**
420
- * @typedef {import('@appium/types').SessionHandler<[string, object],void>} SessionHandler
439
+ * @template {Constraints} [C=BaseDriverCapConstraints]
440
+ * @typedef {import('@appium/types').SessionHandler<[string, object],void, C>} SessionHandler
441
+ */
442
+
443
+ /**
444
+ * @template {Constraints} [C=BaseDriverCapConstraints]
445
+ * @template {StringRecord|void} [Extra=void]
446
+ * @typedef {import('@appium/types').Capabilities<C, Extra>} Capabilities
447
+ */
448
+
449
+ /**
450
+ * @template {Constraints} [C=BaseDriverCapConstraints]
451
+ * @template {StringRecord|void} [Extra=void]
452
+ * @typedef {import('@appium/types').W3CCapabilities<C, Extra>} W3CCapabilities
453
+ */
454
+
455
+ /**
456
+ * @template {Constraints} C
457
+ * @typedef {import('@appium/types').ConstraintsToCaps<C>} ConstraintsToCaps
458
+ */
459
+
460
+ /**
461
+ * @template {Constraints} C
462
+ * @typedef {import('@appium/types').Driver<C>} Driver
463
+ */
464
+
465
+ /**
466
+ * @template {Constraints} C
467
+ * @typedef {import('@appium/types').DriverOpts<C>} DriverOpts
421
468
  */
@@ -26,19 +26,20 @@ function isW3cCaps(caps) {
26
26
 
27
27
  /**
28
28
  *
29
- * @param {Capabilities} originalCaps
30
- * @param {Constraints} desiredCapConstraints
29
+ * @template {Constraints} C
30
+ * @param {any} oldCaps
31
+ * @param {C} desiredCapConstraints
31
32
  * @param {AppiumLogger} log
32
- * @returns {Capabilities}
33
+ * @returns {Capabilities<C>}
33
34
  */
34
- function fixCaps(originalCaps, desiredCapConstraints, log) {
35
- let caps = _.clone(originalCaps);
35
+ function fixCaps(oldCaps, desiredCapConstraints, log) {
36
+ let caps = _.clone(oldCaps);
36
37
 
37
38
  // boolean capabilities can be passed in as strings 'false' and 'true'
38
39
  // which we want to translate into boolean values
39
40
  let booleanCaps = _.keys(_.pickBy(desiredCapConstraints, (k) => k.isBoolean === true));
40
41
  for (let cap of booleanCaps) {
41
- let value = originalCaps[cap];
42
+ let value = oldCaps[cap];
42
43
  if (_.isString(value)) {
43
44
  value = value.toLowerCase();
44
45
  if (value === 'true' || value === 'false') {
@@ -51,9 +52,11 @@ function fixCaps(originalCaps, desiredCapConstraints, log) {
51
52
  }
52
53
 
53
54
  // int capabilities are often sent in as strings by frameworks
54
- let intCaps = _.keys(_.pickBy(desiredCapConstraints, (k) => k.isNumber === true));
55
+ let intCaps = /** @type {import('type-fest').StringKeyOf<typeof caps>[]} */ (
56
+ _.keys(_.pickBy(desiredCapConstraints, (k) => k.isNumber === true))
57
+ );
55
58
  for (let cap of intCaps) {
56
- let value = originalCaps[cap];
59
+ let value = oldCaps[cap];
57
60
  if (_.isString(value)) {
58
61
  value = value.trim();
59
62
  let newValue = parseInt(value, 10);
@@ -73,7 +76,14 @@ function fixCaps(originalCaps, desiredCapConstraints, log) {
73
76
  export {isW3cCaps, fixCaps};
74
77
 
75
78
  /**
76
- * @typedef {import('@appium/types').Capabilities} Capabilities
77
79
  * @typedef {import('@appium/types').Constraints} Constraints
78
80
  * @typedef {import('@appium/types').AppiumLogger} AppiumLogger
81
+ * @typedef {import('@appium/types').StringRecord} StringRecord
82
+ * @typedef {import('@appium/types').BaseDriverCapConstraints} BaseDriverCapConstraints
83
+ */
84
+
85
+ /**
86
+ * @template {Constraints} [C=BaseDriverCapConstraints]
87
+ * @template {StringRecord|void} [Extra=void]
88
+ * @typedef {import('@appium/types').Capabilities<C, Extra>} Capabilities
79
89
  */
package/lib/index.js CHANGED
@@ -30,6 +30,7 @@ export {getSummaryByCode, codes as statusCodes} from './jsonwp-status/status';
30
30
  // W3C capabilities parser
31
31
  export {
32
32
  PREFIXED_APPIUM_OPTS_CAP,
33
+ STANDARD_CAPS,
33
34
  processCapabilities,
34
35
  isStandardCap,
35
36
  validateCaps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/base-driver",
3
- "version": "8.7.1",
3
+ "version": "8.7.2",
4
4
  "description": "Base driver class for Appium drivers",
5
5
  "keywords": [
6
6
  "automation",
@@ -45,21 +45,20 @@
45
45
  "test:unit": "mocha \"./test/unit/**/*.spec.js\""
46
46
  },
47
47
  "dependencies": {
48
- "@appium/support": "^2.60.0",
49
- "@babel/runtime": "7.19.0",
48
+ "@appium/support": "^2.61.0",
50
49
  "@colors/colors": "1.5.0",
51
- "@types/async-lock": "1.1.5",
52
- "@types/bluebird": "3.5.36",
53
- "@types/express": "4.17.13",
50
+ "@types/async-lock": "1.3.0",
51
+ "@types/bluebird": "3.5.37",
52
+ "@types/express": "4.17.14",
54
53
  "@types/method-override": "0.0.32",
55
54
  "@types/serve-favicon": "2.5.3",
56
55
  "async-lock": "1.3.2",
57
56
  "asyncbox": "2.9.2",
58
57
  "axios": "0.27.2",
59
58
  "bluebird": "3.7.2",
60
- "body-parser": "1.20.0",
59
+ "body-parser": "1.20.1",
61
60
  "es6-error": "4.1.1",
62
- "express": "4.18.1",
61
+ "express": "4.18.2",
63
62
  "http-status-codes": "2.2.0",
64
63
  "lodash": "4.17.21",
65
64
  "lru-cache": "7.14.0",
@@ -67,7 +66,7 @@
67
66
  "morgan": "1.10.0",
68
67
  "serve-favicon": "2.5.0",
69
68
  "source-map-support": "0.5.21",
70
- "type-fest": "2.19.0",
69
+ "type-fest": "3.1.0",
71
70
  "validate.js": "0.13.1"
72
71
  },
73
72
  "engines": {
@@ -78,5 +77,5 @@
78
77
  "access": "public"
79
78
  },
80
79
  "types": "./build/lib/index.d.ts",
81
- "gitHead": "c26af8f85230ac65cbc19f08f763942f74b0eb0c"
80
+ "gitHead": "f545a6cde58d83f3289072f8957468793947ba66"
82
81
  }