@appium/base-driver 8.5.2 → 8.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/build/lib/basedriver/capabilities.d.ts.map +1 -1
  2. package/build/lib/basedriver/capabilities.js +1 -1
  3. package/build/lib/basedriver/commands/event.js +1 -1
  4. package/build/lib/basedriver/commands/find.d.ts.map +1 -1
  5. package/build/lib/basedriver/commands/find.js +1 -1
  6. package/build/lib/basedriver/commands/index.js +1 -1
  7. package/build/lib/basedriver/commands/log.d.ts.map +1 -1
  8. package/build/lib/basedriver/commands/log.js +1 -1
  9. package/build/lib/basedriver/commands/session.js +1 -1
  10. package/build/lib/basedriver/commands/settings.d.ts.map +1 -1
  11. package/build/lib/basedriver/commands/settings.js +1 -1
  12. package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
  13. package/build/lib/basedriver/commands/timeout.js +1 -1
  14. package/build/lib/basedriver/core.d.ts +120 -139
  15. package/build/lib/basedriver/core.d.ts.map +1 -1
  16. package/build/lib/basedriver/core.js +1 -49
  17. package/build/lib/basedriver/desired-caps.d.ts +5 -2
  18. package/build/lib/basedriver/desired-caps.d.ts.map +1 -1
  19. package/build/lib/basedriver/desired-caps.js +14 -18
  20. package/build/lib/basedriver/device-settings.d.ts +9 -9
  21. package/build/lib/basedriver/device-settings.d.ts.map +1 -1
  22. package/build/lib/basedriver/device-settings.js +4 -4
  23. package/build/lib/basedriver/driver.d.ts +43 -38
  24. package/build/lib/basedriver/driver.d.ts.map +1 -1
  25. package/build/lib/basedriver/driver.js +58 -11
  26. package/build/lib/basedriver/helpers.d.ts +8 -3
  27. package/build/lib/basedriver/helpers.d.ts.map +1 -1
  28. package/build/lib/basedriver/helpers.js +4 -6
  29. package/build/lib/basedriver/logger.d.ts +1 -1
  30. package/build/lib/basedriver/logger.d.ts.map +1 -1
  31. package/build/lib/basedriver/logger.js +1 -1
  32. package/build/lib/constants.js +1 -1
  33. package/build/lib/express/crash.d.ts.map +1 -1
  34. package/build/lib/express/crash.js +1 -1
  35. package/build/lib/express/express-logging.d.ts.map +1 -1
  36. package/build/lib/express/express-logging.js +1 -1
  37. package/build/lib/express/idempotency.js +1 -1
  38. package/build/lib/express/logger.d.ts +1 -1
  39. package/build/lib/express/logger.d.ts.map +1 -1
  40. package/build/lib/express/logger.js +1 -1
  41. package/build/lib/express/middleware.d.ts.map +1 -1
  42. package/build/lib/express/middleware.js +1 -1
  43. package/build/lib/express/server.d.ts +21 -0
  44. package/build/lib/express/server.d.ts.map +1 -1
  45. package/build/lib/express/server.js +4 -9
  46. package/build/lib/express/static.d.ts.map +1 -1
  47. package/build/lib/express/static.js +2 -2
  48. package/build/lib/express/websocket.d.ts +14 -11
  49. package/build/lib/express/websocket.d.ts.map +1 -1
  50. package/build/lib/express/websocket.js +2 -2
  51. package/build/lib/helpers/capabilities.d.ts.map +1 -1
  52. package/build/lib/helpers/capabilities.js +1 -1
  53. package/build/lib/index.d.ts +2 -1
  54. package/build/lib/index.js +7 -1
  55. package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
  56. package/build/lib/jsonwp-proxy/protocol-converter.js +2 -2
  57. package/build/lib/jsonwp-proxy/proxy.d.ts +30 -5
  58. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
  59. package/build/lib/jsonwp-proxy/proxy.js +20 -4
  60. package/build/lib/jsonwp-status/status.d.ts.map +1 -1
  61. package/build/lib/jsonwp-status/status.js +2 -2
  62. package/build/lib/protocol/errors.d.ts +17 -8
  63. package/build/lib/protocol/errors.d.ts.map +1 -1
  64. package/build/lib/protocol/errors.js +9 -5
  65. package/build/lib/protocol/helpers.js +1 -1
  66. package/build/lib/protocol/index.js +1 -1
  67. package/build/lib/protocol/protocol.d.ts.map +1 -1
  68. package/build/lib/protocol/protocol.js +1 -1
  69. package/build/lib/protocol/routes.d.ts +17 -3
  70. package/build/lib/protocol/routes.d.ts.map +1 -1
  71. package/build/lib/protocol/routes.js +1 -1
  72. package/build/lib/protocol/validators.js +1 -1
  73. package/build/test/basedriver/driver-e2e-tests.js +1 -1
  74. package/build/test/basedriver/driver-tests.js +1 -1
  75. package/build/test/basedriver/index.js +1 -1
  76. package/build/test/e2e/basedriver/driver.e2e.spec.js +1 -1
  77. package/build/test/e2e/basedriver/helpers.e2e.spec.js +1 -1
  78. package/build/test/e2e/basedriver/websockets.e2e.spec.js +1 -1
  79. package/build/test/e2e/express/server.e2e.spec.js +1 -1
  80. package/build/test/e2e/jsonwp-proxy/proxy.e2e.spec.js +1 -1
  81. package/build/test/e2e/protocol/fake-driver.js +1 -1
  82. package/build/test/e2e/protocol/helpers.js +1 -1
  83. package/build/test/e2e/protocol/protocol.e2e.spec.js +13 -13
  84. package/build/test/helpers.js +1 -1
  85. package/build/test/unit/basedriver/capabilities.spec.js +12 -12
  86. package/build/test/unit/basedriver/capability.spec.js +15 -15
  87. package/build/test/unit/basedriver/commands/event.spec.js +1 -1
  88. package/build/test/unit/basedriver/commands/log.spec.js +1 -1
  89. package/build/test/unit/basedriver/device-settings.spec.js +1 -1
  90. package/build/test/unit/basedriver/driver.spec.js +1 -1
  91. package/build/test/unit/basedriver/helpers.spec.js +33 -33
  92. package/build/test/unit/basedriver/timeout.spec.js +1 -1
  93. package/build/test/unit/express/server.spec.js +1 -1
  94. package/build/test/unit/express/static.spec.js +2 -2
  95. package/build/test/unit/jsonwp-proxy/mock-request.js +1 -1
  96. package/build/test/unit/jsonwp-proxy/protocol-converter.spec.js +1 -1
  97. package/build/test/unit/jsonwp-proxy/proxy.spec.js +2 -2
  98. package/build/test/unit/jsonwp-proxy/url.spec.js +1 -1
  99. package/build/test/unit/jsonwp-status/status.spec.js +1 -1
  100. package/build/test/unit/protocol/errors.spec.js +1 -1
  101. package/build/test/unit/protocol/routes.spec.js +1 -1
  102. package/build/test/unit/protocol/validator.spec.js +1 -1
  103. package/build/tsconfig.tsbuildinfo +1 -1
  104. package/lib/basedriver/capabilities.js +95 -47
  105. package/lib/basedriver/commands/event.js +4 -4
  106. package/lib/basedriver/commands/find.js +12 -26
  107. package/lib/basedriver/commands/index.js +7 -7
  108. package/lib/basedriver/commands/log.js +5 -7
  109. package/lib/basedriver/commands/session.js +3 -3
  110. package/lib/basedriver/commands/settings.js +3 -5
  111. package/lib/basedriver/commands/timeout.js +18 -23
  112. package/lib/basedriver/core.js +150 -229
  113. package/lib/basedriver/desired-caps.js +30 -29
  114. package/lib/basedriver/device-settings.js +21 -20
  115. package/lib/basedriver/driver.js +131 -96
  116. package/lib/basedriver/helpers.js +124 -81
  117. package/lib/basedriver/logger.js +1 -1
  118. package/lib/constants.js +2 -6
  119. package/lib/express/crash.js +4 -6
  120. package/lib/express/express-logging.js +26 -24
  121. package/lib/express/idempotency.js +16 -16
  122. package/lib/express/logger.js +1 -1
  123. package/lib/express/middleware.js +49 -33
  124. package/lib/express/server.js +68 -44
  125. package/lib/express/static.js +11 -12
  126. package/lib/express/websocket.js +26 -16
  127. package/lib/helpers/capabilities.js +11 -16
  128. package/lib/index.js +50 -33
  129. package/lib/jsonwp-proxy/protocol-converter.js +85 -69
  130. package/lib/jsonwp-proxy/proxy.js +116 -53
  131. package/lib/jsonwp-status/status.js +36 -29
  132. package/lib/protocol/errors.js +469 -292
  133. package/lib/protocol/helpers.js +5 -8
  134. package/lib/protocol/index.js +22 -15
  135. package/lib/protocol/protocol.js +103 -55
  136. package/lib/protocol/routes.js +430 -273
  137. package/lib/protocol/validators.js +5 -5
  138. package/package.json +9 -11
  139. package/test/basedriver/driver-e2e-tests.js +92 -66
  140. package/test/basedriver/driver-tests.js +90 -33
  141. package/test/basedriver/index.js +1 -1
