@appium/base-driver 10.3.0 → 10.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 (58) hide show
  1. package/build/lib/basedriver/capabilities.d.ts +4 -0
  2. package/build/lib/basedriver/capabilities.d.ts.map +1 -1
  3. package/build/lib/basedriver/capabilities.js +4 -0
  4. package/build/lib/basedriver/capabilities.js.map +1 -1
  5. package/build/lib/basedriver/commands/execute.js +5 -16
  6. package/build/lib/basedriver/commands/execute.js.map +1 -1
  7. package/build/lib/basedriver/core.d.ts +24 -24
  8. package/build/lib/basedriver/core.d.ts.map +1 -1
  9. package/build/lib/basedriver/core.js +29 -29
  10. package/build/lib/basedriver/core.js.map +1 -1
  11. package/build/lib/basedriver/driver.d.ts.map +1 -1
  12. package/build/lib/basedriver/driver.js +7 -2
  13. package/build/lib/basedriver/driver.js.map +1 -1
  14. package/build/lib/basedriver/extension-core.d.ts +1 -1
  15. package/build/lib/basedriver/extension-core.d.ts.map +1 -1
  16. package/build/lib/basedriver/extension-core.js +1 -1
  17. package/build/lib/basedriver/extension-core.js.map +1 -1
  18. package/build/lib/basedriver/helpers.d.ts.map +1 -1
  19. package/build/lib/basedriver/helpers.js +2 -2
  20. package/build/lib/basedriver/helpers.js.map +1 -1
  21. package/build/lib/helpers/levenshtein-match.d.ts +27 -0
  22. package/build/lib/helpers/levenshtein-match.d.ts.map +1 -0
  23. package/build/lib/helpers/levenshtein-match.js +61 -0
  24. package/build/lib/helpers/levenshtein-match.js.map +1 -0
  25. package/build/lib/jsonwp-proxy/protocol-converter.d.ts +1 -1
  26. package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
  27. package/build/lib/jsonwp-proxy/protocol-converter.js +3 -3
  28. package/build/lib/jsonwp-proxy/protocol-converter.js.map +1 -1
  29. package/build/lib/jsonwp-proxy/proxy.d.ts +9 -9
  30. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
  31. package/build/lib/jsonwp-proxy/proxy.js +13 -13
  32. package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
  33. package/build/lib/protocol/errors.d.ts +45 -45
  34. package/build/lib/protocol/errors.d.ts.map +1 -1
  35. package/build/lib/protocol/errors.js +162 -162
  36. package/build/lib/protocol/errors.js.map +1 -1
  37. package/build/lib/protocol/protocol.d.ts +35 -0
  38. package/build/lib/protocol/protocol.d.ts.map +1 -1
  39. package/build/lib/protocol/protocol.js +105 -77
  40. package/build/lib/protocol/protocol.js.map +1 -1
  41. package/build/lib/protocol/routes.d.ts +6 -0
  42. package/build/lib/protocol/routes.d.ts.map +1 -1
  43. package/build/lib/protocol/routes.js +6 -0
  44. package/build/lib/protocol/routes.js.map +1 -1
  45. package/lib/basedriver/capabilities.ts +4 -0
  46. package/lib/basedriver/commands/execute.ts +5 -17
  47. package/lib/basedriver/core.ts +34 -34
  48. package/lib/basedriver/driver.ts +9 -2
  49. package/lib/basedriver/extension-core.ts +1 -1
  50. package/lib/basedriver/helpers.ts +21 -21
  51. package/lib/helpers/levenshtein-match.ts +74 -0
  52. package/lib/jsonwp-proxy/protocol-converter.ts +4 -4
  53. package/lib/jsonwp-proxy/proxy.ts +16 -16
  54. package/lib/protocol/errors.ts +281 -246
  55. package/lib/protocol/protocol.ts +121 -93
  56. package/lib/protocol/routes.ts +6 -0
  57. package/package.json +7 -7
  58. package/tsconfig.json +6 -0
