@appium/base-driver 8.7.1 → 8.7.3

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 +323 -28
  29. package/build/lib/basedriver/driver.d.ts.map +1 -1
  30. package/build/lib/basedriver/driver.js +27 -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 +113 -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,67 @@ 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} [CArgs=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 {CArgs & 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
+ static BASE_DESIRED_CAP_CONSTRAINTS = BASE_DESIRED_CAP_CONSTRAINTS;
60
+
61
+ /**
62
+ *
63
+ * @param {DriverOpts<C>} opts
64
+ * @param {boolean} shouldValidateCaps
65
+ */
66
+ constructor(opts = /** @type {DriverOpts<C>} */ ({}), shouldValidateCaps = true) {
67
+ super(opts, shouldValidateCaps);
68
+
69
+ /**
70
+ * This must be assigned here because the declaration of {@linkcode BaseDriverCore.opts} above
71
+ * blows away {@linkcode DriverCore.opts}.
72
+ */
73
+ this.opts = opts;
74
+ }
75
+
76
+ /**
77
+ * Contains the base constraints plus whatever the subclass wants to add.
78
+ *
79
+ * Subclasses _shouldn't_ need to use this. If you need to use this, please create
80
+ * an issue:
81
+ * @see https://github.com/appium/appium/issues/new
82
+ * @type {Readonly<BaseDriverCapConstraints & C>}
83
+ * @protected
84
+ */
85
+ get _desiredCapConstraints() {
86
+ return Object.freeze(_.merge({}, BASE_DESIRED_CAP_CONSTRAINTS, this.desiredCapConstraints));
87
+ }
88
+
36
89
  // This is the main command handler for the driver. It wraps command
37
90
  // execution with timeout logic, checking that we have a valid session,
38
91
  // and ensuring that we execute commands one at a time. This method is called
@@ -114,7 +167,7 @@ export class BaseDriverCore extends DriverCore {
114
167
 
115
168
  /**
116
169
  *
117
- * @param {Error} err
170
+ * @param {Error|import('../protocol/errors').NoSuchDriverError} err
118
171
  */
119
172
  async startUnexpectedShutdown(
120
173
  err = new errors.NoSuchDriverError('The driver was unexpectedly shut down!')
@@ -208,11 +261,11 @@ export class BaseDriverCore extends DriverCore {
208
261
  * Appium 2 has dropped the support of these, so now we only accept capability
209
262
  * objects in W3C format and thus allow any of the three arguments to represent
210
263
  * the latter.
211
- * @param {W3CCapabilities} w3cCapabilities1
212
- * @param {W3CCapabilities} [w3cCapabilities2]
213
- * @param {W3CCapabilities} [w3cCapabilities]
264
+ * @param {W3CCapabilities<C>} w3cCapabilities1
265
+ * @param {W3CCapabilities<C>} [w3cCapabilities2]
266
+ * @param {W3CCapabilities<C>} [w3cCapabilities]
214
267
  * @param {DriverData[]} [driverData]
215
- * @returns {Promise<[string,object]>}
268
+ * @returns {Promise<[string,Capabilities<C>]>}
216
269
  */
217
270
  async createSession(w3cCapabilities1, w3cCapabilities2, w3cCapabilities, driverData) {
218
271
  if (this.sessionId !== null) {
@@ -235,21 +288,26 @@ export class BaseDriverCore extends DriverCore {
235
288
 
236
289
  this.setProtocolW3C();
237
290
 
238
- this.originalCaps = _.cloneDeep(originalCaps);
291
+ this.originalCaps = originalCaps;
239
292
  this.log.debug(
240
293
  `Creating session with W3C capabilities: ${JSON.stringify(originalCaps, null, 2)}`
241
294
  );
242
295
 
296
+ /** @type {Capabilities<C>} */
243
297
  let caps;
244
298
  try {
245
- caps = processCapabilities(originalCaps, this.desiredCapConstraints, this.shouldValidateCaps);
299
+ caps = processCapabilities(
300
+ originalCaps,
301
+ this._desiredCapConstraints,
302
+ this.shouldValidateCaps
303
+ );
246
304
  if (caps[APPIUM_OPTS_CAP]) {
247
305
  this.log.debug(
248
306
  `Found ${PREFIXED_APPIUM_OPTS_CAP} capability present; will promote items inside to caps`
249
307
  );
250
308
  caps = promoteAppiumOptions(caps);
251
309
  }
252
- caps = fixCaps(caps, this.desiredCapConstraints, this.log);
310
+ caps = fixCaps(caps, this._desiredCapConstraints, this.log);
253
311
  } catch (e) {
254
312
  throw new errors.SessionNotCreatedError(e.message);
255
313
  }
@@ -258,10 +316,8 @@ export class BaseDriverCore extends DriverCore {
258
316
 
259
317
  this.sessionId = util.uuidV4();
260
318
  this.caps = caps;
261
- this.opts = _.cloneDeep(this.initialOpts);
262
-
263
319
  // merge caps onto opts so we don't need to worry about what's where
264
- Object.assign(this.opts, this.caps);
320
+ this.opts = {..._.cloneDeep(this.initialOpts), ...this.caps};
265
321
 
266
322
  // deal with resets
267
323
  // some people like to do weird things by setting noReset and fullReset
@@ -288,7 +344,7 @@ export class BaseDriverCore extends DriverCore {
288
344
  }
289
345
 
290
346
  if (!_.isUndefined(this.caps.newCommandTimeout)) {
291
- this.newCommandTimeoutMs = this.caps.newCommandTimeout * 1000;
347
+ this.newCommandTimeoutMs = /** @type {number} */ (this.caps.newCommandTimeout) * 1000;
292
348
  }
293
349
 
294
350
  this._log.prefix = helpers.generateDriverLogPrefix(this, this.sessionId);
@@ -323,7 +379,7 @@ export class BaseDriverCore extends DriverCore {
323
379
  * @param {Capabilities} caps
324
380
  */
325
381
  logExtraCaps(caps) {
326
- let extraCaps = _.difference(_.keys(caps), _.keys(this._constraints));
382
+ let extraCaps = _.difference(_.keys(caps), _.keys(this._desiredCapConstraints));
327
383
  if (extraCaps.length) {
328
384
  this.log.warn(
329
385
  `The following capabilities were provided, but are not ` + `recognized by Appium:`
@@ -336,7 +392,7 @@ export class BaseDriverCore extends DriverCore {
336
392
 
337
393
  /**
338
394
  *
339
- * @param {Capabilities} caps
395
+ * @param {Capabilities<C>} caps
340
396
  * @returns {boolean}
341
397
  */
342
398
  validateDesiredCaps(caps) {
@@ -345,7 +401,7 @@ export class BaseDriverCore extends DriverCore {
345
401
  }
346
402
 
347
403
  try {
348
- validateCaps(caps, this._constraints);
404
+ validateCaps(caps, this._desiredCapConstraints);
349
405
  } catch (e) {
350
406
  this.log.errorAndThrow(
351
407
  new errors.SessionNotCreatedError(
@@ -359,47 +415,25 @@ export class BaseDriverCore extends DriverCore {
359
415
 
360
416
  return true;
361
417
  }
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
418
  }
381
419
 
382
420
  /**
383
421
  * 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>}
422
+ * @template {Constraints} [C={}]
423
+ * @implements {Driver<C>}
390
424
  */
391
- const BaseDriver = _BaseDriver;
392
-
393
- export {BaseDriver};
425
+ export class BaseDriver extends createBaseDriverClass(BaseDriverCore) {}
394
426
  export default BaseDriver;
395
427
 
396
428
  /**
397
429
  * @typedef {import('@appium/types').HTTPMethod} HTTPMethod
398
- * @typedef {import('@appium/types').Driver} Driver
399
430
  * @typedef {import('@appium/types').ExternalDriver} ExternalDriver
400
- * @typedef {import('@appium/types').Capabilities} Capabilities
401
- * @typedef {import('@appium/types').W3CCapabilities} W3CCapabilities
402
431
  * @typedef {import('@appium/types').DriverData} DriverData
432
+ * @typedef {import('@appium/types').Constraints} Constraints
433
+ * @typedef {import('@appium/types').Constraint} Constraint
434
+ * @typedef {import('@appium/types').StringRecord} StringRecord
435
+ * @typedef {import('@appium/types').BaseDriverCapConstraints} BaseDriverCapConstraints
436
+ * @typedef {import('@appium/types').ServerArgs} ServerArgs
403
437
  */
404
438
 
405
439
  /**
@@ -417,5 +451,33 @@ export default BaseDriver;
417
451
  */
418
452
 
419
453
  /**
420
- * @typedef {import('@appium/types').SessionHandler<[string, object],void>} SessionHandler
454
+ * @template {Constraints} [C=BaseDriverCapConstraints]
455
+ * @typedef {import('@appium/types').SessionHandler<[string, object],void, C>} SessionHandler
456
+ */
457
+
458
+ /**
459
+ * @template {Constraints} [C=BaseDriverCapConstraints]
460
+ * @template {StringRecord|void} [Extra=void]
461
+ * @typedef {import('@appium/types').Capabilities<C, Extra>} Capabilities
462
+ */
463
+
464
+ /**
465
+ * @template {Constraints} [C=BaseDriverCapConstraints]
466
+ * @template {StringRecord|void} [Extra=void]
467
+ * @typedef {import('@appium/types').W3CCapabilities<C, Extra>} W3CCapabilities
468
+ */
469
+
470
+ /**
471
+ * @template {Constraints} C
472
+ * @typedef {import('@appium/types').ConstraintsToCaps<C>} ConstraintsToCaps
473
+ */
474
+
475
+ /**
476
+ * @template {Constraints} C
477
+ * @typedef {import('@appium/types').Driver<C>} Driver
478
+ */
479
+
480
+ /**
481
+ * @template {Constraints} C
482
+ * @typedef {import('@appium/types').DriverOpts<C>} DriverOpts
421
483
  */
@@ -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.3",
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.1",
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": "6b3cc1a8743f78c1f50320364f25f3011d2b2136"
82
81
  }