@@ -1,7 +1,7 @@
1
1
  import ES6Error from 'es6-error';
2
2
  import _ from 'lodash';
3
- import { util, logger } from '@appium/support';
4
- import { StatusCodes as HTTPStatusCodes } from 'http-status-codes';
3
+ import {util, logger} from '@appium/support';
4
+ import {StatusCodes as HTTPStatusCodes} from 'http-status-codes';
5
5
 
6
6
  const mjsonwpLog = logger.getLogger('MJSONWP');
7
7
  const w3cLog = logger.getLogger('W3C');
@@ -10,7 +10,7 @@ const W3C_UNKNOWN_ERROR = 'unknown error';
10
10
 
11
11
  // base error class for all of our errors
12
12
  export class ProtocolError extends ES6Error {
13
- constructor (msg, jsonwpCode, w3cStatus, error) {
13
+ constructor(msg, jsonwpCode, w3cStatus, error) {
14
14
  super(msg);
15
15
  this.jsonwpCode = jsonwpCode;
16
16
  this.error = error || W3C_UNKNOWN_ERROR;
@@ -21,11 +21,11 @@ export class ProtocolError extends ES6Error {
21
21
  this._stacktrace = null;
22
22
  }
23
23
 
24
- get stacktrace () {
24
+ get stacktrace() {
25
25
  return this._stacktrace || this.stack;
26
26
  }
27
27
 
28
- set stacktrace (value) {
28
+ set stacktrace(value) {
29
29
  this._stacktrace = value;
30
30
  }
31
31
  }
@@ -35,587 +35,719 @@ export class ProtocolError extends ES6Error {
35
35
  // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-error-code
36
36
 
37
37
  export class NoSuchDriverError extends ProtocolError {
38
- static code () {
38
+ static code() {
39
39
  return 6;
40
40
  }
41
41
  // W3C Error is called InvalidSessionID
42
- static w3cStatus () {
42
+ static w3cStatus() {
43
43
  return HTTPStatusCodes.NOT_FOUND;
44
44
  }
45
- static error () {
45
+ static error() {
46
46
  return 'invalid session id';
47
47
  }
48
- constructor (err) {
49
- super(err || 'A session is either terminated or not started', NoSuchDriverError.code(),
50
- NoSuchDriverError.w3cStatus(), NoSuchDriverError.error());
48
+ constructor(err) {
49
+ super(
50
+ err || 'A session is either terminated or not started',
51
+ NoSuchDriverError.code(),
52
+ NoSuchDriverError.w3cStatus(),
53
+ NoSuchDriverError.error()
54
+ );
51
55
  }
52
56
  }
53
57
 
54
58
  export class NoSuchElementError extends ProtocolError {
55
- static code () {
59
+ static code() {
56
60
  return 7;
57
61
  }
58
- static w3cStatus () {
62
+ static w3cStatus() {
59
63
  return HTTPStatusCodes.NOT_FOUND;
60
64
  }
61
- static error () {
65
+ static error() {
62
66
  return 'no such element';
63
67
  }
64
- constructor (err) {
65
- super(err || 'An element could not be located on the page using the given ' +
66
- 'search parameters.', NoSuchElementError.code(), NoSuchElementError.w3cStatus(),
67
- NoSuchElementError.error());
68
+ constructor(err) {
69
+ super(
70
+ err || 'An element could not be located on the page using the given ' + 'search parameters.',
71
+ NoSuchElementError.code(),
72
+ NoSuchElementError.w3cStatus(),
73
+ NoSuchElementError.error()
74
+ );
68
75
  }
69
76
  }
70
77
 
71
78
  export class NoSuchFrameError extends ProtocolError {
72
- static code () {
79
+ static code() {
73
80
  return 8;
74
81
  }
75
- static error () {
82
+ static error() {
76
83
  return 'no such frame';
77
84
  }
78
- static w3cStatus () {
85
+ static w3cStatus() {
79
86
  return HTTPStatusCodes.NOT_FOUND;
80
87
  }
81
- constructor (err) {
82
- super(err || 'A request to switch to a frame could not be satisfied because ' +
83
- 'the frame could not be found.', NoSuchFrameError.code(),
84
- NoSuchFrameError.w3cStatus(), NoSuchFrameError.error());
88
+ constructor(err) {
89
+ super(
90
+ err ||
91
+ 'A request to switch to a frame could not be satisfied because ' +
92
+ 'the frame could not be found.',
93
+ NoSuchFrameError.code(),
94
+ NoSuchFrameError.w3cStatus(),
95
+ NoSuchFrameError.error()
96
+ );
85
97
  }
86
98
  }
87
99
 
88
100
  export class UnknownCommandError extends ProtocolError {
89
- static code () {
101
+ static code() {
90
102
  return 9;
91
103
  }
92
- static w3cStatus () {
104
+ static w3cStatus() {
93
105
  return HTTPStatusCodes.NOT_FOUND;
94
106
  }
95
- static error () {
107
+ static error() {
96
108
  return 'unknown command';
97
109
  }
98
- constructor (err) {
99
- super(err || 'The requested resource could not be found, or a request was ' +
110
+ constructor(err) {
111
+ super(
112
+ err ||
113
+ 'The requested resource could not be found, or a request was ' +
100
114
  'received using an HTTP method that is not supported by the mapped ' +
101
- 'resource.', UnknownCommandError.code(), UnknownCommandError.w3cStatus(), UnknownCommandError.error());
115
+ 'resource.',
116
+ UnknownCommandError.code(),
117
+ UnknownCommandError.w3cStatus(),
118
+ UnknownCommandError.error()
119
+ );
102
120
  }
103
121
  }
104
122
 
105
123
  export class StaleElementReferenceError extends ProtocolError {
106
- static code () {
124
+ static code() {
107
125
  return 10;
108
126
  }
109
- static w3cStatus () {
127
+ static w3cStatus() {
110
128
  return HTTPStatusCodes.NOT_FOUND;
111
129
  }
112
- static error () {
130
+ static error() {
113
131
  return 'stale element reference';
114
132
  }
115
- constructor (err) {
116
- super(err || 'An element command failed because the referenced element is no ' +
117
- 'longer attached to the DOM.', StaleElementReferenceError.code(),
118
- StaleElementReferenceError.w3cStatus(), StaleElementReferenceError.error());
133
+ constructor(err) {
134
+ super(
135
+ err ||
136
+ 'An element command failed because the referenced element is no ' +
137
+ 'longer attached to the DOM.',
138
+ StaleElementReferenceError.code(),
139
+ StaleElementReferenceError.w3cStatus(),
140
+ StaleElementReferenceError.error()
141
+ );
119
142
  }
120
143
  }
121
144
 
122
145
  export class ElementNotVisibleError extends ProtocolError {
123
- static code () {
146
+ static code() {
124
147
  return 11;
125
148
  }
126
- static w3cStatus () {
149
+ static w3cStatus() {
127
150
  return HTTPStatusCodes.BAD_REQUEST;
128
151
  }
129
- static error () {
152
+ static error() {
130
153
  return 'element not visible';
131
154
  }
132
- constructor (err) {
133
- super(err || 'An element command could not be completed because the element is ' +
134
- 'not visible on the page.', ElementNotVisibleError.code(),
135
- ElementNotVisibleError.w3cStatus(), ElementNotVisibleError.error());
155
+ constructor(err) {
156
+ super(
157
+ err ||
158
+ 'An element command could not be completed because the element is ' +
159
+ 'not visible on the page.',
160
+ ElementNotVisibleError.code(),
161
+ ElementNotVisibleError.w3cStatus(),
162
+ ElementNotVisibleError.error()
163
+ );
136
164
  }
137
165
  }
138
166
 
139
167
  export class InvalidElementStateError extends ProtocolError {
140
- static code () {
168
+ static code() {
141
169
  return 12;
142
170
  }
143
- static w3cStatus () {
171
+ static w3cStatus() {
144
172
  return HTTPStatusCodes.BAD_REQUEST;
145
173
  }
146
- static error () {
174
+ static error() {
147
175
  return 'invalid element state';
148
176
  }
149
- constructor (err) {
150
- super(err || 'An element command could not be completed because the element is ' +
177
+ constructor(err) {
178
+ super(
179
+ err ||
180
+ 'An element command could not be completed because the element is ' +
151
181
  'in an invalid state (e.g. attempting to click a disabled element).',
152
- InvalidElementStateError.code(), InvalidElementStateError.w3cStatus(),
153
- InvalidElementStateError.error());
182
+ InvalidElementStateError.code(),
183
+ InvalidElementStateError.w3cStatus(),
184
+ InvalidElementStateError.error()
185
+ );
154
186
  }
155
187
  }
156
188
 
157
189
  export class UnknownError extends ProtocolError {
158
- static code () {
190
+ static code() {
159
191
  return 13;
160
192
  }
161
- static w3cStatus () {
193
+ static w3cStatus() {
162
194
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
163
195
  }
164
- static error () {
196
+ static error() {
165
197
  return W3C_UNKNOWN_ERROR;
166
198
  }
167
- constructor (errorOrMessage) {
199
+ constructor(errorOrMessage) {
168
200
  const origMessage = _.isString((errorOrMessage || {}).message)
169
201
  ? errorOrMessage.message
170
202
  : errorOrMessage;
171
- const message = 'An unknown server-side error occurred while processing the command.' +
203
+ const message =
204
+ 'An unknown server-side error occurred while processing the command.' +
172
205
  (origMessage ? ` Original error: ${origMessage}` : '');
173
206
  super(message, UnknownError.code(), UnknownError.w3cStatus(), UnknownError.error());
174
207
  }
175
208
  }
176
209
 
177
210
  export class UnknownMethodError extends ProtocolError {
178
- static code () {
211
+ static code() {
179
212
  return 405;
180
213
  }
181
- static w3cStatus () {
214
+ static w3cStatus() {
182
215
  return HTTPStatusCodes.METHOD_NOT_ALLOWED;
183
216
  }
184
- static error () {
217
+ static error() {
185
218
  return 'unknown method';
186
219
  }
187
- constructor (err) {
188
- super(err || 'The requested command matched a known URL but did not match an method for that URL',
189
- UnknownMethodError.code(), UnknownMethodError.w3cStatus(), UnknownMethodError.error());
220
+ constructor(err) {
221
+ super(
222
+ err || 'The requested command matched a known URL but did not match an method for that URL',
223
+ UnknownMethodError.code(),
224
+ UnknownMethodError.w3cStatus(),
225
+ UnknownMethodError.error()
226
+ );
190
227
  }
191
228
  }
192
229
 
193
230
  export class UnsupportedOperationError extends ProtocolError {
194
- static code () {
231
+ static code() {
195
232
  return 405;
196
233
  }
197
- static w3cStatus () {
234
+ static w3cStatus() {
198
235
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
199
236
  }
200
- static error () {
237
+ static error() {
201
238
  return 'unsupported operation';
202
239
  }
203
- constructor (err) {
204
- super(err || 'A server-side error occurred. Command cannot be supported.',
205
- UnsupportedOperationError.code(), UnsupportedOperationError.w3cStatus(),
206
- UnsupportedOperationError.error());
240
+ constructor(err) {
241
+ super(
242
+ err || 'A server-side error occurred. Command cannot be supported.',
243
+ UnsupportedOperationError.code(),
244
+ UnsupportedOperationError.w3cStatus(),
245
+ UnsupportedOperationError.error()
246
+ );
207
247
  }
208
248
  }
209
249
 
210
250
  export class ElementIsNotSelectableError extends ProtocolError {
211
- static code () {
251
+ static code() {
212
252
  return 15;
213
253
  }
214
- static error () {
254
+ static error() {
215
255
  return 'element not selectable';
216
256
  }
217
- static w3cStatus () {
257
+ static w3cStatus() {
218
258
  return HTTPStatusCodes.BAD_REQUEST;
219
259
  }
220
- constructor (err) {
221
- super(err || 'An attempt was made to select an element that cannot be selected.',
222
- ElementIsNotSelectableError.code(), ElementIsNotSelectableError.w3cStatus(),
223
- ElementIsNotSelectableError.error());
260
+ constructor(err) {
261
+ super(
262
+ err || 'An attempt was made to select an element that cannot be selected.',
263
+ ElementIsNotSelectableError.code(),
264
+ ElementIsNotSelectableError.w3cStatus(),
265
+ ElementIsNotSelectableError.error()
266
+ );
224
267
  }
225
268
  }
226
269
 
227
270
  export class ElementClickInterceptedError extends ProtocolError {
228
- static code () {
271
+ static code() {
229
272
  return 64;
230
273
  }
231
- static error () {
274
+ static error() {
232
275
  return 'element click intercepted';
233
276
  }
234
- static w3cStatus () {
277
+ static w3cStatus() {
235
278
  return HTTPStatusCodes.BAD_REQUEST;
236
279
  }
237
- constructor (err) {
238
- super(err || 'The Element Click command could not be completed because the element receiving ' +
280
+ constructor(err) {
281
+ super(
282
+ err ||
283
+ 'The Element Click command could not be completed because the element receiving ' +
239
284
  'the events is obscuring the element that was requested clicked',
240
- ElementClickInterceptedError.code(), ElementClickInterceptedError.w3cStatus(),
241
- ElementClickInterceptedError.error());
285
+ ElementClickInterceptedError.code(),
286
+ ElementClickInterceptedError.w3cStatus(),
287
+ ElementClickInterceptedError.error()
288
+ );
242
289
  }
243
290
  }
244
291
 
245
292
  export class ElementNotInteractableError extends ProtocolError {
246
- static code () {
293
+ static code() {
247
294
  return 60;
248
295
  }
249
- static error () {
296
+ static error() {
250
297
  return 'element not interactable';
251
298
  }
252
- static w3cStatus () {
299
+ static w3cStatus() {
253
300
  return HTTPStatusCodes.BAD_REQUEST;
254
301
  }
255
- constructor (err) {
256
- super(err || 'A command could not be completed because the element is not pointer- or keyboard interactable',
257
- ElementNotInteractableError.code(), ElementNotInteractableError.w3cStatus(),
258
- ElementNotInteractableError.error());
302
+ constructor(err) {
303
+ super(
304
+ err ||
305
+ 'A command could not be completed because the element is not pointer- or keyboard interactable',
306
+ ElementNotInteractableError.code(),
307
+ ElementNotInteractableError.w3cStatus(),
308
+ ElementNotInteractableError.error()
309
+ );
259
310
  }
260
311
  }
261
312
 
262
313
  export class InsecureCertificateError extends ProtocolError {
263
- static error () {
314
+ static error() {
264
315
  return 'insecure certificate';
265
316
  }
266
- constructor (err) {
267
- super(err || 'Navigation caused the user agent to hit a certificate warning, which is usually the result of an expired or invalid TLS certificate',
268
- ElementIsNotSelectableError.code(), null, InsecureCertificateError.error());
317
+ constructor(err) {
318
+ super(
319
+ err ||
320
+ 'Navigation caused the user agent to hit a certificate warning, which is usually the result of an expired or invalid TLS certificate',
321
+ ElementIsNotSelectableError.code(),
322
+ null,
323
+ InsecureCertificateError.error()
324
+ );
269
325
  }
270
326
  }
271
327
 
272
328
  export class JavaScriptError extends ProtocolError {
273
- static code () {
329
+ static code() {
274
330
  return 17;
275
331
  }
276
- static w3cStatus () {
332
+ static w3cStatus() {
277
333
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
278
334
  }
279
- static error () {
335
+ static error() {
280
336
  return 'javascript error';
281
337
  }
282
- constructor (err) {
283
- super(err || 'An error occurred while executing user supplied JavaScript.',
284
- JavaScriptError.code(), JavaScriptError.w3cStatus(), JavaScriptError.error());
338
+ constructor(err) {
339
+ super(
340
+ err || 'An error occurred while executing user supplied JavaScript.',
341
+ JavaScriptError.code(),
342
+ JavaScriptError.w3cStatus(),
343
+ JavaScriptError.error()
344
+ );
285
345
  }
286
346
  }
287
347
 
288
348
  export class XPathLookupError extends ProtocolError {
289
- static code () {
349
+ static code() {
290
350
  return 19;
291
351
  }
292
- static w3cStatus () {
352
+ static w3cStatus() {
293
353
  return HTTPStatusCodes.BAD_REQUEST;
294
354
  }
295
- static error () {
355
+ static error() {
296
356
  return 'invalid selector';
297
357
  }
298
- constructor (err) {
299
- super(err || 'An error occurred while searching for an element by XPath.',
300
- XPathLookupError.code(), XPathLookupError.w3cStatus(), XPathLookupError.error());
358
+ constructor(err) {
359
+ super(
360
+ err || 'An error occurred while searching for an element by XPath.',
361
+ XPathLookupError.code(),
362
+ XPathLookupError.w3cStatus(),
363
+ XPathLookupError.error()
364
+ );
301
365
  }
302
366
  }
303
367
 
304
368
  export class TimeoutError extends ProtocolError {
305
- static code () {
369
+ static code() {
306
370
  return 21;
307
371
  }
308
- static w3cStatus () {
372
+ static w3cStatus() {
309
373
  return HTTPStatusCodes.REQUEST_TIMEOUT;
310
374
  }
311
- static error () {
375
+ static error() {
312
376
  return 'timeout';
313
377
  }
314
- constructor (err) {
315
- super(err || 'An operation did not complete before its timeout expired.',
316
- TimeoutError.code(), TimeoutError.w3cStatus(), TimeoutError.error());
378
+ constructor(err) {
379
+ super(
380
+ err || 'An operation did not complete before its timeout expired.',
381
+ TimeoutError.code(),
382
+ TimeoutError.w3cStatus(),
383
+ TimeoutError.error()
384
+ );
317
385
  }
318
386
  }
319
387
 
320
388
  export class NoSuchWindowError extends ProtocolError {
321
- static code () {
389
+ static code() {
322
390
  return 23;
323
391
  }
324
- static error () {
392
+ static error() {
325
393
  return 'no such window';
326
394
  }
327
- static w3cStatus () {
395
+ static w3cStatus() {
328
396
  return HTTPStatusCodes.NOT_FOUND;
329
397
  }
330
- constructor (err) {
331
- super(err || 'A request to switch to a different window could not be satisfied ' +
332
- 'because the window could not be found.', NoSuchWindowError.code(),
333
- NoSuchWindowError.w3cStatus(), NoSuchWindowError.error());
398
+ constructor(err) {
399
+ super(
400
+ err ||
401
+ 'A request to switch to a different window could not be satisfied ' +
402
+ 'because the window could not be found.',
403
+ NoSuchWindowError.code(),
404
+ NoSuchWindowError.w3cStatus(),
405
+ NoSuchWindowError.error()
406
+ );
334
407
  }
335
408
  }
336
409
 
337
410
  export class InvalidArgumentError extends ProtocolError {
338
- static code () {
411
+ static code() {
339
412
  return 61;
340
413
  }
341
- static error () {
414
+ static error() {
342
415
  return 'invalid argument';
343
416
  }
344
- static w3cStatus () {
417
+ static w3cStatus() {
345
418
  return HTTPStatusCodes.BAD_REQUEST;
346
419
  }
347
- constructor (err) {
348
- super(err || 'The arguments passed to the command are either invalid or malformed',
349
- InvalidArgumentError.code(), InvalidArgumentError.w3cStatus(),
350
- InvalidArgumentError.error());
420
+ constructor(err) {
421
+ super(
422
+ err || 'The arguments passed to the command are either invalid or malformed',
423
+ InvalidArgumentError.code(),
424
+ InvalidArgumentError.w3cStatus(),
425
+ InvalidArgumentError.error()
426
+ );
351
427
  }
352
428
  }
353
429
 
354
430
  export class InvalidCookieDomainError extends ProtocolError {
355
- static code () {
431
+ static code() {
356
432
  return 24;
357
433
  }
358
- static error () {
434
+ static error() {
359
435
  return 'invalid cookie domain';
360
436
  }
361
- static w3cStatus () {
437
+ static w3cStatus() {
362
438
  return HTTPStatusCodes.BAD_REQUEST;
363
439
  }
364
- constructor (err) {
365
- super(err || 'An illegal attempt was made to set a cookie under a different ' +
366
- 'domain than the current page.', InvalidCookieDomainError.code(),
367
- InvalidCookieDomainError.w3cStatus(), InvalidCookieDomainError.error());
440
+ constructor(err) {
441
+ super(
442
+ err ||
443
+ 'An illegal attempt was made to set a cookie under a different ' +
444
+ 'domain than the current page.',
445
+ InvalidCookieDomainError.code(),
446
+ InvalidCookieDomainError.w3cStatus(),
447
+ InvalidCookieDomainError.error()
448
+ );
368
449
  }
369
450
  }
370
451
 
371
452
  export class NoSuchCookieError extends ProtocolError {
372
- static code () {
453
+ static code() {
373
454
  return 62;
374
455
  }
375
- static w3cStatus () {
456
+ static w3cStatus() {
376
457
  return HTTPStatusCodes.NOT_FOUND;
377
458
  }
378
- static error () {
459
+ static error() {
379
460
  return 'no such cookie';
380
461
  }
381
- constructor (err) {
382
- super(err || 'No cookie matching the given path name was found amongst the associated cookies of the current browsing context’s active document',
383
- NoSuchCookieError.code(), NoSuchCookieError.w3cStatus(), NoSuchCookieError.error());
462
+ constructor(err) {
463
+ super(
464
+ err ||
465
+ 'No cookie matching the given path name was found amongst the associated cookies of the current browsing context’s active document',
466
+ NoSuchCookieError.code(),
467
+ NoSuchCookieError.w3cStatus(),
468
+ NoSuchCookieError.error()
469
+ );
384
470
  }
385
471
  }
386
472
 
387
473
  export class UnableToSetCookieError extends ProtocolError {
388
- static code () {
474
+ static code() {
389
475
  return 25;
390
476
  }
391
- static w3cStatus () {
477
+ static w3cStatus() {
392
478
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
393
479
  }
394
- static error () {
480
+ static error() {
395
481
  return 'unable to set cookie';
396
482
  }
397
- constructor (err) {
398
- super(err || 'A request to set a cookie\'s value could not be satisfied.',
399
- UnableToSetCookieError.code(), UnableToSetCookieError.w3cStatus(), UnableToSetCookieError.error());
483
+ constructor(err) {
484
+ super(
485
+ err || "A request to set a cookie's value could not be satisfied.",
486
+ UnableToSetCookieError.code(),
487
+ UnableToSetCookieError.w3cStatus(),
488
+ UnableToSetCookieError.error()
489
+ );
400
490
  }
401
491
  }
402
492
 
403
493
  export class UnexpectedAlertOpenError extends ProtocolError {
404
- static code () {
494
+ static code() {
405
495
  return 26;
406
496
  }
407
- static w3cStatus () {
497
+ static w3cStatus() {
408
498
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
409
499
  }
410
- static error () {
500
+ static error() {
411
501
  return 'unexpected alert open';
412
502
  }
413
- constructor (err) {
414
- super(err || 'A modal dialog was open, blocking this operation',
415
- UnexpectedAlertOpenError.code(), UnexpectedAlertOpenError.w3cStatus(), UnexpectedAlertOpenError.error());
503
+ constructor(err) {
504
+ super(
505
+ err || 'A modal dialog was open, blocking this operation',
506
+ UnexpectedAlertOpenError.code(),
507
+ UnexpectedAlertOpenError.w3cStatus(),
508
+ UnexpectedAlertOpenError.error()
509
+ );
416
510
  }
417
511
  }
418
512
 
419
513
  export class NoAlertOpenError extends ProtocolError {
420
- static code () {
514
+ static code() {
421
515
  return 27;
422
516
  }
423
- static w3cStatus () {
517
+ static w3cStatus() {
424
518
  return HTTPStatusCodes.NOT_FOUND;
425
519
  }
426
- static error () {
520
+ static error() {
427
521
  return 'no such alert';
428
522
  }
429
- constructor (err) {
430
- super(err || 'An attempt was made to operate on a modal dialog when one ' +
431
- 'was not open.', NoAlertOpenError.code(), NoAlertOpenError.w3cStatus(), NoAlertOpenError.error());
523
+ constructor(err) {
524
+ super(
525
+ err || 'An attempt was made to operate on a modal dialog when one ' + 'was not open.',
526
+ NoAlertOpenError.code(),
527
+ NoAlertOpenError.w3cStatus(),
528
+ NoAlertOpenError.error()
529
+ );
432
530
  }
433
531
  }
434
532
 
435
533
  export class NoSuchAlertError extends NoAlertOpenError {}
436
534
 
437
535
  export class ScriptTimeoutError extends ProtocolError {
438
- static code () {
536
+ static code() {
439
537
  return 28;
440
538
  }
441
- static w3cStatus () {
539
+ static w3cStatus() {
442
540
  return HTTPStatusCodes.REQUEST_TIMEOUT;
443
541
  }
444
- static error () {
542
+ static error() {
445
543
  return 'script timeout';
446
544
  }
447
- constructor (err) {
448
- super(err || 'A script did not complete before its timeout expired.',
449
- ScriptTimeoutError.code(), ScriptTimeoutError.w3cStatus(), ScriptTimeoutError.error());
545
+ constructor(err) {
546
+ super(
547
+ err || 'A script did not complete before its timeout expired.',
548
+ ScriptTimeoutError.code(),
549
+ ScriptTimeoutError.w3cStatus(),
550
+ ScriptTimeoutError.error()
551
+ );
450
552
  }
451
553
  }
452
554
 
453
555
  export class InvalidElementCoordinatesError extends ProtocolError {
454
- static code () {
556
+ static code() {
455
557
  return 29;
456
558
  }
457
- static w3cStatus () {
559
+ static w3cStatus() {
458
560
  return HTTPStatusCodes.BAD_REQUEST;
459
561
  }
460
- static error () {
562
+ static error() {
461
563
  return 'invalid coordinates';
462
564
  }
463
- constructor (err) {
464
- super(err || 'The coordinates provided to an interactions operation are invalid.',
465
- InvalidElementCoordinatesError.code(), InvalidElementCoordinatesError.w3cStatus(),
466
- InvalidElementCoordinatesError.error());
565
+ constructor(err) {
566
+ super(
567
+ err || 'The coordinates provided to an interactions operation are invalid.',
568
+ InvalidElementCoordinatesError.code(),
569
+ InvalidElementCoordinatesError.w3cStatus(),
570
+ InvalidElementCoordinatesError.error()
571
+ );
467
572
  }
468
573
  }
469
574
 
470
575
  export class InvalidCoordinatesError extends InvalidElementCoordinatesError {}
471
576
 
472
577
  export class IMENotAvailableError extends ProtocolError {
473
- static code () {
578
+ static code() {
474
579
  return 30;
475
580
  }
476
- static w3cStatus () {
581
+ static w3cStatus() {
477
582
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
478
583
  }
479
- static error () {
584
+ static error() {
480
585
  return 'unsupported operation';
481
586
  }
482
- constructor (err) {
483
- super(err || 'IME was not available.', IMENotAvailableError.code(),
484
- IMENotAvailableError.w3cStatus(), IMENotAvailableError.error());
587
+ constructor(err) {
588
+ super(
589
+ err || 'IME was not available.',
590
+ IMENotAvailableError.code(),
591
+ IMENotAvailableError.w3cStatus(),
592
+ IMENotAvailableError.error()
593
+ );
485
594
  }
486
595
  }
487
596
 
488
597
  export class IMEEngineActivationFailedError extends ProtocolError {
489
- static code () {
598
+ static code() {
490
599
  return 31;
491
600
  }
492
- static w3cStatus () {
601
+ static w3cStatus() {
493
602
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
494
603
  }
495
- static error () {
604
+ static error() {
496
605
  return 'unsupported operation';
497
606
  }
498
- constructor (err) {
499
- super(err || 'An IME engine could not be started.',
500
- IMEEngineActivationFailedError.code(), IMEEngineActivationFailedError.w3cStatus(),
501
- IMEEngineActivationFailedError.error());
607
+ constructor(err) {
608
+ super(
609
+ err || 'An IME engine could not be started.',
610
+ IMEEngineActivationFailedError.code(),
611
+ IMEEngineActivationFailedError.w3cStatus(),
612
+ IMEEngineActivationFailedError.error()
613
+ );
502
614
  }
503
615
  }
504
616
 
505
617
  export class InvalidSelectorError extends ProtocolError {
506
- static code () {
618
+ static code() {
507
619
  return 32;
508
620
  }
509
- static w3cStatus () {
621
+ static w3cStatus() {
510
622
  return HTTPStatusCodes.BAD_REQUEST;
511
623
  }
512
- static error () {
624
+ static error() {
513
625
  return 'invalid selector';
514
626
  }
515
- constructor (err) {
516
- super(err || 'Argument was an invalid selector (e.g. XPath/CSS).',
517
- InvalidSelectorError.code(), InvalidSelectorError.w3cStatus(),
518
- InvalidSelectorError.error());
627
+ constructor(err) {
628
+ super(
629
+ err || 'Argument was an invalid selector (e.g. XPath/CSS).',
630
+ InvalidSelectorError.code(),
631
+ InvalidSelectorError.w3cStatus(),
632
+ InvalidSelectorError.error()
633
+ );
519
634
  }
520
635
  }
521
636
 
522
637
  export class SessionNotCreatedError extends ProtocolError {
523
- static code () {
638
+ static code() {
524
639
  return 33;
525
640
  }
526
- static w3cStatus () {
641
+ static w3cStatus() {
527
642
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
528
643
  }
529
- static error () {
644
+ static error() {
530
645
  return 'session not created';
531
646
  }
532
- constructor (details) {
647
+ constructor(details) {
533
648
  let message = 'A new session could not be created.';
534
649
  if (details) {
535
650
  message += ` Details: ${details}`;
536
651
  }
537
652
 
538
- super(message, SessionNotCreatedError.code(), SessionNotCreatedError.w3cStatus(), SessionNotCreatedError.error());
653
+ super(
654
+ message,
655
+ SessionNotCreatedError.code(),
656
+ SessionNotCreatedError.w3cStatus(),
657
+ SessionNotCreatedError.error()
658
+ );
539
659
  }
540
660
  }
541
661
 
542
662
  export class MoveTargetOutOfBoundsError extends ProtocolError {
543
- static code () {
663
+ static code() {
544
664
  return 34;
545
665
  }
546
- static w3cStatus () {
666
+ static w3cStatus() {
547
667
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
548
668
  }
549
- static error () {
669
+ static error() {
550
670
  return 'move target out of bounds';
551
671
  }
552
- constructor (err) {
553
- super(err || 'Target provided for a move action is out of bounds.',
554
- MoveTargetOutOfBoundsError.code(), MoveTargetOutOfBoundsError.w3cStatus(), MoveTargetOutOfBoundsError.error());
672
+ constructor(err) {
673
+ super(
674
+ err || 'Target provided for a move action is out of bounds.',
675
+ MoveTargetOutOfBoundsError.code(),
676
+ MoveTargetOutOfBoundsError.w3cStatus(),
677
+ MoveTargetOutOfBoundsError.error()
678
+ );
555
679
  }
556
680
  }
557
681
 
558
682
  export class NoSuchContextError extends ProtocolError {
559
- static code () {
683
+ static code() {
560
684
  return 35;
561
685
  }
562
- constructor (err) {
686
+ constructor(err) {
563
687
  super(err || 'No such context found.', NoSuchContextError.code());
564
688
  }
565
689
  }
566
690
 
567
691
  export class InvalidContextError extends ProtocolError {
568
- static code () {
692
+ static code() {
569
693
  return 36;
570
694
  }
571
- constructor (err) {
572
- super(err || 'That command could not be executed in the current context.',
573
- InvalidContextError.code());
695
+ constructor(err) {
696
+ super(
697
+ err || 'That command could not be executed in the current context.',
698
+ InvalidContextError.code()
699
+ );
574
700
  }
575
701
  }
576
702
 
577
703
  // These are aliases for UnknownMethodError
578
704
  export class NotYetImplementedError extends UnknownMethodError {
579
- constructor (err) {
705
+ constructor(err) {
580
706
  super(err || 'Method has not yet been implemented');
581
707
  }
582
708
  }
583
709
  export class NotImplementedError extends UnknownMethodError {
584
- constructor (err) {
710
+ constructor(err) {
585
711
  super(err || 'Method is not implemented');
586
712
  }
587
713
  }
588
714
 
589
715
  export class UnableToCaptureScreen extends ProtocolError {
590
- static code () {
716
+ static code() {
591
717
  return 63;
592
718
  }
593
- static w3cStatus () {
719
+ static w3cStatus() {
594
720
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
595
721
  }
596
- static error () {
722
+ static error() {
597
723
  return 'unable to capture screen';
598
724
  }
599
- constructor (err) {
600
- super(err || 'A screen capture was made impossible',
601
- UnableToCaptureScreen.code(), UnableToCaptureScreen.w3cStatus(), UnableToCaptureScreen.error());
725
+ constructor(err) {
726
+ super(
727
+ err || 'A screen capture was made impossible',
728
+ UnableToCaptureScreen.code(),
729
+ UnableToCaptureScreen.w3cStatus(),
730
+ UnableToCaptureScreen.error()
731
+ );
602
732
  }
603
733
  }
604
734
 
605
-
606
735
  // Equivalent to W3C InvalidArgumentError
607
736
  export class BadParametersError extends ES6Error {
608
- static error () {
737
+ static error() {
609
738
  return 'invalid argument';
610
739
  }
611
- constructor (requiredParams, actualParams, errMessage) {
740
+ constructor(requiredParams, actualParams, errMessage) {
612
741
  let message;
613
742
  if (!errMessage) {
614
- message = `Parameters were incorrect. We wanted ` +
615
- `${JSON.stringify(requiredParams)} and you ` +
616
- `sent ${JSON.stringify(actualParams)}`;
743
+ message =
744
+ `Parameters were incorrect. We wanted ` +
745
+ `${JSON.stringify(requiredParams)} and you ` +
746
+ `sent ${JSON.stringify(actualParams)}`;
617
747
  } else {
618
- message = `Parameters were incorrect. You sent ${JSON.stringify(actualParams)}, ${errMessage}`;
748
+ message = `Parameters were incorrect. You sent ${JSON.stringify(
749
+ actualParams
750
+ )}, ${errMessage}`;
619
751
  }
620
752
  super(message);
621
753
  this.w3cStatus = HTTPStatusCodes.BAD_REQUEST;
@@ -629,7 +761,7 @@ export class BadParametersError extends ES6Error {
629
761
  * for proxy failure to generate the client response.
630
762
  */
631
763
  export class ProxyRequestError extends ES6Error {
632
- constructor (err, responseError, httpStatus) {
764
+ constructor(err, responseError, httpStatus) {
633
765
  let responseErrorObj = util.safeJsonParse(responseError);
634
766
  if (!_.isPlainObject(responseErrorObj)) {
635
767
  responseErrorObj = {};
@@ -638,7 +770,10 @@ export class ProxyRequestError extends ES6Error {
638
770
  if (!_.isEmpty(responseErrorObj)) {
639
771
  if (_.isString(responseErrorObj.value)) {
640
772
  origMessage = responseErrorObj.value;
641
- } else if (_.isPlainObject(responseErrorObj.value) && _.isString(responseErrorObj.value.message)) {
773
+ } else if (
774
+ _.isPlainObject(responseErrorObj.value) &&
775
+ _.isString(responseErrorObj.value.message)
776
+ ) {
642
777
  origMessage = responseErrorObj.value.message;
643
778
  }
644
779
  }
@@ -655,81 +790,89 @@ export class ProxyRequestError extends ES6Error {
655
790
  }
656
791
  }
657
792
 
658
- getActualError () {
793
+ getActualError() {
659
794
  // If it's MJSONWP error, returns actual error cause for request failure based on `jsonwp.status`
660
795
  if (util.hasValue(this.jsonwp?.status) && util.hasValue(this.jsonwp?.value)) {
661
796
  return errorFromMJSONWPStatusCode(this.jsonwp.status, this.jsonwp.value);
662
797
  } else if (util.hasValue(this.w3c) && _.isNumber(this.w3cStatus) && this.w3cStatus >= 300) {
663
- return errorFromW3CJsonCode(this.w3c.error, this.w3c.message || this.message, this.w3c.stacktrace);
798
+ return errorFromW3CJsonCode(
799
+ this.w3c.error,
800
+ this.w3c.message || this.message,
801
+ this.w3c.stacktrace
802
+ );
664
803
  }
665
804
  return new UnknownError(this.message);
666
805
  }
667
806
  }
668
807
  // map of error class name to error class
669
- const errors = {NotYetImplementedError,
670
- NotImplementedError,
671
- BadParametersError,
672
- InvalidArgumentError,
673
- NoSuchDriverError,
674
- NoSuchElementError,
675
- UnknownCommandError,
676
- StaleElementReferenceError,
677
- ElementNotVisibleError,
678
- InvalidElementStateError,
679
- UnknownError,
680
- ElementIsNotSelectableError,
681
- ElementClickInterceptedError,
682
- ElementNotInteractableError,
683
- InsecureCertificateError,
684
- JavaScriptError,
685
- XPathLookupError,
686
- TimeoutError,
687
- NoSuchWindowError,
688
- NoSuchCookieError,
689
- InvalidCookieDomainError,
690
- InvalidCoordinatesError,
691
- UnableToSetCookieError,
692
- UnexpectedAlertOpenError,
693
- NoAlertOpenError,
694
- ScriptTimeoutError,
695
- InvalidElementCoordinatesError,
696
- IMENotAvailableError,
697
- IMEEngineActivationFailedError,
698
- InvalidSelectorError,
699
- SessionNotCreatedError,
700
- MoveTargetOutOfBoundsError,
701
- NoSuchAlertError,
702
- NoSuchContextError,
703
- InvalidContextError,
704
- NoSuchFrameError,
705
- UnableToCaptureScreen,
706
- UnknownMethodError,
707
- UnsupportedOperationError,
708
- ProxyRequestError};
808
+ const errors = {
809
+ NotYetImplementedError,
810
+ NotImplementedError,
811
+ BadParametersError,
812
+ InvalidArgumentError,
813
+ NoSuchDriverError,
814
+ NoSuchElementError,
815
+ UnknownCommandError,
816
+ StaleElementReferenceError,
817
+ ElementNotVisibleError,
818
+ InvalidElementStateError,
819
+ UnknownError,
820
+ ElementIsNotSelectableError,
821
+ ElementClickInterceptedError,
822
+ ElementNotInteractableError,
823
+ InsecureCertificateError,
824
+ JavaScriptError,
825
+ XPathLookupError,
826
+ TimeoutError,
827
+ NoSuchWindowError,
828
+ NoSuchCookieError,
829
+ InvalidCookieDomainError,
830
+ InvalidCoordinatesError,
831
+ UnableToSetCookieError,
832
+ UnexpectedAlertOpenError,
833
+ NoAlertOpenError,
834
+ ScriptTimeoutError,
835
+ InvalidElementCoordinatesError,
836
+ IMENotAvailableError,
837
+ IMEEngineActivationFailedError,
838
+ InvalidSelectorError,
839
+ SessionNotCreatedError,
840
+ MoveTargetOutOfBoundsError,
841
+ NoSuchAlertError,
842
+ NoSuchContextError,
843
+ InvalidContextError,
844
+ NoSuchFrameError,
845
+ UnableToCaptureScreen,
846
+ UnknownMethodError,
847
+ UnsupportedOperationError,
848
+ ProxyRequestError,
849
+ };
709
850
 
710
851
  // map of error code to error class
711
852
  const jsonwpErrorCodeMap = {};
712
853
  for (let ErrorClass of _.values(errors)) {
713
- if (ErrorClass.code) {
854
+ if ('code' in ErrorClass) {
714
855
  jsonwpErrorCodeMap[ErrorClass.code()] = ErrorClass;
715
856
  }
716
857
  }
717
858
 
718
859
  const w3cErrorCodeMap = {};
719
860
  for (let ErrorClass of _.values(errors)) {
720
- if (ErrorClass.error) {
861
+ if ('error' in ErrorClass) {
721
862
  w3cErrorCodeMap[ErrorClass.error()] = ErrorClass;
722
863
  }
723
864
  }
724
865
 
725
- function isUnknownError (err) {
726
- return !err.constructor.name ||
727
- !_.values(errors).find(function equalNames (error) {
728
- return error.name === err.constructor.name;
729
- });
866
+ function isUnknownError(err) {
867
+ return (
868
+ !err.constructor.name ||
869
+ !_.values(errors).find(function equalNames(error) {
870
+ return error.name === err.constructor.name;
871
+ })
872
+ );
730
873
  }
731
874
 
732
- function isErrorType (err, type) {
875
+ function isErrorType(err, type) {
733
876
  // `name` property is the constructor name
734
877
  if (type.name === ProtocolError.name) {
735
878
  // `jsonwpCode` is `0` on success
@@ -755,7 +898,7 @@ function isErrorType (err, type) {
755
898
  * @param {string|Object} value The error message, or an object with a `message` property
756
899
  * @return {ProtocolError} The error that is associated with provided JSONWP status code
757
900
  */
758
- function errorFromMJSONWPStatusCode (code, value = '') {
901
+ function errorFromMJSONWPStatusCode(code, value = '') {
759
902
  // if `value` is an object, pull message from it, otherwise use the plain
760
903
  // value, or default to an empty string, if null
761
904
  const message = (value || {}).message || value || '';
@@ -774,7 +917,7 @@ function errorFromMJSONWPStatusCode (code, value = '') {
774
917
  * @param {?string} stacktrace an optional error stacktrace
775
918
  * @return {ProtocolError} The error that is associated with the W3C error string
776
919
  */
777
- function errorFromW3CJsonCode (code, message, stacktrace = null) {
920
+ function errorFromW3CJsonCode(code, message, stacktrace = null) {
778
921
  if (code && w3cErrorCodeMap[code.toLowerCase()]) {
779
922
  w3cLog.debug(`Matched W3C error code '${code}' to ${w3cErrorCodeMap[code.toLowerCase()].name}`);
780
923
  const resultError = new w3cErrorCodeMap[code.toLowerCase()](message);
@@ -787,20 +930,29 @@ function errorFromW3CJsonCode (code, message, stacktrace = null) {
787
930
  return resultError;
788
931
  }
789
932
 
933
+ /**
934
+ *
935
+ * @param {any} err
936
+ * @returns {err is ProtocolError}
937
+ */
938
+ function isProtocolError(err) {
939
+ return 'w3cStatus' in err;
940
+ }
941
+
790
942
  /**
791
943
  * Convert an Appium error to proper W3C HTTP response
792
- * @param {ProtocolError} err The error that needs to be translated
944
+ * @param {ProtocolError|MJSONWPError} err The error that needs to be translated
793
945
  */
794
- function getResponseForW3CError (err) {
946
+ function getResponseForW3CError(err) {
795
947
  let httpStatus;
796
948
 
797
949
  // W3C defined error message (https://www.w3.org/TR/webdriver/#dfn-error-code)
798
950
  let w3cErrorString;
799
951
 
800
- if (!err.w3cStatus) {
952
+ if (!isProtocolError(err)) {
801
953
  err = util.hasValue(err.status)
802
- // If it's a JSONWP error, find corresponding error
803
- ? errorFromMJSONWPStatusCode(err.status, err.value)
954
+ ? // If it's a JSONWP error, find corresponding error
955
+ errorFromMJSONWPStatusCode(err.status, err.value)
804
956
  : new errors.UnknownError(err.message);
805
957
  }
806
958
 
@@ -823,7 +975,7 @@ function getResponseForW3CError (err) {
823
975
  error: w3cErrorString,
824
976
  message: err.message,
825
977
  stacktrace: err.stacktrace || err.stack,
826
- }
978
+ },
827
979
  };
828
980
  return [httpStatus, httpResBody];
829
981
  }
@@ -832,17 +984,19 @@ function getResponseForW3CError (err) {
832
984
  * Convert an Appium error to a proper JSONWP response
833
985
  * @param {ProtocolError} err The error to be converted
834
986
  */
835
- function getResponseForJsonwpError (err) {
987
+ function getResponseForJsonwpError(err) {
836
988
  if (isUnknownError(err)) {
837
989
  err = new errors.UnknownError(err);
838
990
  }
839
991
  // MJSONWP errors are usually 500 status code so set it to that by default
840
992
  let httpStatus = HTTPStatusCodes.INTERNAL_SERVER_ERROR;
993
+
994
+ /** @type {HttpResultBody} */
841
995
  let httpResBody = {
842
996
  status: err.jsonwpCode,
843
997
  value: {
844
- message: err.message
845
- }
998
+ message: err.message,
999
+ },
846
1000
  };
847
1001
 
848
1002
  if (isErrorType(err, errors.BadParametersError)) {
@@ -850,8 +1004,10 @@ function getResponseForJsonwpError (err) {
850
1004
  mjsonwpLog.debug(`Bad parameters: ${err}`);
851
1005
  httpStatus = HTTPStatusCodes.BAD_REQUEST;
852
1006
  httpResBody = err.message;
853
- } else if (isErrorType(err, errors.NotYetImplementedError) ||
854
- isErrorType(err, errors.NotImplementedError)) {
1007
+ } else if (
1008
+ isErrorType(err, errors.NotYetImplementedError) ||
1009
+ isErrorType(err, errors.NotImplementedError)
1010
+ ) {
855
1011
  // respond with a 501 if the method is not implemented
856
1012
  httpStatus = HTTPStatusCodes.NOT_IMPLEMENTED;
857
1013
  } else if (isErrorType(err, errors.NoSuchDriverError)) {
@@ -859,12 +1015,33 @@ function getResponseForJsonwpError (err) {
859
1015
  httpStatus = HTTPStatusCodes.NOT_FOUND;
860
1016
  }
861
1017
 
862
-
863
1018
  return [httpStatus, httpResBody];
864
1019
  }
865
1020
 
866
1021
  export {
867
- errors, isErrorType, isUnknownError,
868
- errorFromMJSONWPStatusCode, errorFromW3CJsonCode,
869
- getResponseForW3CError, getResponseForJsonwpError,
1022
+ errors,
1023
+ isErrorType,
1024
+ isUnknownError,
1025
+ errorFromMJSONWPStatusCode,
1026
+ errorFromW3CJsonCode,
1027
+ getResponseForW3CError,
1028
+ getResponseForJsonwpError,
870
1029
  };
1030
+
1031
+ /**
1032
+ * @typedef { string | {value: HttpResultBodyValue, status?: number } } HttpResultBody
1033
+ */
1034
+
1035
+ /**
1036
+ * @typedef HttpResultBodyValue
1037
+ * @property {string} [message]
1038
+ * @property {string|Error} [error]
1039
+ * @property {string} [stacktrace]
1040
+ */
1041
+
1042
+ /**
1043
+ * @typedef MJSONWPError
1044
+ * @property {number} status
1045
+ * @property {string|object} value
1046
+ * @property {string} message
1047
+ */