@@ -41,10 +41,10 @@ class BaseError extends Error {
41
41
 
42
42
  // base error class for all of our errors
43
43
  export class ProtocolError extends BaseError {
44
- protected _stacktrace: string | undefined;
45
44
  public jsonwpCode: number;
46
45
  public error: string;
47
46
  public w3cStatus: number;
47
+ protected _stacktrace: string | undefined;
48
48
 
49
49
  constructor(
50
50
  msg: string,
@@ -93,17 +93,6 @@ export class ProtocolError extends BaseError {
93
93
  // https://w3c.github.io/webdriver/webdriver-spec.html#dfn-error-code
94
94
 
95
95
  export class NoSuchDriverError extends ProtocolError {
96
- static code() {
97
- return 6;
98
- }
99
- // W3C Error is called InvalidSessionID
100
- static w3cStatus() {
101
- return HTTPStatusCodes.NOT_FOUND;
102
- }
103
- static error() {
104
- return 'invalid session id';
105
- }
106
-
107
96
  constructor(message: string = '', cause?: Error) {
108
97
  super(
109
98
  message || 'A session is either terminated or not started',
@@ -113,19 +102,21 @@ export class NoSuchDriverError extends ProtocolError {
113
102
  cause,
114
103
  );
115
104
  }
116
- }
117
105
 
118
- export class NoSuchElementError extends ProtocolError {
119
106
  static code() {
120
- return 7;
107
+ return 6;
121
108
  }
109
+ // W3C Error is called InvalidSessionID
122
110
  static w3cStatus() {
123
111
  return HTTPStatusCodes.NOT_FOUND;
124
112
  }
125
113
  static error() {
126
- return 'no such element';
114
+ return 'invalid session id';
127
115
  }
128
116
 
117
+ }
118
+
119
+ export class NoSuchElementError extends ProtocolError {
129
120
  constructor(message: string = '', cause?: Error) {
130
121
  super(
131
122
  message ||
@@ -136,19 +127,20 @@ export class NoSuchElementError extends ProtocolError {
136
127
  cause,
137
128
  );
138
129
  }
139
- }
140
130
 
141
- export class NoSuchFrameError extends ProtocolError {
142
131
  static code() {
143
- return 8;
144
- }
145
- static error() {
146
- return 'no such frame';
132
+ return 7;
147
133
  }
148
134
  static w3cStatus() {
149
135
  return HTTPStatusCodes.NOT_FOUND;
150
136
  }
137
+ static error() {
138
+ return 'no such element';
139
+ }
140
+
141
+ }
151
142
 
143
+ export class NoSuchFrameError extends ProtocolError {
152
144
  constructor(message: string = '', cause?: Error) {
153
145
  super(
154
146
  message ||
@@ -160,19 +152,20 @@ export class NoSuchFrameError extends ProtocolError {
160
152
  cause,
161
153
  );
162
154
  }
163
- }
164
155
 
165
- export class UnknownCommandError extends ProtocolError {
166
156
  static code() {
167
- return 9;
157
+ return 8;
158
+ }
159
+ static error() {
160
+ return 'no such frame';
168
161
  }
169
162
  static w3cStatus() {
170
163
  return HTTPStatusCodes.NOT_FOUND;
171
164
  }
172
- static error() {
173
- return 'unknown command';
174
- }
175
165
 
166
+ }
167
+
168
+ export class UnknownCommandError extends ProtocolError {
176
169
  constructor(message: string = '', cause?: Error) {
177
170
  super(
178
171
  message ||
@@ -185,19 +178,20 @@ export class UnknownCommandError extends ProtocolError {
185
178
  cause,
186
179
  );
187
180
  }
188
- }
189
181
 
190
- export class StaleElementReferenceError extends ProtocolError {
191
182
  static code() {
192
- return 10;
183
+ return 9;
193
184
  }
194
185
  static w3cStatus() {
195
186
  return HTTPStatusCodes.NOT_FOUND;
196
187
  }
197
188
  static error() {
198
- return 'stale element reference';
189
+ return 'unknown command';
199
190
  }
200
191
 
192
+ }
193
+
194
+ export class StaleElementReferenceError extends ProtocolError {
201
195
  constructor(message: string = '', cause?: Error) {
202
196
  super(
203
197
  message ||
@@ -209,19 +203,20 @@ export class StaleElementReferenceError extends ProtocolError {
209
203
  cause,
210
204
  );
211
205
  }
212
- }
213
206
 
214
- export class ElementNotVisibleError extends ProtocolError {
215
207
  static code() {
216
- return 11;
208
+ return 10;
217
209
  }
218
210
  static w3cStatus() {
219
- return HTTPStatusCodes.BAD_REQUEST;
211
+ return HTTPStatusCodes.NOT_FOUND;
220
212
  }
221
213
  static error() {
222
- return 'element not visible';
214
+ return 'stale element reference';
223
215
  }
224
216
 
217
+ }
218
+
219
+ export class ElementNotVisibleError extends ProtocolError {
225
220
  constructor(message: string = '', cause?: Error) {
226
221
  super(
227
222
  message ||
@@ -233,19 +228,20 @@ export class ElementNotVisibleError extends ProtocolError {
233
228
  cause,
234
229
  );
235
230
  }
236
- }
237
231
 
238
- export class InvalidElementStateError extends ProtocolError {
239
232
  static code() {
240
- return 12;
233
+ return 11;
241
234
  }
242
235
  static w3cStatus() {
243
236
  return HTTPStatusCodes.BAD_REQUEST;
244
237
  }
245
238
  static error() {
246
- return 'invalid element state';
239
+ return 'element not visible';
247
240
  }
248
241
 
242
+ }
243
+
244
+ export class InvalidElementStateError extends ProtocolError {
249
245
  constructor(message: string = '', cause?: Error) {
250
246
  super(
251
247
  message ||
@@ -257,19 +253,20 @@ export class InvalidElementStateError extends ProtocolError {
257
253
  cause,
258
254
  );
259
255
  }
260
- }
261
256
 
262
- export class UnknownError extends ProtocolError {
263
257
  static code() {
264
- return 13;
258
+ return 12;
265
259
  }
266
260
  static w3cStatus() {
267
- return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
261
+ return HTTPStatusCodes.BAD_REQUEST;
268
262
  }
269
263
  static error() {
270
- return 'unknown error';
264
+ return 'invalid element state';
271
265
  }
272
266
 
267
+ }
268
+
269
+ export class UnknownError extends ProtocolError {
273
270
  constructor(message: string = '', cause?: Error) {
274
271
  super(
275
272
  message || 'An unknown server-side error occurred while processing the command.',
@@ -279,19 +276,20 @@ export class UnknownError extends ProtocolError {
279
276
  cause,
280
277
  );
281
278
  }
282
- }
283
279
 
284
- export class UnknownMethodError extends ProtocolError {
285
280
  static code() {
286
- return 405;
281
+ return 13;
287
282
  }
288
283
  static w3cStatus() {
289
- return HTTPStatusCodes.METHOD_NOT_ALLOWED;
284
+ return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
290
285
  }
291
286
  static error() {
292
- return 'unknown method';
287
+ return 'unknown error';
293
288
  }
294
289
 
290
+ }
291
+
292
+ export class UnknownMethodError extends ProtocolError {
295
293
  constructor(message: string = '', cause?: Error) {
296
294
  super(
297
295
  message ||
@@ -302,19 +300,20 @@ export class UnknownMethodError extends ProtocolError {
302
300
  cause,
303
301
  );
304
302
  }
305
- }
306
303
 
307
- export class UnsupportedOperationError extends ProtocolError {
308
304
  static code() {
309
305
  return 405;
310
306
  }
311
307
  static w3cStatus() {
312
- return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
308
+ return HTTPStatusCodes.METHOD_NOT_ALLOWED;
313
309
  }
314
310
  static error() {
315
- return 'unsupported operation';
311
+ return 'unknown method';
316
312
  }
317
313
 
314
+ }
315
+
316
+ export class UnsupportedOperationError extends ProtocolError {
318
317
  constructor(message: string = '', cause?: Error) {
319
318
  super(
320
319
  message || 'A server-side error occurred. Command cannot be supported.',
@@ -324,19 +323,20 @@ export class UnsupportedOperationError extends ProtocolError {
324
323
  cause,
325
324
  );
326
325
  }
327
- }
328
326
 
329
- export class ElementIsNotSelectableError extends ProtocolError {
330
327
  static code() {
331
- return 15;
332
- }
333
- static error() {
334
- return 'element not selectable';
328
+ return 405;
335
329
  }
336
330
  static w3cStatus() {
337
- return HTTPStatusCodes.BAD_REQUEST;
331
+ return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
332
+ }
333
+ static error() {
334
+ return 'unsupported operation';
338
335
  }
339
336
 
337
+ }
338
+
339
+ export class ElementIsNotSelectableError extends ProtocolError {
340
340
  constructor(message: string = '', cause?: Error) {
341
341
  super(
342
342
  message || 'An attempt was made to select an element that cannot be selected.',
@@ -346,19 +346,20 @@ export class ElementIsNotSelectableError extends ProtocolError {
346
346
  cause,
347
347
  );
348
348
  }
349
- }
350
349
 
351
- export class ElementClickInterceptedError extends ProtocolError {
352
350
  static code() {
353
- return 64;
351
+ return 15;
354
352
  }
355
353
  static error() {
356
- return 'element click intercepted';
354
+ return 'element not selectable';
357
355
  }
358
356
  static w3cStatus() {
359
357
  return HTTPStatusCodes.BAD_REQUEST;
360
358
  }
361
359
 
360
+ }
361
+
362
+ export class ElementClickInterceptedError extends ProtocolError {
362
363
  constructor(message: string = '', cause?: Error) {
363
364
  super(
364
365
  message ||
@@ -370,19 +371,20 @@ export class ElementClickInterceptedError extends ProtocolError {
370
371
  cause,
371
372
  );
372
373
  }
373
- }
374
374
 
375
- export class ElementNotInteractableError extends ProtocolError {
376
375
  static code() {
377
- return 60;
376
+ return 64;
378
377
  }
379
378
  static error() {
380
- return 'element not interactable';
379
+ return 'element click intercepted';
381
380
  }
382
381
  static w3cStatus() {
383
382
  return HTTPStatusCodes.BAD_REQUEST;
384
383
  }
385
384
 
385
+ }
386
+
387
+ export class ElementNotInteractableError extends ProtocolError {
386
388
  constructor(message: string = '', cause?: Error) {
387
389
  super(
388
390
  message ||
@@ -393,16 +395,20 @@ export class ElementNotInteractableError extends ProtocolError {
393
395
  cause,
394
396
  );
395
397
  }
396
- }
397
398
 
398
- export class InsecureCertificateError extends ProtocolError {
399
+ static code() {
400
+ return 60;
401
+ }
399
402
  static error() {
400
- return 'insecure certificate';
403
+ return 'element not interactable';
401
404
  }
402
405
  static w3cStatus() {
403
406
  return HTTPStatusCodes.BAD_REQUEST;
404
407
  }
405
408
 
409
+ }
410
+
411
+ export class InsecureCertificateError extends ProtocolError {
406
412
  constructor(message: string = '', cause?: Error) {
407
413
  super(
408
414
  message ||
@@ -413,19 +419,17 @@ export class InsecureCertificateError extends ProtocolError {
413
419
  cause,
414
420
  );
415
421
  }
416
- }
417
422
 
418
- export class JavaScriptError extends ProtocolError {
419
- static code() {
420
- return 17;
423
+ static error() {
424
+ return 'insecure certificate';
421
425
  }
422
426
  static w3cStatus() {
423
- return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
424
- }
425
- static error() {
426
- return 'javascript error';
427
+ return HTTPStatusCodes.BAD_REQUEST;
427
428
  }
428
429
 
430
+ }
431
+
432
+ export class JavaScriptError extends ProtocolError {
429
433
  constructor(message: string = '', cause?: Error) {
430
434
  super(
431
435
  message || 'An error occurred while executing user supplied JavaScript.',
@@ -435,19 +439,20 @@ export class JavaScriptError extends ProtocolError {
435
439
  cause,
436
440
  );
437
441
  }
438
- }
439
442
 
440
- export class XPathLookupError extends ProtocolError {
441
443
  static code() {
442
- return 19;
444
+ return 17;
443
445
  }
444
446
  static w3cStatus() {
445
- return HTTPStatusCodes.BAD_REQUEST;
447
+ return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
446
448
  }
447
449
  static error() {
448
- return 'invalid selector';
450
+ return 'javascript error';
449
451
  }
450
452
 
453
+ }
454
+
455
+ export class XPathLookupError extends ProtocolError {
451
456
  constructor(message: string = '', cause?: Error) {
452
457
  super(
453
458
  message || 'An error occurred while searching for an element by XPath.',
@@ -457,19 +462,20 @@ export class XPathLookupError extends ProtocolError {
457
462
  cause,
458
463
  );
459
464
  }
460
- }
461
465
 
462
- export class TimeoutError extends ProtocolError {
463
466
  static code() {
464
- return 21;
467
+ return 19;
465
468
  }
466
469
  static w3cStatus() {
467
- return HTTPStatusCodes.REQUEST_TIMEOUT;
470
+ return HTTPStatusCodes.BAD_REQUEST;
468
471
  }
469
472
  static error() {
470
- return 'timeout';
473
+ return 'invalid selector';
471
474
  }
472
475
 
476
+ }
477
+
478
+ export class TimeoutError extends ProtocolError {
473
479
  constructor(message: string = '', cause?: Error) {
474
480
  super(
475
481
  message || 'An operation did not complete before its timeout expired.',
@@ -479,19 +485,20 @@ export class TimeoutError extends ProtocolError {
479
485
  cause,
480
486
  );
481
487
  }
482
- }
483
488
 
484
- export class NoSuchWindowError extends ProtocolError {
485
489
  static code() {
486
- return 23;
487
- }
488
- static error() {
489
- return 'no such window';
490
+ return 21;
490
491
  }
491
492
  static w3cStatus() {
492
- return HTTPStatusCodes.NOT_FOUND;
493
+ return HTTPStatusCodes.REQUEST_TIMEOUT;
494
+ }
495
+ static error() {
496
+ return 'timeout';
493
497
  }
494
498
 
499
+ }
500
+
501
+ export class NoSuchWindowError extends ProtocolError {
495
502
  constructor(message: string = '', cause?: Error) {
496
503
  super(
497
504
  message ||
@@ -503,19 +510,20 @@ export class NoSuchWindowError extends ProtocolError {
503
510
  cause,
504
511
  );
505
512
  }
506
- }
507
513
 
508
- export class InvalidArgumentError extends ProtocolError {
509
514
  static code() {
510
- return 61;
515
+ return 23;
511
516
  }
512
517
  static error() {
513
- return 'invalid argument';
518
+ return 'no such window';
514
519
  }
515
520
  static w3cStatus() {
516
- return HTTPStatusCodes.BAD_REQUEST;
521
+ return HTTPStatusCodes.NOT_FOUND;
517
522
  }
518
523
 
524
+ }
525
+
526
+ export class InvalidArgumentError extends ProtocolError {
519
527
  constructor(message: string = '', cause?: Error) {
520
528
  super(
521
529
  message || 'The arguments passed to the command are either invalid or malformed',
@@ -525,19 +533,20 @@ export class InvalidArgumentError extends ProtocolError {
525
533
  cause,
526
534
  );
527
535
  }
528
- }
529
536
 
530
- export class InvalidCookieDomainError extends ProtocolError {
531
537
  static code() {
532
- return 24;
538
+ return 61;
533
539
  }
534
540
  static error() {
535
- return 'invalid cookie domain';
541
+ return 'invalid argument';
536
542
  }
537
543
  static w3cStatus() {
538
544
  return HTTPStatusCodes.BAD_REQUEST;
539
545
  }
540
546
 
547
+ }
548
+
549
+ export class InvalidCookieDomainError extends ProtocolError {
541
550
  constructor(message: string = '', cause?: Error) {
542
551
  super(
543
552
  message ||
@@ -549,19 +558,20 @@ export class InvalidCookieDomainError extends ProtocolError {
549
558
  cause,
550
559
  );
551
560
  }
552
- }
553
561
 
554
- export class NoSuchCookieError extends ProtocolError {
555
562
  static code() {
556
- return 62;
557
- }
558
- static w3cStatus() {
559
- return HTTPStatusCodes.NOT_FOUND;
563
+ return 24;
560
564
  }
561
565
  static error() {
562
- return 'no such cookie';
566
+ return 'invalid cookie domain';
563
567
  }
568
+ static w3cStatus() {
569
+ return HTTPStatusCodes.BAD_REQUEST;
570
+ }
571
+
572
+ }
564
573
 
574
+ export class NoSuchCookieError extends ProtocolError {
565
575
  constructor(message: string = '', cause?: Error) {
566
576
  super(
567
577
  message ||
@@ -572,19 +582,20 @@ export class NoSuchCookieError extends ProtocolError {
572
582
  cause,
573
583
  );
574
584
  }
575
- }
576
585
 
577
- export class UnableToSetCookieError extends ProtocolError {
578
586
  static code() {
579
- return 25;
587
+ return 62;
580
588
  }
581
589
  static w3cStatus() {
582
- return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
590
+ return HTTPStatusCodes.NOT_FOUND;
583
591
  }
584
592
  static error() {
585
- return 'unable to set cookie';
593
+ return 'no such cookie';
586
594
  }
587
595
 
596
+ }
597
+
598
+ export class UnableToSetCookieError extends ProtocolError {
588
599
  constructor(message: string = '', cause?: Error) {
589
600
  super(
590
601
  message || "A request to set a cookie's value could not be satisfied.",
@@ -594,19 +605,21 @@ export class UnableToSetCookieError extends ProtocolError {
594
605
  cause,
595
606
  );
596
607
  }
597
- }
598
608
 
599
- export class UnexpectedAlertOpenError extends ProtocolError {
600
609
  static code() {
601
- return 26;
610
+ return 25;
602
611
  }
603
612
  static w3cStatus() {
604
613
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
605
614
  }
606
615
  static error() {
607
- return 'unexpected alert open';
616
+ return 'unable to set cookie';
608
617
  }
609
- constructor(message: string = '', cause?: Error) {
618
+
619
+ }
620
+
621
+ export class UnexpectedAlertOpenError extends ProtocolError {
622
+ constructor(message: string = '', cause?: Error) {
610
623
  super(
611
624
  message || 'A modal dialog was open, blocking this operation',
612
625
  UnexpectedAlertOpenError.code(),
@@ -615,19 +628,20 @@ export class UnexpectedAlertOpenError extends ProtocolError {
615
628
  cause,
616
629
  );
617
630
  }
618
- }
619
631
 
620
- export class NoAlertOpenError extends ProtocolError {
621
632
  static code() {
622
- return 27;
633
+ return 26;
623
634
  }
624
635
  static w3cStatus() {
625
- return HTTPStatusCodes.NOT_FOUND;
636
+ return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
626
637
  }
627
638
  static error() {
628
- return 'no such alert';
639
+ return 'unexpected alert open';
629
640
  }
630
641
 
642
+ }
643
+
644
+ export class NoAlertOpenError extends ProtocolError {
631
645
  constructor(message: string = '', cause?: Error) {
632
646
  super(
633
647
  message || 'An attempt was made to operate on a modal dialog when one was not open.',
@@ -637,21 +651,22 @@ export class NoAlertOpenError extends ProtocolError {
637
651
  cause,
638
652
  );
639
653
  }
640
- }
641
654
 
642
- export class NoSuchAlertError extends NoAlertOpenError {}
643
-
644
- export class ScriptTimeoutError extends ProtocolError {
645
655
  static code() {
646
- return 28;
656
+ return 27;
647
657
  }
648
658
  static w3cStatus() {
649
- return HTTPStatusCodes.REQUEST_TIMEOUT;
659
+ return HTTPStatusCodes.NOT_FOUND;
650
660
  }
651
661
  static error() {
652
- return 'script timeout';
662
+ return 'no such alert';
653
663
  }
654
664
 
665
+ }
666
+
667
+ export class NoSuchAlertError extends NoAlertOpenError {}
668
+
669
+ export class ScriptTimeoutError extends ProtocolError {
655
670
  constructor(message: string = '', cause?: Error) {
656
671
  super(
657
672
  message || 'A script did not complete before its timeout expired.',
@@ -661,19 +676,20 @@ export class ScriptTimeoutError extends ProtocolError {
661
676
  cause,
662
677
  );
663
678
  }
664
- }
665
679
 
666
- export class InvalidElementCoordinatesError extends ProtocolError {
667
680
  static code() {
668
- return 29;
681
+ return 28;
669
682
  }
670
683
  static w3cStatus() {
671
- return HTTPStatusCodes.BAD_REQUEST;
684
+ return HTTPStatusCodes.REQUEST_TIMEOUT;
672
685
  }
673
686
  static error() {
674
- return 'invalid coordinates';
687
+ return 'script timeout';
675
688
  }
676
689
 
690
+ }
691
+
692
+ export class InvalidElementCoordinatesError extends ProtocolError {
677
693
  constructor(message: string = '', cause?: Error) {
678
694
  super(
679
695
  message || 'The coordinates provided to an interactions operation are invalid.',
@@ -683,21 +699,22 @@ export class InvalidElementCoordinatesError extends ProtocolError {
683
699
  cause,
684
700
  );
685
701
  }
686
- }
687
702
 
688
- export class InvalidCoordinatesError extends InvalidElementCoordinatesError {}
689
-
690
- export class IMENotAvailableError extends ProtocolError {
691
703
  static code() {
692
- return 30;
704
+ return 29;
693
705
  }
694
706
  static w3cStatus() {
695
- return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
707
+ return HTTPStatusCodes.BAD_REQUEST;
696
708
  }
697
709
  static error() {
698
- return 'unsupported operation';
710
+ return 'invalid coordinates';
699
711
  }
700
712
 
713
+ }
714
+
715
+ export class InvalidCoordinatesError extends InvalidElementCoordinatesError {}
716
+
717
+ export class IMENotAvailableError extends ProtocolError {
701
718
  constructor(message: string = '', cause?: Error) {
702
719
  super(
703
720
  message || 'IME was not available.',
@@ -707,11 +724,9 @@ export class IMENotAvailableError extends ProtocolError {
707
724
  cause,
708
725
  );
709
726
  }
710
- }
711
727
 
712
- export class IMEEngineActivationFailedError extends ProtocolError {
713
728
  static code() {
714
- return 31;
729
+ return 30;
715
730
  }
716
731
  static w3cStatus() {
717
732
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
@@ -720,6 +735,9 @@ export class IMEEngineActivationFailedError extends ProtocolError {
720
735
  return 'unsupported operation';
721
736
  }
722
737
 
738
+ }
739
+
740
+ export class IMEEngineActivationFailedError extends ProtocolError {
723
741
  constructor(message: string = '', cause?: Error) {
724
742
  super(
725
743
  message || 'An IME engine could not be started.',
@@ -729,19 +747,20 @@ export class IMEEngineActivationFailedError extends ProtocolError {
729
747
  cause,
730
748
  );
731
749
  }
732
- }
733
750
 
734
- export class InvalidSelectorError extends ProtocolError {
735
751
  static code() {
736
- return 32;
752
+ return 31;
737
753
  }
738
754
  static w3cStatus() {
739
- return HTTPStatusCodes.BAD_REQUEST;
755
+ return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
740
756
  }
741
757
  static error() {
742
- return 'invalid selector';
758
+ return 'unsupported operation';
743
759
  }
744
760
 
761
+ }
762
+
763
+ export class InvalidSelectorError extends ProtocolError {
745
764
  constructor(message: string = '', cause?: Error) {
746
765
  super(
747
766
  message || 'Argument was an invalid selector (e.g. XPath/CSS).',
@@ -751,19 +770,20 @@ export class InvalidSelectorError extends ProtocolError {
751
770
  cause,
752
771
  );
753
772
  }
754
- }
755
773
 
756
- export class SessionNotCreatedError extends ProtocolError {
757
774
  static code() {
758
- return 33;
775
+ return 32;
759
776
  }
760
777
  static w3cStatus() {
761
- return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
778
+ return HTTPStatusCodes.BAD_REQUEST;
762
779
  }
763
780
  static error() {
764
- return 'session not created';
781
+ return 'invalid selector';
765
782
  }
766
783
 
784
+ }
785
+
786
+ export class SessionNotCreatedError extends ProtocolError {
767
787
  constructor(message: string = '', cause?: Error) {
768
788
  super(
769
789
  `A new session could not be created.${message ? (' Details: ' + message) : ''}`,
@@ -773,19 +793,20 @@ export class SessionNotCreatedError extends ProtocolError {
773
793
  cause,
774
794
  );
775
795
  }
776
- }
777
796
 
778
- export class MoveTargetOutOfBoundsError extends ProtocolError {
779
797
  static code() {
780
- return 34;
798
+ return 33;
781
799
  }
782
800
  static w3cStatus() {
783
801
  return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
784
802
  }
785
803
  static error() {
786
- return 'move target out of bounds';
804
+ return 'session not created';
787
805
  }
788
806
 
807
+ }
808
+
809
+ export class MoveTargetOutOfBoundsError extends ProtocolError {
789
810
  constructor(message: string = '', cause?: Error) {
790
811
  super(
791
812
  message || 'Target provided for a move action is out of bounds.',
@@ -795,13 +816,20 @@ export class MoveTargetOutOfBoundsError extends ProtocolError {
795
816
  cause,
796
817
  );
797
818
  }
798
- }
799
819
 
800
- export class NoSuchContextError extends ProtocolError {
801
820
  static code() {
802
- return 35;
821
+ return 34;
822
+ }
823
+ static w3cStatus() {
824
+ return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
803
825
  }
826
+ static error() {
827
+ return 'move target out of bounds';
828
+ }
829
+
830
+ }
804
831
 
832
+ export class NoSuchContextError extends ProtocolError {
805
833
  constructor(message: string = '', cause?: Error) {
806
834
  super(
807
835
  message || 'No such context found.',
@@ -811,13 +839,14 @@ export class NoSuchContextError extends ProtocolError {
811
839
  cause,
812
840
  );
813
841
  }
814
- }
815
842
 
816
- export class InvalidContextError extends ProtocolError {
817
843
  static code() {
818
- return 36;
844
+ return 35;
819
845
  }
820
846
 
847
+ }
848
+
849
+ export class InvalidContextError extends ProtocolError {
821
850
  constructor(message: string = '', cause?: Error) {
822
851
  super(
823
852
  message || 'That command could not be executed in the current context.',
@@ -827,6 +856,11 @@ export class InvalidContextError extends ProtocolError {
827
856
  cause,
828
857
  );
829
858
  }
859
+
860
+ static code() {
861
+ return 36;
862
+ }
863
+
830
864
  }
831
865
 
832
866
  // Aliases to UnknownMethodError
@@ -842,16 +876,6 @@ export class NotImplementedError extends UnknownMethodError {
842
876
  }
843
877
 
844
878
  export class UnableToCaptureScreen extends ProtocolError {
845
- static code() {
846
- return 63;
847
- }
848
- static w3cStatus() {
849
- return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
850
- }
851
- static error() {
852
- return 'unable to capture screen';
853
- }
854
-
855
879
  constructor(message: string = '', cause?: Error) {
856
880
  super(
857
881
  message || 'A screen capture was made impossible',
@@ -861,47 +885,17 @@ export class UnableToCaptureScreen extends ProtocolError {
861
885
  cause,
862
886
  );
863
887
  }
864
- }
865
888
 
866
- function generateBadParametersMessage(
867
- paramRequirements: ParameterRequirements,
868
- paramNames: string[]
869
- ): string {
870
- const toArray = function <T> (x: T | T[]): T[] {
871
- if (_.isUndefined(x)) {
872
- return [];
873
- }
874
- if (_.isArray(x)) {
875
- return x;
876
- }
877
- return [x];
878
- };
879
-
880
- const requiredParamNames = toArray(paramRequirements.required);
881
- const actualParamNames = toArray(paramNames);
882
- const missingRequiredParamNames = _.difference(requiredParamNames, actualParamNames);
883
- const resultLines: string[] = [];
884
- resultLines.push(
885
- _.isEmpty(missingRequiredParamNames)
886
- ? // This should not happen
887
- 'Some of the provided parameters are not known'
888
- : `The following required parameter${
889
- missingRequiredParamNames.length === 1 ? ' is' : 's are'
890
- } missing: ${JSON.stringify(missingRequiredParamNames)}`,
891
- );
892
- if (!_.isEmpty(requiredParamNames)) {
893
- resultLines.push(`Known required parameters are: ${JSON.stringify(requiredParamNames)}`);
889
+ static code() {
890
+ return 63;
894
891
  }
895
- const optionalParamNames = _.difference(toArray(paramRequirements.optional), ['sessionId', 'id']);
896
- if (!_.isEmpty(optionalParamNames)) {
897
- resultLines.push(`Known optional parameters are: ${JSON.stringify(optionalParamNames)}`);
892
+ static w3cStatus() {
893
+ return HTTPStatusCodes.INTERNAL_SERVER_ERROR;
898
894
  }
899
- resultLines.push(
900
- `You have provided${
901
- _.isEmpty(actualParamNames) ? ' none' : ': ' + JSON.stringify(paramNames)
902
- }`,
903
- );
904
- return resultLines.join('\n');
895
+ static error() {
896
+ return 'unable to capture screen';
897
+ }
898
+
905
899
  }
906
900
 
907
901
  // Equivalent to W3C InvalidArgumentError
@@ -945,6 +939,20 @@ export class ProxyRequestError extends BaseError {
945
939
  }
946
940
  }
947
941
 
942
+ private static _parseHttpResponse(data: any): [Record<string, any>, string] {
943
+ let responseErrorObj: Record<string, any> = util.safeJsonParse(data);
944
+ if (!_.isPlainObject(responseErrorObj)) {
945
+ responseErrorObj = {};
946
+ }
947
+ let errorMessage: string = _.isString(data) ? data : '';
948
+ if (_.isString(responseErrorObj.value)) {
949
+ errorMessage = responseErrorObj.value;
950
+ } else if (_.isString(responseErrorObj.value?.message)) {
951
+ errorMessage = responseErrorObj.value.message;
952
+ }
953
+ return [responseErrorObj, errorMessage];
954
+ }
955
+
948
956
  getActualError(): ProtocolError {
949
957
  if (util.hasValue(this._jwpError?.status) && util.hasValue(this._jwpError?.value)) {
950
958
  // If it's MJSONWP error, returns actual error cause for request failure based on `jsonwp.status`
@@ -959,20 +967,47 @@ export class ProxyRequestError extends BaseError {
959
967
  }
960
968
  return new UnknownError(this.message, this.cause);
961
969
  }
970
+ }
962
971
 
963
- private static _parseHttpResponse(data: any): [Record<string, any>, string] {
964
- let responseErrorObj: Record<string, any> = util.safeJsonParse(data);
965
- if (!_.isPlainObject(responseErrorObj)) {
966
- responseErrorObj = {};
972
+ function generateBadParametersMessage(
973
+ paramRequirements: ParameterRequirements,
974
+ paramNames: string[]
975
+ ): string {
976
+ const toArray = function <T> (x: T | T[]): T[] {
977
+ if (_.isUndefined(x)) {
978
+ return [];
967
979
  }
968
- let errorMessage: string = _.isString(data) ? data : '';
969
- if (_.isString(responseErrorObj.value)) {
970
- errorMessage = responseErrorObj.value;
971
- } else if (_.isString(responseErrorObj.value?.message)) {
972
- errorMessage = responseErrorObj.value.message;
980
+ if (_.isArray(x)) {
981
+ return x;
973
982
  }
974
- return [responseErrorObj, errorMessage];
983
+ return [x];
984
+ };
985
+
986
+ const requiredParamNames = toArray(paramRequirements.required);
987
+ const actualParamNames = toArray(paramNames);
988
+ const missingRequiredParamNames = _.difference(requiredParamNames, actualParamNames);
989
+ const resultLines: string[] = [];
990
+ resultLines.push(
991
+ _.isEmpty(missingRequiredParamNames)
992
+ ? // This should not happen
993
+ 'Some of the provided parameters are not known'
994
+ : `The following required parameter${
995
+ missingRequiredParamNames.length === 1 ? ' is' : 's are'
996
+ } missing: ${JSON.stringify(missingRequiredParamNames)}`,
997
+ );
998
+ if (!_.isEmpty(requiredParamNames)) {
999
+ resultLines.push(`Known required parameters are: ${JSON.stringify(requiredParamNames)}`);
975
1000
  }
1001
+ const optionalParamNames = _.difference(toArray(paramRequirements.optional), ['sessionId', 'id']);
1002
+ if (!_.isEmpty(optionalParamNames)) {
1003
+ resultLines.push(`Known optional parameters are: ${JSON.stringify(optionalParamNames)}`);
1004
+ }
1005
+ resultLines.push(
1006
+ `You have provided${
1007
+ _.isEmpty(actualParamNames) ? ' none' : ': ' + JSON.stringify(paramNames)
1008
+ }`,
1009
+ );
1010
+ return resultLines.join('\n');
976
1011
  }
977
1012
 
978
1013
  // map of error class name to error class
@@ -1035,6 +1070,23 @@ const w3cErrorCodeMap: Record<string, Class<ProtocolError>> = _.values(errors)
1035
1070
  }, {});
1036
1071
 
1037
1072
 
1073
+ interface MJSONWPError {
1074
+ status: number;
1075
+ value?: any;
1076
+ message?: string;
1077
+ }
1078
+
1079
+ interface W3CError {
1080
+ error: string;
1081
+ message?: string;
1082
+ stacktrace?: string;
1083
+ }
1084
+
1085
+ interface ParameterRequirements {
1086
+ required: string[] | string;
1087
+ optional?: string[] | string;
1088
+ }
1089
+
1038
1090
  /**
1039
1091
  * Type guard to check if an Error is of a specific type
1040
1092
  */
@@ -1102,20 +1154,3 @@ export function getResponseForW3CError(err: any): [number, { value: W3CError }]
1102
1154
 
1103
1155
  return protocolErrorToResponse(new UnknownError(err.message, err));
1104
1156
  }
1105
-
1106
- interface MJSONWPError {
1107
- status: number;
1108
- value?: any;
1109
- message?: string;
1110
- }
1111
-
1112
- interface W3CError {
1113
- error: string;
1114
- message?: string;
1115
- stacktrace?: string;
1116
- }
1117
-
1118
- interface ParameterRequirements {
1119
- required: string[] | string;
1120
- optional?: string[] | string;
1121
- }