@appium/base-driver 8.3.1 → 8.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.
Files changed (115) hide show
  1. package/build/lib/basedriver/capabilities.d.ts +80 -0
  2. package/build/lib/basedriver/capabilities.d.ts.map +1 -0
  3. package/build/lib/basedriver/capabilities.js +11 -10
  4. package/build/lib/basedriver/commands/event.d.ts +9 -0
  5. package/build/lib/basedriver/commands/event.d.ts.map +1 -0
  6. package/build/lib/basedriver/commands/event.js +21 -21
  7. package/build/lib/basedriver/commands/find.d.ts +11 -0
  8. package/build/lib/basedriver/commands/find.d.ts.map +1 -0
  9. package/build/lib/basedriver/commands/find.js +44 -37
  10. package/build/lib/basedriver/commands/index.d.ts +8 -0
  11. package/build/lib/basedriver/commands/index.d.ts.map +1 -0
  12. package/build/lib/basedriver/commands/index.js +17 -14
  13. package/build/lib/basedriver/commands/log.d.ts +12 -0
  14. package/build/lib/basedriver/commands/log.d.ts.map +1 -0
  15. package/build/lib/basedriver/commands/log.js +24 -26
  16. package/build/lib/basedriver/commands/session.d.ts +11 -0
  17. package/build/lib/basedriver/commands/session.d.ts.map +1 -0
  18. package/build/lib/basedriver/commands/session.js +21 -147
  19. package/build/lib/basedriver/commands/settings.d.ts +10 -0
  20. package/build/lib/basedriver/commands/settings.d.ts.map +1 -0
  21. package/build/lib/basedriver/commands/settings.js +19 -17
  22. package/build/lib/basedriver/commands/timeout.d.ts +8 -0
  23. package/build/lib/basedriver/commands/timeout.d.ts.map +1 -0
  24. package/build/lib/basedriver/commands/timeout.js +118 -137
  25. package/build/lib/basedriver/core.d.ts +235 -0
  26. package/build/lib/basedriver/core.d.ts.map +1 -0
  27. package/build/lib/basedriver/core.js +283 -0
  28. package/build/lib/basedriver/desired-caps.d.ts +5 -0
  29. package/build/lib/basedriver/desired-caps.d.ts.map +1 -0
  30. package/build/lib/basedriver/desired-caps.js +1 -1
  31. package/build/lib/basedriver/device-settings.d.ts +32 -0
  32. package/build/lib/basedriver/device-settings.d.ts.map +1 -0
  33. package/build/lib/basedriver/device-settings.js +19 -11
  34. package/build/lib/basedriver/driver.d.ts +83 -0
  35. package/build/lib/basedriver/driver.d.ts.map +1 -0
  36. package/build/lib/basedriver/driver.js +100 -266
  37. package/build/lib/basedriver/helpers.d.ts +132 -0
  38. package/build/lib/basedriver/helpers.d.ts.map +1 -0
  39. package/build/lib/basedriver/helpers.js +17 -1
  40. package/build/lib/basedriver/logger.d.ts +3 -0
  41. package/build/lib/basedriver/logger.d.ts.map +1 -0
  42. package/build/lib/constants.d.ts +9 -0
  43. package/build/lib/constants.d.ts.map +1 -0
  44. package/build/lib/express/crash.d.ts +3 -0
  45. package/build/lib/express/crash.d.ts.map +1 -0
  46. package/build/lib/express/express-logging.d.ts +3 -0
  47. package/build/lib/express/express-logging.d.ts.map +1 -0
  48. package/build/lib/express/idempotency.d.ts +2 -0
  49. package/build/lib/express/idempotency.d.ts.map +1 -0
  50. package/build/lib/express/logger.d.ts +3 -0
  51. package/build/lib/express/logger.d.ts.map +1 -0
  52. package/build/lib/express/middleware.d.ts +9 -0
  53. package/build/lib/express/middleware.d.ts.map +1 -0
  54. package/build/lib/express/server.d.ts +10 -0
  55. package/build/lib/express/server.d.ts.map +1 -0
  56. package/build/lib/express/static.d.ts +6 -0
  57. package/build/lib/express/static.d.ts.map +1 -0
  58. package/build/lib/express/websocket.d.ts +64 -0
  59. package/build/lib/express/websocket.d.ts.map +1 -0
  60. package/build/lib/helpers/capabilities.d.ts +13 -0
  61. package/build/lib/helpers/capabilities.d.ts.map +1 -0
  62. package/build/lib/helpers/capabilities.js +41 -1
  63. package/build/lib/index.d.ts +183 -0
  64. package/build/lib/index.d.ts.map +1 -0
  65. package/build/lib/index.js +40 -20
  66. package/build/lib/jsonwp-proxy/protocol-converter.d.ts +48 -0
  67. package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -0
  68. package/build/lib/jsonwp-proxy/proxy.d.ts +41 -0
  69. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -0
  70. package/build/lib/jsonwp-status/status.d.ts +159 -0
  71. package/build/lib/jsonwp-status/status.d.ts.map +1 -0
  72. package/build/lib/protocol/errors.d.ts +310 -0
  73. package/build/lib/protocol/errors.d.ts.map +1 -0
  74. package/build/lib/protocol/errors.js +81 -2
  75. package/build/lib/protocol/helpers.d.ts +22 -0
  76. package/build/lib/protocol/helpers.d.ts.map +1 -0
  77. package/build/lib/protocol/index.d.ts +16 -0
  78. package/build/lib/protocol/index.d.ts.map +1 -0
  79. package/build/lib/protocol/index.js +7 -7
  80. package/build/lib/protocol/protocol.d.ts +11 -0
  81. package/build/lib/protocol/protocol.d.ts.map +1 -0
  82. package/build/lib/protocol/protocol.js +2 -6
  83. package/build/lib/protocol/routes.d.ts +6 -0
  84. package/build/lib/protocol/routes.d.ts.map +1 -0
  85. package/build/lib/protocol/routes.js +17 -1
  86. package/build/lib/protocol/validators.d.ts +8 -0
  87. package/build/lib/protocol/validators.d.ts.map +1 -0
  88. package/build/test/basedriver/driver-tests.js +30 -3
  89. package/build/test/unit/basedriver/commands/event.spec.js +7 -7
  90. package/build/test/unit/basedriver/commands/log.spec.js +31 -24
  91. package/build/test/unit/basedriver/timeout.spec.js +1 -1
  92. package/build/test/unit/protocol/routes.spec.js +2 -2
  93. package/build/tsconfig.tsbuildinfo +1 -0
  94. package/lib/basedriver/capabilities.js +49 -10
  95. package/lib/basedriver/commands/event.js +49 -31
  96. package/lib/basedriver/commands/find.js +108 -43
  97. package/lib/basedriver/commands/index.js +25 -19
  98. package/lib/basedriver/commands/log.js +60 -33
  99. package/lib/basedriver/commands/session.js +39 -141
  100. package/lib/basedriver/commands/settings.js +33 -13
  101. package/lib/basedriver/commands/timeout.js +153 -153
  102. package/lib/basedriver/core.js +497 -0
  103. package/lib/basedriver/desired-caps.js +1 -1
  104. package/lib/basedriver/device-settings.js +47 -12
  105. package/lib/basedriver/driver.js +273 -395
  106. package/lib/basedriver/helpers.js +18 -2
  107. package/lib/helpers/capabilities.js +60 -1
  108. package/lib/index.js +16 -12
  109. package/lib/protocol/errors.js +42 -42
  110. package/lib/protocol/index.js +4 -4
  111. package/lib/protocol/protocol.js +1 -3
  112. package/lib/protocol/routes.js +9 -0
  113. package/package.json +10 -9
  114. package/test/basedriver/driver-tests.js +31 -2
  115. package/index.d.ts +0 -386
