@appium/base-driver 8.2.4 → 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 (206) 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 +12 -13
  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 -23
  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 +41 -43
  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 -16
  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 +23 -30
  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 -158
  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 +18 -22
  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 -144
  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 +2 -4
  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 +33 -15
  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 +104 -257
  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 +24 -10
  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/basedriver/logger.js +2 -4
  43. package/build/lib/constants.d.ts +9 -0
  44. package/build/lib/constants.d.ts.map +1 -0
  45. package/build/lib/constants.js +2 -4
  46. package/build/lib/express/crash.d.ts +3 -0
  47. package/build/lib/express/crash.d.ts.map +1 -0
  48. package/build/lib/express/crash.js +2 -4
  49. package/build/lib/express/express-logging.d.ts +3 -0
  50. package/build/lib/express/express-logging.d.ts.map +1 -0
  51. package/build/lib/express/express-logging.js +3 -5
  52. package/build/lib/express/idempotency.d.ts +2 -0
  53. package/build/lib/express/idempotency.d.ts.map +1 -0
  54. package/build/lib/express/idempotency.js +3 -5
  55. package/build/lib/express/logger.d.ts +3 -0
  56. package/build/lib/express/logger.d.ts.map +1 -0
  57. package/build/lib/express/logger.js +2 -4
  58. package/build/lib/express/middleware.d.ts +9 -0
  59. package/build/lib/express/middleware.d.ts.map +1 -0
  60. package/build/lib/express/middleware.js +2 -4
  61. package/build/lib/express/server.d.ts +10 -0
  62. package/build/lib/express/server.d.ts.map +1 -0
  63. package/build/lib/express/server.js +2 -4
  64. package/build/lib/express/static.d.ts +6 -0
  65. package/build/lib/express/static.d.ts.map +1 -0
  66. package/build/lib/express/static.js +2 -4
  67. package/build/lib/express/websocket.d.ts +64 -0
  68. package/build/lib/express/websocket.d.ts.map +1 -0
  69. package/build/lib/express/websocket.js +2 -4
  70. package/build/lib/helpers/capabilities.d.ts +13 -0
  71. package/build/lib/helpers/capabilities.d.ts.map +1 -0
  72. package/build/lib/helpers/capabilities.js +77 -0
  73. package/build/lib/index.d.ts +183 -0
  74. package/build/lib/index.d.ts.map +1 -0
  75. package/build/lib/index.js +41 -25
  76. package/build/lib/jsonwp-proxy/protocol-converter.d.ts +48 -0
  77. package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -0
  78. package/build/lib/jsonwp-proxy/protocol-converter.js +19 -15
  79. package/build/lib/jsonwp-proxy/proxy.d.ts +41 -0
  80. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -0
  81. package/build/lib/jsonwp-proxy/proxy.js +20 -15
  82. package/build/lib/jsonwp-status/status.d.ts +159 -0
  83. package/build/lib/jsonwp-status/status.d.ts.map +1 -0
  84. package/build/lib/jsonwp-status/status.js +2 -4
  85. package/build/lib/protocol/errors.d.ts +310 -0
  86. package/build/lib/protocol/errors.d.ts.map +1 -0
  87. package/build/lib/protocol/errors.js +82 -5
  88. package/build/lib/protocol/helpers.d.ts +22 -0
  89. package/build/lib/protocol/helpers.d.ts.map +1 -0
  90. package/build/lib/protocol/helpers.js +2 -4
  91. package/build/lib/protocol/index.d.ts +16 -0
  92. package/build/lib/protocol/index.d.ts.map +1 -0
  93. package/build/lib/protocol/index.js +8 -10
  94. package/build/lib/protocol/protocol.d.ts +11 -0
  95. package/build/lib/protocol/protocol.d.ts.map +1 -0
  96. package/build/lib/protocol/protocol.js +38 -35
  97. package/build/lib/protocol/routes.d.ts +6 -0
  98. package/build/lib/protocol/routes.d.ts.map +1 -0
  99. package/build/lib/protocol/routes.js +84 -4
  100. package/build/lib/protocol/validators.d.ts +8 -0
  101. package/build/lib/protocol/validators.d.ts.map +1 -0
  102. package/build/lib/protocol/validators.js +2 -4
  103. package/build/test/basedriver/README.md +5 -0
  104. package/build/test/basedriver/driver-e2e-tests.js +2 -4
  105. package/build/test/basedriver/driver-tests.js +41 -19
  106. package/build/test/basedriver/index.js +2 -4
  107. package/build/test/e2e/basedriver/driver.e2e.spec.js +15 -0
  108. package/build/test/e2e/basedriver/helpers.e2e.spec.js +192 -0
  109. package/build/test/e2e/basedriver/websockets.e2e.spec.js +82 -0
  110. package/build/test/e2e/express/server.e2e.spec.js +159 -0
  111. package/build/test/e2e/jsonwp-proxy/proxy.e2e.spec.js +59 -0
  112. package/build/test/e2e/protocol/fake-driver.js +163 -0
  113. package/build/test/e2e/protocol/helpers.js +25 -0
  114. package/build/test/e2e/protocol/protocol.e2e.spec.js +1186 -0
  115. package/build/test/helpers.js +2 -4
  116. package/build/test/unit/basedriver/capabilities.spec.js +672 -0
  117. package/build/test/unit/basedriver/capability.spec.js +353 -0
  118. package/build/test/unit/basedriver/commands/event.spec.js +110 -0
  119. package/build/test/unit/basedriver/commands/log.spec.js +92 -0
  120. package/build/test/unit/basedriver/driver.spec.js +15 -0
  121. package/build/test/unit/basedriver/helpers.spec.js +151 -0
  122. package/build/test/unit/basedriver/timeout.spec.js +135 -0
  123. package/build/test/unit/express/server.spec.js +155 -0
  124. package/build/test/unit/express/static.spec.js +26 -0
  125. package/build/test/unit/jsonwp-proxy/mock-request.js +91 -0
  126. package/build/test/unit/jsonwp-proxy/protocol-converter.spec.js +171 -0
  127. package/build/test/unit/jsonwp-proxy/proxy.spec.js +292 -0
  128. package/build/test/unit/jsonwp-proxy/url.spec.js +165 -0
  129. package/build/test/unit/jsonwp-status/status.spec.js +34 -0
  130. package/build/test/unit/protocol/errors.spec.js +390 -0
  131. package/build/test/unit/protocol/routes.spec.js +80 -0
  132. package/build/test/unit/protocol/validator.spec.js +149 -0
  133. package/build/tsconfig.tsbuildinfo +1 -0
  134. package/lib/basedriver/capabilities.js +49 -10
  135. package/lib/basedriver/commands/event.js +49 -31
  136. package/lib/basedriver/commands/find.js +107 -45
  137. package/lib/basedriver/commands/index.js +25 -19
  138. package/lib/basedriver/commands/log.js +59 -34
  139. package/lib/basedriver/commands/session.js +39 -142
  140. package/lib/basedriver/commands/settings.js +32 -14
  141. package/lib/basedriver/commands/timeout.js +153 -154
  142. package/lib/basedriver/core.js +497 -0
  143. package/lib/basedriver/desired-caps.js +1 -1
  144. package/lib/basedriver/device-settings.js +57 -13
  145. package/lib/basedriver/driver.js +277 -375
  146. package/lib/basedriver/helpers.js +31 -13
  147. package/lib/express/express-logging.js +1 -1
  148. package/lib/express/idempotency.js +1 -1
  149. package/lib/helpers/capabilities.js +84 -0
  150. package/lib/index.js +17 -13
  151. package/lib/jsonwp-proxy/protocol-converter.js +14 -13
  152. package/lib/jsonwp-proxy/proxy.js +16 -12
  153. package/lib/protocol/errors.js +42 -42
  154. package/lib/protocol/index.js +4 -4
  155. package/lib/protocol/protocol.js +35 -32
  156. package/lib/protocol/routes.js +69 -1
  157. package/package.json +37 -24
  158. package/test/basedriver/README.md +5 -0
  159. package/test/basedriver/driver-e2e-tests.js +1 -1
  160. package/test/basedriver/driver-tests.js +43 -9
  161. package/build/lib/protocol/sessions-cache.js +0 -88
  162. package/build/test/basedriver/capabilities-specs.js +0 -632
  163. package/build/test/basedriver/capability-specs.js +0 -396
  164. package/build/test/basedriver/commands/event-specs.js +0 -112
  165. package/build/test/basedriver/commands/log-specs.js +0 -80
  166. package/build/test/basedriver/driver-e2e-specs.js +0 -17
  167. package/build/test/basedriver/driver-specs.js +0 -17
  168. package/build/test/basedriver/helpers-e2e-specs.js +0 -194
  169. package/build/test/basedriver/helpers-specs.js +0 -153
  170. package/build/test/basedriver/timeout-specs.js +0 -139
  171. package/build/test/basedriver/websockets-e2e-specs.js +0 -84
  172. package/build/test/express/server-e2e-specs.js +0 -156
  173. package/build/test/express/server-specs.js +0 -151
  174. package/build/test/express/static-specs.js +0 -23
  175. package/build/test/jsonwp-proxy/mock-request.js +0 -93
  176. package/build/test/jsonwp-proxy/protocol-converter-specs.js +0 -173
  177. package/build/test/jsonwp-proxy/proxy-e2e-specs.js +0 -61
  178. package/build/test/jsonwp-proxy/proxy-specs.js +0 -294
  179. package/build/test/jsonwp-proxy/url-specs.js +0 -167
  180. package/build/test/jsonwp-status/status-specs.js +0 -36
  181. package/build/test/protocol/errors-specs.js +0 -388
  182. package/build/test/protocol/fake-driver.js +0 -168
  183. package/build/test/protocol/helpers.js +0 -27
  184. package/build/test/protocol/protocol-e2e-specs.js +0 -1182
  185. package/build/test/protocol/routes-specs.js +0 -82
  186. package/build/test/protocol/validator-specs.js +0 -151
  187. package/index.d.ts +0 -386
  188. package/lib/protocol/sessions-cache.js +0 -74
  189. package/test/basedriver/capabilities-specs.js +0 -505
  190. package/test/basedriver/capability-specs.js +0 -409
  191. package/test/basedriver/commands/event-specs.js +0 -74
  192. package/test/basedriver/commands/log-specs.js +0 -70
  193. package/test/basedriver/driver-e2e-specs.js +0 -8
  194. package/test/basedriver/driver-specs.js +0 -8
  195. package/test/basedriver/fixtures/BadZippedApp.zip +0 -1
  196. package/test/basedriver/fixtures/FakeAndroidApp.apk +0 -1
  197. package/test/basedriver/fixtures/FakeAndroidApp.asd +0 -0
  198. package/test/basedriver/fixtures/FakeIOSApp.app +0 -1
  199. package/test/basedriver/fixtures/FakeIOSApp.app.zip +0 -0
  200. package/test/basedriver/fixtures/FakeIOSApp.ipa +0 -0
  201. package/test/basedriver/fixtures/custom-element-finder-bad.js +0 -5
  202. package/test/basedriver/fixtures/custom-element-finder.js +0 -29
  203. package/test/basedriver/helpers-e2e-specs.js +0 -187
  204. package/test/basedriver/helpers-specs.js +0 -137
  205. package/test/basedriver/timeout-specs.js +0 -133
  206. package/test/basedriver/websockets-e2e-specs.js +0 -75