@@ -2,7 +2,7 @@ import _ from 'lodash';
2
2
  import path from 'path';
3
3
  import url from 'url';
4
4
  import logger from './logger';
5
- import { tempDir, fs, util, zip, net, timing } from '@appium/support';
5
+ import { tempDir, fs, util, zip, net, timing, node } from '@appium/support';
6
6
  import LRU from 'lru-cache';
7
7
  import AsyncLock from 'async-lock';
8
8
  import axios from 'axios';
@@ -546,6 +546,22 @@ function parseCapsArray (cap) {
546
546
  throw new Error(`must provide a string or JSON Array; received ${cap}`);
547
547
  }
548
548
 
549
+ /**
550
+ * Generate a string that uniquely describes driver instance
551
+ *
552
+ * @param {import('@appium/types').Core} obj driver instance
553
+ * @param {string?} sessionId session identifier (if exists)
554
+ * @returns {string}
555
+ */
556
+ function generateDriverLogPrefix (obj, sessionId = null) {
557
+ const instanceName = `${obj.constructor.name}@${node.getObjectId(obj).substring(0, 4)}`;
558
+ return sessionId ? `${instanceName} (${sessionId.substring(0, 8)})` : instanceName;
559
+ }
560
+
561
+ /** @type {import('@appium/types').DriverHelpers} */
562
+ export default {
563
+ configureApp, isPackageOrBundle, duplicateKeys, parseCapsArray, generateDriverLogPrefix
564
+ };
549
565
  export {
550
- configureApp, isPackageOrBundle, duplicateKeys, parseCapsArray
566
+ configureApp, isPackageOrBundle, duplicateKeys, parseCapsArray, generateDriverLogPrefix
551
567
  };
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  import _ from 'lodash';
2
4
 
3
5
  function isW3cCaps (caps) {
@@ -20,6 +22,63 @@ function isW3cCaps (caps) {
20
22
  return false;
21
23
  }
22
24
 
25
+ /**
26
+ *
27
+ * @param {Capabilities} originalCaps
28
+ * @param {Constraints} desiredCapConstraints
29
+ * @param {AppiumLogger} log
30
+ * @returns {Capabilities}
31
+ */
32
+ function fixCaps (originalCaps, desiredCapConstraints, log) {
33
+ let caps = _.clone(originalCaps);
34
+
35
+ // boolean capabilities can be passed in as strings 'false' and 'true'
36
+ // which we want to translate into boolean values
37
+ let booleanCaps = _.keys(
38
+ _.pickBy(desiredCapConstraints, (k) => k.isBoolean === true),
39
+ );
40
+ for (let cap of booleanCaps) {
41
+ let value = originalCaps[cap];
42
+ if (_.isString(value)) {
43
+ value = value.toLowerCase();
44
+ if (value === 'true' || value === 'false') {
45
+ log.warn(
46
+ `Capability '${cap}' changed from string to boolean. This may cause unexpected behavior`,
47
+ );
48
+ caps[cap] = value === 'true';
49
+ }
50
+ }
51
+ }
52
+
53
+ // int capabilities are often sent in as strings by frameworks
54
+ let intCaps = _.keys(
55
+ _.pickBy(desiredCapConstraints, (k) => k.isNumber === true),
56
+ );
57
+ for (let cap of intCaps) {
58
+ let value = originalCaps[cap];
59
+ if (_.isString(value)) {
60
+ value = value.trim();
61
+ let newValue = parseInt(value, 10);
62
+ if (value !== `${newValue}`) {
63
+ newValue = parseFloat(value);
64
+ }
65
+ log.warn(
66
+ `Capability '${cap}' changed from string ('${value}') to integer (${newValue}). This may cause unexpected behavior`,
67
+ );
68
+ caps[cap] = newValue;
69
+ }
70
+ }
71
+
72
+ return caps;
73
+ }
74
+
23
75
  export {
24
76
  isW3cCaps,
25
- };
77
+ fixCaps
78
+ };
79
+
80
+ /**
81
+ * @typedef {import('@appium/types').Capabilities} Capabilities
82
+ * @typedef {import('@appium/types').Constraints} Constraints
83
+ * @typedef {import('@appium/types').AppiumLogger} AppiumLogger
84
+ */
package/lib/index.js CHANGED
@@ -1,11 +1,15 @@
1
- // transpile:main
1
+ // @ts-check
2
2
 
3
- // BaseDriver exports
4
- import * as driver from './basedriver/driver';
5
- import * as deviceSettings from './basedriver/device-settings';
3
+ import B from 'bluebird';
4
+
5
+ B.config({
6
+ cancellation: true,
7
+ });
6
8
 
7
- const { BaseDriver } = driver;
8
- const { DeviceSettings } = deviceSettings;
9
+ // BaseDriver exports
10
+ import { BaseDriver } from './basedriver/driver';
11
+ export { DriverCore } from './basedriver/core';
12
+ import { DeviceSettings } from './basedriver/device-settings';
9
13
 
10
14
  export { BaseDriver, DeviceSettings };
11
15
  export default BaseDriver;
@@ -18,19 +22,19 @@ import {
18
22
  } from './constants';
19
23
 
20
24
  const {
21
- Protocol, routeConfiguringFunction, errors, isErrorType,
25
+ routeConfiguringFunction, errors, isErrorType,
22
26
  errorFromMJSONWPStatusCode, errorFromW3CJsonCode, ALL_COMMANDS, METHOD_MAP,
23
27
  routeToCommandName, NO_SESSION_ID_COMMANDS, isSessionCommand,
24
- normalizeBasePath, determineProtocol, CREATE_SESSION_COMMAND,
28
+ determineProtocol, CREATE_SESSION_COMMAND,
25
29
  DELETE_SESSION_COMMAND, GET_STATUS_COMMAND,
26
30
  } = protocol;
27
31
 