@@ -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
  };
@@ -1,5 +1,5 @@
1
1
  import _ from 'lodash';
2
- import { util } from '@appium/support';
2
+ import { util, logger, node } from '@appium/support';
3
3
  import { validators } from './validators';
4
4
  import {
5
5
  errors, isErrorType, getResponseForW3CError,
@@ -7,23 +7,17 @@ import {
7
7
  } from './errors';
8
8
  import { METHOD_MAP, NO_SESSION_ID_COMMANDS } from './routes';
9
9
  import B from 'bluebird';
10
- import {
11
- formatResponseValue, formatStatus,
12
- } from './helpers';
10
+ import { formatResponseValue, formatStatus } from './helpers';
13
11
  import { MAX_LOG_BODY_LENGTH, PROTOCOLS, DEFAULT_BASE_PATH } from '../constants';
14
- import SESSIONS_CACHE from './sessions-cache';
12
+ import { isW3cCaps } from '../helpers/capabilities';
15
13
 
16
14
 
17
15
  const CREATE_SESSION_COMMAND = 'createSession';
18
16
  const DELETE_SESSION_COMMAND = 'deleteSession';
19
17
  const GET_STATUS_COMMAND = 'getStatus';
20
18
 
21
- class Protocol {}
22
-
23
- function determineProtocol (desiredCapabilities, requiredCapabilities, capabilities) {
24
- return _.isPlainObject(capabilities) ?
25
- PROTOCOLS.W3C :
26
- PROTOCOLS.MJSONWP;
19
+ function determineProtocol (createSessionArgs) {
20
+ return _.some(createSessionArgs, isW3cCaps) ? PROTOCOLS.W3C : PROTOCOLS.MJSONWP;
27
21
  }
28
22
 
29
23
  function extractProtocol (driver, sessionId = null) {
@@ -38,13 +32,30 @@ function extractProtocol (driver, sessionId = null) {
38
32
  }
39
33
 
40
34
  // Extract the protocol for the current session if the given driver is the umbrella one
41
- return dstDriver ? dstDriver.protocol : SESSIONS_CACHE.getProtocol(sessionId);
35
+ return dstDriver?.protocol ?? PROTOCOLS.W3C;
42
36
  }
43
37
 
44
38
  function isSessionCommand (command) {
45
39
  return !_.includes(NO_SESSION_ID_COMMANDS, command);
46
40
  }
47
41
 
42
+ function getLogger (driver, sessionId = null) {
43
+ const dstDriver = sessionId && _.isFunction(driver.driverForSession)
44
+ ? (driver.driverForSession(sessionId) ?? driver)
45
+ : driver;
46
+ if (_.isFunction(dstDriver.log?.info)) {
47
+ return dstDriver.log;
48
+ }
49
+
50
+ let logPrefix = dstDriver.constructor
51
+ ? `${dstDriver.constructor.name}@${node.getObjectId(dstDriver).substring(0, 8)}`
52
+ : 'AppiumDriver';
53
+ if (sessionId) {
54
+ logPrefix += ` (${sessionId.substring(0, 8)})`;
55
+ }
56
+ return logger.getLogger(logPrefix);
57
+ }
58
+
48
59
  function wrapParams (paramSets, jsonObj) {
49
60
  /* There are commands like performTouch which take a single parameter (primitive type or array).
50
61
  * Some drivers choose to pass this parameter as a value (eg. [action1, action2...]) while others to
@@ -192,11 +203,11 @@ function makeArgs (requestParams, jsonObj, payloadParams, protocol) {
192
203
 
193
204
  function routeConfiguringFunction (driver) {
194
205
  if (!driver.sessionExists) {
195
- throw new Error('Drivers used with MJSONWP must implement `sessionExists`');
206
+ throw new Error('Drivers must implement `sessionExists` property');
196
207
  }
197
208
 
198
209
  if (!(driver.executeCommand || driver.execute)) {
199
- throw new Error('Drivers used with MJSONWP must implement `executeCommand` or `execute`');
210
+ throw new Error('Drivers must implement `executeCommand` or `execute` method');
200
211
  }
201
212
 
202
213
  // return a function which will add all the routes to the driver. Here extraMethods might be
@@ -247,7 +258,7 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
247
258
  await doJwpProxy(driver, req, res);
248
259
  return;
249
260
  }
250
- SESSIONS_CACHE.getLogger(req.params.sessionId, currentProtocol).debug(`Would have proxied ` +
261
+ getLogger(driver, req.params.sessionId).debug(`Would have proxied ` +
251
262
  `command directly, but a plugin exists which might require its value, so will let ` +
252
263
  `its value be collected internally and made part of plugin chain`);
253
264
  didPluginOverrideProxy = true;
@@ -272,7 +283,7 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
272
283
  if (spec.command === CREATE_SESSION_COMMAND) {
273
284
  // try to determine protocol by session creation args, so we can throw a
274
285
  // properly formatted error if arguments validation fails
275
- currentProtocol = determineProtocol(...makeArgs(req.params, jsonObj, spec.payloadParams || {}));
286
+ currentProtocol = determineProtocol(makeArgs(req.params, jsonObj, spec.payloadParams || {}));
276
287
  }
277
288
 
278
289
  // ensure that the json payload conforms to the spec
@@ -288,7 +299,7 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
288
299
  }
289
300
 
290
301
  // run the driver command wrapped inside the argument validators
291
- SESSIONS_CACHE.getLogger(req.params.sessionId, currentProtocol).debug(`Calling ` +
302
+ getLogger(driver, req.params.sessionId).debug(`Calling ` +
292
303
  `${driver.constructor.name}.${spec.command}() with args: ` +
293
304
  _.truncate(JSON.stringify(args), {length: MAX_LOG_BODY_LENGTH}));
294
305
 
@@ -317,8 +328,7 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
317
328
  // unpack createSession response
318
329
  if (spec.command === CREATE_SESSION_COMMAND) {
319
330
  newSessionId = driverRes[0];
320
- SESSIONS_CACHE.putSession(newSessionId, currentProtocol);
321
- SESSIONS_CACHE.getLogger(newSessionId, currentProtocol)
331
+ getLogger(driver, newSessionId)
322
332
  .debug(`Cached the protocol value '${currentProtocol}' for the new session ${newSessionId}`);
323
333
  if (currentProtocol === PROTOCOLS.MJSONWP) {
324
334
  driverRes = driverRes[1];
@@ -333,9 +343,9 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
333
343
 
334
344
  // delete should not return anything even if successful
335
345
  if (spec.command === DELETE_SESSION_COMMAND) {
336
- SESSIONS_CACHE.getLogger(req.params.sessionId, currentProtocol)
346
+ getLogger(driver, req.params.sessionId)
337
347
  .debug(`Received response: ${_.truncate(JSON.stringify(driverRes), {length: MAX_LOG_BODY_LENGTH})}`);
338
- SESSIONS_CACHE.getLogger(req.params.sessionId, currentProtocol).debug('But deleting session, so not returning');
348
+ getLogger(driver, req.params.sessionId).debug('But deleting session, so not returning');
339
349
  driverRes = null;
340
350
  }
341
351
 
@@ -349,15 +359,8 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
349
359
  }
350
360
 
351
361
  httpResBody.value = driverRes;
352
- SESSIONS_CACHE.getLogger(req.params.sessionId || newSessionId, currentProtocol).debug(`Responding ` +
362
+ getLogger(driver, req.params.sessionId || newSessionId).debug(`Responding ` +
353
363
  `to client with driver.${spec.command}() result: ${_.truncate(JSON.stringify(driverRes), {length: MAX_LOG_BODY_LENGTH})}`);
354
-
355
- if (spec.command === DELETE_SESSION_COMMAND) {
356
- // We don't want to keep the logger instance in the cache
357
- // after the session is deleted, because it contains the logging history
358
- // and consumes the memory
359
- SESSIONS_CACHE.resetLogger(req.params.sessionId);
360
- }
361
364
  } catch (err) {
362
365
  // if anything goes wrong, figure out what our response should be
363
366
  // based on the type of error that we encountered
@@ -374,7 +377,7 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
374
377
  if (isErrorType(err, errors.ProxyRequestError)) {
375
378
  actualErr = err.getActualError();
376
379
  } else {
377
- SESSIONS_CACHE.getLogger(req.params.sessionId || newSessionId, currentProtocol)
380
+ getLogger(driver, req.params.sessionId || newSessionId)
378
381
  .debug(`Encountered internal error running command: ${errMsg}`);
379
382
  }
380
383
 
@@ -431,7 +434,7 @@ function driverShouldDoJwpProxy (driver, req, command) {
431
434
  }
432
435
 
433
436
  async function doJwpProxy (driver, req, res) {
434
- SESSIONS_CACHE.getLogger(req.params.sessionId, extractProtocol(driver, req.params.sessionId))
437
+ getLogger(driver, req.params.sessionId)
435
438
  .info('Driver proxy active, passing request on via HTTP proxy');
436
439
 
437
440
  // check that the inner driver has a proxy function
@@ -451,7 +454,7 @@ async function doJwpProxy (driver, req, res) {
451
454
 
452
455
 
453
456
  export {
454
- Protocol, routeConfiguringFunction, isSessionCommand,
457
+ routeConfiguringFunction, isSessionCommand,
455
458
  driverShouldDoJwpProxy, determineProtocol, CREATE_SESSION_COMMAND,
456
459
  DELETE_SESSION_COMMAND, GET_STATUS_COMMAND,
457
460
  };
@@ -1,6 +1,8 @@
1
+ // @ts-check
2
+
1
3
  import _ from 'lodash';
2
4
  import { util } from '@appium/support';
3
- import { DEFAULT_BASE_PATH } from '../constants';
5
+ import { PROTOCOLS, DEFAULT_BASE_PATH } from '../constants';
4
6
 
5
7
 
6
8
  const SET_ALERT_TEXT_PAYLOAD_PARAMS = {
@@ -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'}
@@ -33,6 +36,18 @@ const METHOD_MAP = {
33
36
  '/session/:sessionId/timeouts': {
34
37
  GET: {command: 'getTimeouts'}, // W3C route
35
38
  POST: {command: 'timeouts', payloadParams: {
39
+ validate: (jsonObj, protocolName) => {
40
+ if (protocolName === PROTOCOLS.W3C) {
41
+ if (!util.hasValue(jsonObj.script) && !util.hasValue(jsonObj.pageLoad) && !util.hasValue(jsonObj.implicit)) {
42
+ return 'W3C protocol expects any of script, pageLoad or implicit to be set';
43
+ }
44
+ } else {
45
+ // MJSONWP
46
+ if (!util.hasValue(jsonObj.type) || !util.hasValue(jsonObj.ms)) {
47
+ return 'MJSONWP protocol requires type and ms';
48
+ }
49
+ }
50
+ },
36
51
  optional: ['type', 'ms', 'script', 'pageLoad', 'implicit'],
37
52
  }}
38
53
  },
@@ -42,9 +57,19 @@ const METHOD_MAP = {
42
57
  '/session/:sessionId/timeouts/implicit_wait': {
43
58
  POST: {command: 'implicitWait', payloadParams: {required: ['ms']}}
44
59
  },
60
+ // JSONWP
61
+ '/session/:sessionId/window_handle': {
62
+ GET: {command: 'getWindowHandle'}
63
+ },
64
+ // W3C
45
65
  '/session/:sessionId/window/handle': {
46
66
  GET: {command: 'getWindowHandle'}
47
67
  },
68
+ // JSONWP
69
+ '/session/:sessionId/window_handles': {
70
+ GET: {command: 'getWindowHandles'}
71
+ },
72
+ // W3C
48
73
  '/session/:sessionId/window/handles': {
49
74
  GET: {command: 'getWindowHandles'}
50
75
  },
@@ -61,6 +86,14 @@ const METHOD_MAP = {
61
86
  '/session/:sessionId/refresh': {
62
87
  POST: {command: 'refresh'}
63
88
  },
89
+ // MJSONWP
90
+ '/session/:sessionId/execute': {
91
+ POST: {command: 'execute', payloadParams: {required: ['script', 'args']}}
92
+ },
93
+ // MJSONWP
94
+ '/session/:sessionId/execute_async': {
95
+ POST: {command: 'executeAsync', payloadParams: {required: ['script', 'args']}}
96
+ },
64
97
  '/session/:sessionId/screenshot': {
65
98
  GET: {command: 'getScreenshot'}
66
99
  },
@@ -207,6 +240,15 @@ const METHOD_MAP = {
207
240
  '/session/:sessionId/element/:elementId/size': {
208
241
  GET: {command: 'getSize'}
209
242
  },
243
+ '/session/:sessionId/element/:elementId/shadow': {
244
+ GET: {command: 'elementShadowRoot'}
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
+ },
210
252
  '/session/:sessionId/element/:elementId/css/:propertyName': {
211
253
  GET: {command: 'getCssProperty'}
212
254
  },
@@ -582,6 +624,28 @@ const METHOD_MAP = {
582
624
  POST: {command: 'logCustomEvent', payloadParams: {required: ['vendor', 'event']}}
583
625
  },
584
626
 
627
+ /*
628
+ * The W3C spec has some changes to the wire protocol.
629
+ * https://w3c.github.io/webdriver/webdriver-spec.html
630
+ * Begin to add those changes here, keeping the old version
631
+ * since clients still implement them.
632
+ */
633
+ // MJSONWP
634
+ '/session/:sessionId/alert_text': {
635
+ GET: {command: 'getAlertText'},
636
+ POST: {
637
+ command: 'setAlertText',
638
+ payloadParams: SET_ALERT_TEXT_PAYLOAD_PARAMS,
639
+ }
640
+ },
641
+ // MJSONWP
642
+ '/session/:sessionId/accept_alert': {
643
+ POST: {command: 'postAcceptAlert'}
644
+ },
645
+ // MJSONWP
646
+ '/session/:sessionId/dismiss_alert': {
647
+ POST: {command: 'postDismissAlert'}
648
+ },
585
649
  // https://w3c.github.io/webdriver/webdriver-spec.html#user-prompts
586
650
  '/session/:sessionId/alert/text': {
587
651
  GET: {command: 'getAlertText'},
@@ -606,6 +670,10 @@ const METHOD_MAP = {
606
670
  '/session/:sessionId/execute/async': {
607
671
  POST: {command: 'executeAsync', payloadParams: {required: ['script', 'args']}}
608
672
  },
673
+ // Pre-W3C endpoint for element screenshot
674
+ '/session/:sessionId/screenshot/:elementId': {
675
+ GET: {command: 'getElementScreenshot'}
676
+ },
609
677
  '/session/:sessionId/element/:elementId/screenshot': {
610
678
  GET: {command: 'getElementScreenshot'}
611
679
  },