28
32
  export {
29
- Protocol, routeConfiguringFunction, errors, isErrorType, PROTOCOLS,
33
+ routeConfiguringFunction, errors, isErrorType, PROTOCOLS,
30
34
  errorFromMJSONWPStatusCode, errorFromW3CJsonCode, determineProtocol,
31
35
  errorFromMJSONWPStatusCode as errorFromCode, ALL_COMMANDS, METHOD_MAP,
32
36
  routeToCommandName, NO_SESSION_ID_COMMANDS, isSessionCommand,
33
- DEFAULT_BASE_PATH, normalizeBasePath, CREATE_SESSION_COMMAND,
37
+ DEFAULT_BASE_PATH, CREATE_SESSION_COMMAND,
34
38
  DELETE_SESSION_COMMAND, GET_STATUS_COMMAND,
35
39
  };
36
40
 
@@ -40,8 +44,8 @@ const { STATIC_DIR } = staticIndex;
40
44
  export { STATIC_DIR };
41
45
 
42
46
  import * as serverIndex from './express/server';
43
- const { server } = serverIndex;
44
- export { server };
47
+ const { server, normalizeBasePath } = serverIndex;
48
+ export { server, normalizeBasePath };
45
49
 
46
50
  // jsonwp-proxy exports
47
51
  import * as proxyIndex from './jsonwp-proxy/proxy';
@@ -9,7 +9,7 @@ const w3cLog = logger.getLogger('W3C');
9
9
  const W3C_UNKNOWN_ERROR = 'unknown error';
10
10
 
11
11
  // base error class for all of our errors
12
- class ProtocolError extends ES6Error {
12
+ export class ProtocolError extends ES6Error {
13
13
  constructor (msg, jsonwpCode, w3cStatus, error) {
14
14
  super(msg);
15
15
  this.jsonwpCode = jsonwpCode;
@@ -34,7 +34,7 @@ class ProtocolError extends ES6Error {
34
34
  // https://github.com/SeleniumHQ/selenium/issues/5562#issuecomment-370379470
35
35
  // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-error-code
36
36
 
37
- class NoSuchDriverError extends ProtocolError {
37
+ export class NoSuchDriverError extends ProtocolError {
38
38
  static code () {
39
39
  return 6;
40
40
  }
@@ -51,7 +51,7 @@ class NoSuchDriverError extends ProtocolError {
51
51
  }
52
52
  }
53
53
 
54
- class NoSuchElementError extends ProtocolError {
54
+ export class NoSuchElementError extends ProtocolError {
55
55
  static code () {
56
56
  return 7;
57
57
  }
@@ -68,7 +68,7 @@ class NoSuchElementError extends ProtocolError {
68
68
  }
69
69
  }
70
70
 
71
- class NoSuchFrameError extends ProtocolError {
71
+ export class NoSuchFrameError extends ProtocolError {
72
72
  static code () {
73
73
  return 8;
74
74
  }
@@ -85,7 +85,7 @@ class NoSuchFrameError extends ProtocolError {
85
85
  }
86
86
  }
87
87
 
88
- class UnknownCommandError extends ProtocolError {
88
+ export class UnknownCommandError extends ProtocolError {
89
89
  static code () {
90
90
  return 9;
91
91
  }
@@ -102,7 +102,7 @@ class UnknownCommandError extends ProtocolError {
102
102
  }
103
103
  }
104
104
 
105
- class StaleElementReferenceError extends ProtocolError {
105
+ export class StaleElementReferenceError extends ProtocolError {
106
106
  static code () {
107
107
  return 10;
108
108
  }
@@ -119,7 +119,7 @@ class StaleElementReferenceError extends ProtocolError {
119
119
  }
120
120
  }
121
121
 
122
- class ElementNotVisibleError extends ProtocolError {
122
+ export class ElementNotVisibleError extends ProtocolError {
123
123
  static code () {
124
124
  return 11;
125
125
  }
@@ -136,7 +136,7 @@ class ElementNotVisibleError extends ProtocolError {
136
136
  }
137
137
  }
138
138
 
139
- class InvalidElementStateError extends ProtocolError {
139
+ export class InvalidElementStateError extends ProtocolError {
140
140
  static code () {
141
141
  return 12;
142
142
  }
@@ -154,7 +154,7 @@ class InvalidElementStateError extends ProtocolError {
154
154
  }
155
155
  }
156
156
 
157
- class UnknownError extends ProtocolError {
157
+ export class UnknownError extends ProtocolError {
158
158
  static code () {
159
159
  return 13;
160
160
  }
@@ -174,7 +174,7 @@ class UnknownError extends ProtocolError {
174
174
  }
175
175
  }
176
176
 
177
- class UnknownMethodError extends ProtocolError {
177
+ export class UnknownMethodError extends ProtocolError {
178
178
  static code () {
179
179
  return 405;
180
180
  }
@@ -190,7 +190,7 @@ class UnknownMethodError extends ProtocolError {
190
190
  }
191
191
  }
192
192
 
193
- class UnsupportedOperationError extends ProtocolError {
193
+ export class UnsupportedOperationError extends ProtocolError {
194
194
  static code () {
195
195
  return 405;
196
196
  }
@@ -207,7 +207,7 @@ class UnsupportedOperationError extends ProtocolError {
207
207
  }
208
208
  }
209
209
 
210
- class ElementIsNotSelectableError extends ProtocolError {
210
+ export class ElementIsNotSelectableError extends ProtocolError {
211
211
  static code () {
212
212
  return 15;
213
213
  }
@@ -224,7 +224,7 @@ class ElementIsNotSelectableError extends ProtocolError {
224
224
  }
225
225
  }
226
226
 
227
- class ElementClickInterceptedError extends ProtocolError {
227
+ export class ElementClickInterceptedError extends ProtocolError {
228
228
  static code () {
229
229
  return 64;
230
230
  }
@@ -242,7 +242,7 @@ class ElementClickInterceptedError extends ProtocolError {
242
242
  }
243
243
  }
244
244
 
245
- class ElementNotInteractableError extends ProtocolError {
245
+ export class ElementNotInteractableError extends ProtocolError {
246
246
  static code () {
247
247
  return 60;
248
248
  }
@@ -259,7 +259,7 @@ class ElementNotInteractableError extends ProtocolError {
259
259
  }
260
260
  }
261
261
 
262
- class InsecureCertificateError extends ProtocolError {
262
+ export class InsecureCertificateError extends ProtocolError {
263
263
  static error () {
264
264
  return 'insecure certificate';
265
265
  }
@@ -269,7 +269,7 @@ class InsecureCertificateError extends ProtocolError {
269
269
  }
270
270
  }
271
271
 
272
- class JavaScriptError extends ProtocolError {
272
+ export class JavaScriptError extends ProtocolError {
273
273
  static code () {
274
274
  return 17;
275
275
  }
@@ -285,7 +285,7 @@ class JavaScriptError extends ProtocolError {
285
285
  }
286
286
  }
287
287
 
288
- class XPathLookupError extends ProtocolError {
288
+ export class XPathLookupError extends ProtocolError {
289
289
  static code () {
290
290
  return 19;
291
291
  }
@@ -301,7 +301,7 @@ class XPathLookupError extends ProtocolError {
301
301
  }
302
302
  }
303
303
 
304
- class TimeoutError extends ProtocolError {
304
+ export class TimeoutError extends ProtocolError {
305
305
  static code () {
306
306
  return 21;
307
307
  }
@@ -317,7 +317,7 @@ class TimeoutError extends ProtocolError {
317
317
  }
318
318
  }
319
319
 
320
- class NoSuchWindowError extends ProtocolError {
320
+ export class NoSuchWindowError extends ProtocolError {
321
321
  static code () {
322
322
  return 23;
323
323
  }
@@ -334,7 +334,7 @@ class NoSuchWindowError extends ProtocolError {
334
334
  }
335
335
  }
336
336
 
337
- class InvalidArgumentError extends ProtocolError {
337
+ export class InvalidArgumentError extends ProtocolError {
338
338
  static code () {
339
339
  return 61;
340
340
  }
@@ -351,7 +351,7 @@ class InvalidArgumentError extends ProtocolError {
351
351
  }
352
352
  }
353
353
 
354
- class InvalidCookieDomainError extends ProtocolError {
354
+ export class InvalidCookieDomainError extends ProtocolError {
355
355
  static code () {
356
356
  return 24;
357
357
  }
@@ -368,7 +368,7 @@ class InvalidCookieDomainError extends ProtocolError {
368
368
  }
369
369
  }
370
370
 
371
- class NoSuchCookieError extends ProtocolError {
371
+ export class NoSuchCookieError extends ProtocolError {
372
372
  static code () {
373
373
  return 62;
374
374
  }
@@ -384,7 +384,7 @@ class NoSuchCookieError extends ProtocolError {
384
384
  }
385
385
  }
386
386
 
387
- class UnableToSetCookieError extends ProtocolError {
387
+ export class UnableToSetCookieError extends ProtocolError {
388
388
  static code () {
389
389
  return 25;
390
390
  }
@@ -400,7 +400,7 @@ class UnableToSetCookieError extends ProtocolError {
400
400
  }
401
401
  }
402
402
 
403
- class UnexpectedAlertOpenError extends ProtocolError {
403
+ export class UnexpectedAlertOpenError extends ProtocolError {
404
404
  static code () {
405
405
  return 26;
406
406
  }
@@ -416,7 +416,7 @@ class UnexpectedAlertOpenError extends ProtocolError {
416
416
  }
417
417
  }
418
418
 
419
- class NoAlertOpenError extends ProtocolError {
419
+ export class NoAlertOpenError extends ProtocolError {
420
420
  static code () {
421
421
  return 27;
422
422
  }
@@ -432,9 +432,9 @@ class NoAlertOpenError extends ProtocolError {
432
432
  }
433
433
  }
434
434
 
435
- class NoSuchAlertError extends NoAlertOpenError {}
435
+ export class NoSuchAlertError extends NoAlertOpenError {}
436
436
 
437
- class ScriptTimeoutError extends ProtocolError {
437
+ export class ScriptTimeoutError extends ProtocolError {
438
438
  static code () {
439
439
  return 28;
440
440
  }
@@ -450,7 +450,7 @@ class ScriptTimeoutError extends ProtocolError {
450
450
  }
451
451
  }
452
452
 
453
- class InvalidElementCoordinatesError extends ProtocolError {
453
+ export class InvalidElementCoordinatesError extends ProtocolError {
454
454
  static code () {
455
455
  return 29;
456
456
  }
@@ -467,9 +467,9 @@ class InvalidElementCoordinatesError extends ProtocolError {
467
467
  }
468
468
  }
469
469
 
470
- class InvalidCoordinatesError extends InvalidElementCoordinatesError {}
470
+ export class InvalidCoordinatesError extends InvalidElementCoordinatesError {}
471
471
 
472
- class IMENotAvailableError extends ProtocolError {
472
+ export class IMENotAvailableError extends ProtocolError {
473
473
  static code () {
474
474
  return 30;
475
475
  }
@@ -485,7 +485,7 @@ class IMENotAvailableError extends ProtocolError {
485
485
  }
486
486
  }
487
487
 
488
- class IMEEngineActivationFailedError extends ProtocolError {
488
+ export class IMEEngineActivationFailedError extends ProtocolError {
489
489
  static code () {
490
490
  return 31;
491
491
  }
@@ -502,7 +502,7 @@ class IMEEngineActivationFailedError extends ProtocolError {
502
502
  }
503
503
  }
504
504
 
505
- class InvalidSelectorError extends ProtocolError {
505
+ export class InvalidSelectorError extends ProtocolError {
506
506
  static code () {
507
507
  return 32;
508
508
  }
@@ -519,7 +519,7 @@ class InvalidSelectorError extends ProtocolError {
519
519
  }
520
520
  }
521
521
 
522
- class SessionNotCreatedError extends ProtocolError {
522
+ export class SessionNotCreatedError extends ProtocolError {
523
523
  static code () {
524
524
  return 33;
525
525
  }
@@ -539,7 +539,7 @@ class SessionNotCreatedError extends ProtocolError {
539
539
  }
540
540
  }
541
541
 
542
- class MoveTargetOutOfBoundsError extends ProtocolError {
542
+ export class MoveTargetOutOfBoundsError extends ProtocolError {
543
543
  static code () {
544
544
  return 34;
545
545
  }
@@ -555,7 +555,7 @@ class MoveTargetOutOfBoundsError extends ProtocolError {
555
555
  }
556
556
  }
557
557
 
558
- class NoSuchContextError extends ProtocolError {
558
+ export class NoSuchContextError extends ProtocolError {
559
559
  static code () {
560
560
  return 35;
561
561
  }
@@ -564,7 +564,7 @@ class NoSuchContextError extends ProtocolError {
564
564
  }
565
565
  }
566
566
 
567
- class InvalidContextError extends ProtocolError {
567
+ export class InvalidContextError extends ProtocolError {
568
568
  static code () {
569
569
  return 36;
570
570
  }
@@ -575,18 +575,18 @@ class InvalidContextError extends ProtocolError {
575
575
  }
576
576
 
577
577
  // These are aliases for UnknownMethodError
578
- class NotYetImplementedError extends UnknownMethodError {
578
+ export class NotYetImplementedError extends UnknownMethodError {
579
579
  constructor (err) {
580
580
  super(err || 'Method has not yet been implemented');
581
581
  }
582
582
  }
583
- class NotImplementedError extends UnknownMethodError {
583
+ export class NotImplementedError extends UnknownMethodError {
584
584
  constructor (err) {
585
585
  super(err || 'Method is not implemented');
586
586
  }
587
587
  }
588
588
 
589
- class UnableToCaptureScreen extends ProtocolError {
589
+ export class UnableToCaptureScreen extends ProtocolError {
590
590
  static code () {
591
591
  return 63;
592
592
  }
@@ -604,7 +604,7 @@ class UnableToCaptureScreen extends ProtocolError {
604
604
 
605
605
 
606
606
  // Equivalent to W3C InvalidArgumentError
607
- class BadParametersError extends ES6Error {
607
+ export class BadParametersError extends ES6Error {
608
608
  static error () {
609
609
  return 'invalid argument';
610
610
  }
@@ -628,7 +628,7 @@ class BadParametersError extends ES6Error {
628
628
  * In case of ProxyRequestError should fetch the actual error by calling `getActualError()`
629
629
  * for proxy failure to generate the client response.
630
630
  */
631
- class ProxyRequestError extends ES6Error {
631
+ export class ProxyRequestError extends ES6Error {
632
632
  constructor (err, responseError, httpStatus) {
633
633
  let responseErrorObj = util.safeJsonParse(responseError);
634
634
  if (!_.isPlainObject(responseErrorObj)) {
@@ -864,7 +864,7 @@ function getResponseForJsonwpError (err) {
864
864
  }
865
865
 
866
866
  export {
867
- ProtocolError, errors, isErrorType, isUnknownError,
867
+ errors, isErrorType, isUnknownError,
868
868
  errorFromMJSONWPStatusCode, errorFromW3CJsonCode,
869
869
  getResponseForW3CError, getResponseForJsonwpError,
870
870
  };
@@ -1,8 +1,8 @@
1
1
  // transpile:main
2
2
 
3
3
  import {
4
- Protocol, isSessionCommand, routeConfiguringFunction, determineProtocol,
5
- CREATE_SESSION_COMMAND, DELETE_SESSION_COMMAND,
4
+ isSessionCommand, routeConfiguringFunction, determineProtocol,
5
+ CREATE_SESSION_COMMAND, DELETE_SESSION_COMMAND, GET_STATUS_COMMAND
6
6
  } from './protocol';
7
7
  import {
8
8
  NO_SESSION_ID_COMMANDS, ALL_COMMANDS, METHOD_MAP,
@@ -13,8 +13,8 @@ import {
13
13
  } from './errors';
14
14
 
15
15
  export {
16
- Protocol, routeConfiguringFunction, errors, isErrorType,
16
+ routeConfiguringFunction, errors, isErrorType,
17
17
  errorFromMJSONWPStatusCode, errorFromW3CJsonCode, ALL_COMMANDS, METHOD_MAP,
18
18
  routeToCommandName, NO_SESSION_ID_COMMANDS, isSessionCommand, determineProtocol,
19
- CREATE_SESSION_COMMAND, DELETE_SESSION_COMMAND,
19
+ CREATE_SESSION_COMMAND, DELETE_SESSION_COMMAND, GET_STATUS_COMMAND
20
20
  };
@@ -16,8 +16,6 @@ const CREATE_SESSION_COMMAND = 'createSession';
16
16
  const DELETE_SESSION_COMMAND = 'deleteSession';
17
17
  const GET_STATUS_COMMAND = 'getStatus';
18
18
 
19
- class Protocol {}
20
-
21
19
  function determineProtocol (createSessionArgs) {
22
20
  return _.some(createSessionArgs, isW3cCaps) ? PROTOCOLS.W3C : PROTOCOLS.MJSONWP;
23
21
  }
@@ -456,7 +454,7 @@ async function doJwpProxy (driver, req, res) {
456
454
 
457
455
 
458
456
  export {
459
- Protocol, routeConfiguringFunction, isSessionCommand,
457
+ routeConfiguringFunction, isSessionCommand,
460
458
  driverShouldDoJwpProxy, determineProtocol, CREATE_SESSION_COMMAND,
461
459
  DELETE_SESSION_COMMAND, GET_STATUS_COMMAND,
462
460
  };
@@ -1,3 +1,5 @@
1
+ // @ts-check
2
+
1
3
  import _ from 'lodash';
2
4
  import { util } from '@appium/support';
3
5
  import { PROTOCOLS, DEFAULT_BASE_PATH } from '../constants';
@@ -14,6 +16,7 @@ const SET_ALERT_TEXT_PAYLOAD_PARAMS = {
14
16
  // define the routes, mapping of HTTP methods to particular driver commands,
15
17
  // and any parameters that are expected in a request
16
18
  // parameters can be `required` or `optional`
19
+ /** @type {import('@appium/types').MethodMap} */
17
20
  const METHOD_MAP = {
18
21
  '/status': {
19
22
  GET: {command: 'getStatus'}
@@ -240,6 +243,12 @@ const METHOD_MAP = {
240
243
  '/session/:sessionId/element/:elementId/shadow': {
241
244
  GET: {command: 'elementShadowRoot'}
242
245
  },
246
+ '/session/:sessionId/shadow/:shadowId/element': {
247
+ POST: {command: 'findElementFromShadowRoot', payloadParams: {required: ['using', 'value']}}
248
+ },
249
+ '/session/:sessionId/shadow/:shadowId/elements': {
250
+ POST: {command: 'findElementsFromShadowRoot', payloadParams: {required: ['using', 'value']}}
251
+ },
243
252
  '/session/:sessionId/element/:elementId/css/:propertyName': {
244
253
  GET: {command: 'getCssProperty'}
245
254
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/base-driver",
3
- "version": "8.3.1",
3
+ "version": "8.4.0",
4
4
  "description": "Base driver class for Appium drivers",
5
5
  "keywords": [
6
6
  "automation",
@@ -37,10 +37,10 @@
37
37
  "!build/test/e2e/fixtures"
38
38
  ],
39
39
  "scripts": {
40
- "build": "npm run build:sources && npm run build:test",
41
- "build:sources": "babel lib --root-mode=upward --out-dir=build/lib",
40
+ "build": "npm run build:distfiles && npm run build:test",
41
+ "build:distfiles": "babel lib --root-mode=upward --out-dir=build/lib",
42
42
  "build:test": "babel test --root-mode=upward --out-dir=build/test --copy-files",
43
- "dev": "npm run build -- --watch",
43
+ "dev": "run-p \"build:distfiles -- --watch\" \"build:test -- --watch\"",
44
44
  "fix": "npm run lint -- --fix",
45
45
  "lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore .",
46
46
  "test": "npm run test:unit",
@@ -48,19 +48,19 @@
48
48
  "test:unit": "mocha --require ../../test/setup-babel.js \"./test/unit/**/*.spec.js\""
49
49
  },
50
50
  "dependencies": {
51
- "@appium/support": "^2.56.1",
52
- "@babel/runtime": "7.17.8",
51
+ "@appium/support": "^2.57.0",
52
+ "@babel/runtime": "7.17.9",
53
53
  "@colors/colors": "1.5.0",
54
54
  "async-lock": "1.3.1",
55
55
  "asyncbox": "2.9.2",
56
56
  "axios": "0.26.1",
57
57
  "bluebird": "3.7.2",
58
- "body-parser": "1.19.2",
58
+ "body-parser": "1.20.0",
59
59
  "es6-error": "4.1.1",
60
60
  "express": "4.17.3",
61
61
  "http-status-codes": "2.2.0",
62
62
  "lodash": "4.17.21",
63
- "lru-cache": "7.7.1",
63
+ "lru-cache": "7.7.3",
64
64
  "method-override": "3.0.0",
65
65
  "morgan": "1.10.0",
66
66
  "serve-favicon": "2.5.0",
@@ -75,5 +75,6 @@
75
75
  "publishConfig": {
76
76
  "access": "public"
77
77
  },
78
- "gitHead": "6d35def9ed754121fee691cdaf7b30e3a7ac3e8b"
78
+ "types": "./build/lib/index.d.ts",
79
+ "gitHead": "3ec3a0efa590e22e264ffbd23316ee5714a12081"
79
80
  }
@@ -10,6 +10,35 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
10
10
  // to display the driver under test in report
11
11
  const className = DriverClass.name || '(unknown driver)';
12
12
 
13
+ describe('static property', function () {
14
+ describe('baseVersion', function () {
15
+ it('should exist', function () {
16
+ DriverClass.baseVersion.should.exist;
17
+ });
18
+ });
19
+ });
20
+
21
+ describe('Log prefix', function () {
22
+
23
+ it('should setup log prefix', async function () {
24
+ const d = new DriverClass();
25
+ const previousPrefix = d.log.prefix;
26
+ await d.createSession({
27
+ alwaysMatch: Object.assign({}, defaultCaps, {
28
+ platformName: 'Fake',
29
+ 'appium:deviceName': 'Commodore 64',
30
+ }),
31
+ firstMatch: [{}],
32
+ });
33
+ try {
34
+ previousPrefix.should.not.eql(d.log.prefix);
35
+ } finally {
36
+ await d.deleteSession();
37
+ previousPrefix.should.eql(d.log.prefix);
38
+ }
39
+ });
40
+
41
+ });
13
42
 
14
43
  describe(`BaseDriver (as ${className})`, function () {
15
44
  let d, w3cCaps;
@@ -183,8 +212,8 @@ function baseDriverUnitTests (DriverClass, defaultCaps = {}) {
183
212
  throw new Error('multipass');
184
213
  }.bind(d);
185
214
 
186
- afterEach(function () {
187
- d.clearNewCommandTimeout();
215
+ afterEach(async function () {
216
+ await d.clearNewCommandTimeout();
188
217
  });
189
218
 
190
219
  it('should queue commands and.executeCommand/respond in the order received', async function () {