@appium/base-driver 10.5.2 → 10.7.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.
- package/build/lib/basedriver/capabilities.d.ts +1 -1
- package/build/lib/basedriver/capabilities.d.ts.map +1 -1
- package/build/lib/basedriver/capabilities.js +58 -50
- package/build/lib/basedriver/capabilities.js.map +1 -1
- package/build/lib/basedriver/commands/bidi.d.ts.map +1 -1
- package/build/lib/basedriver/commands/bidi.js +10 -14
- package/build/lib/basedriver/commands/bidi.js.map +1 -1
- package/build/lib/basedriver/commands/event.d.ts.map +1 -1
- package/build/lib/basedriver/commands/event.js +4 -7
- package/build/lib/basedriver/commands/event.js.map +1 -1
- package/build/lib/basedriver/commands/execute.js +3 -6
- package/build/lib/basedriver/commands/execute.js.map +1 -1
- package/build/lib/basedriver/commands/find.d.ts.map +1 -1
- package/build/lib/basedriver/commands/find.js +2 -1
- package/build/lib/basedriver/commands/find.js.map +1 -1
- package/build/lib/basedriver/commands/log.d.ts.map +1 -1
- package/build/lib/basedriver/commands/log.js +1 -5
- package/build/lib/basedriver/commands/log.js.map +1 -1
- package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
- package/build/lib/basedriver/commands/timeout.js +9 -13
- package/build/lib/basedriver/commands/timeout.js.map +1 -1
- package/build/lib/basedriver/core.d.ts.map +1 -1
- package/build/lib/basedriver/core.js +17 -14
- package/build/lib/basedriver/core.js.map +1 -1
- package/build/lib/basedriver/device-settings.d.ts.map +1 -1
- package/build/lib/basedriver/device-settings.js +3 -7
- package/build/lib/basedriver/device-settings.js.map +1 -1
- package/build/lib/basedriver/driver.d.ts.map +1 -1
- package/build/lib/basedriver/driver.js +34 -38
- package/build/lib/basedriver/driver.js.map +1 -1
- package/build/lib/basedriver/extension-core.d.ts +4 -1
- package/build/lib/basedriver/extension-core.d.ts.map +1 -1
- package/build/lib/basedriver/extension-core.js +37 -13
- package/build/lib/basedriver/extension-core.js.map +1 -1
- package/build/lib/basedriver/helpers.d.ts.map +1 -1
- package/build/lib/basedriver/helpers.js +47 -33
- package/build/lib/basedriver/helpers.js.map +1 -1
- package/build/lib/basedriver/ipc.d.ts +36 -0
- package/build/lib/basedriver/ipc.d.ts.map +1 -0
- package/build/lib/basedriver/ipc.js +157 -0
- package/build/lib/basedriver/ipc.js.map +1 -0
- package/build/lib/basedriver/validation.d.ts.map +1 -1
- package/build/lib/basedriver/validation.js +27 -29
- package/build/lib/basedriver/validation.js.map +1 -1
- package/build/lib/express/express-logging.d.ts +0 -1
- package/build/lib/express/express-logging.d.ts.map +1 -1
- package/build/lib/express/express-logging.js +11 -11
- package/build/lib/express/express-logging.js.map +1 -1
- package/build/lib/express/idempotency.js +3 -6
- package/build/lib/express/idempotency.js.map +1 -1
- package/build/lib/express/middleware.d.ts.map +1 -1
- package/build/lib/express/middleware.js +6 -10
- package/build/lib/express/middleware.js.map +1 -1
- package/build/lib/express/server.d.ts +1 -1
- package/build/lib/express/server.d.ts.map +1 -1
- package/build/lib/express/server.js +82 -73
- package/build/lib/express/server.js.map +1 -1
- package/build/lib/express/websocket.d.ts.map +1 -1
- package/build/lib/express/websocket.js +6 -9
- package/build/lib/express/websocket.js.map +1 -1
- package/build/lib/helpers/capabilities.d.ts.map +1 -1
- package/build/lib/helpers/capabilities.js +14 -17
- package/build/lib/helpers/capabilities.js.map +1 -1
- package/build/lib/helpers/extension-command-name.js +2 -5
- package/build/lib/helpers/extension-command-name.js.map +1 -1
- package/build/lib/helpers/levenshtein-match.d.ts.map +1 -1
- package/build/lib/helpers/levenshtein-match.js +6 -7
- package/build/lib/helpers/levenshtein-match.js.map +1 -1
- package/build/lib/index.d.ts +2 -1
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +6 -16
- package/build/lib/index.js.map +1 -1
- package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/protocol-converter.js +21 -18
- package/build/lib/jsonwp-proxy/protocol-converter.js.map +1 -1
- package/build/lib/jsonwp-proxy/proxy-request.d.ts +2 -2
- package/build/lib/jsonwp-proxy/proxy-request.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy-request.js +25 -21
- package/build/lib/jsonwp-proxy/proxy-request.js.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.js +45 -36
- package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
- package/build/lib/protocol/errors.d.ts.map +1 -1
- package/build/lib/protocol/errors.js +33 -37
- package/build/lib/protocol/errors.js.map +1 -1
- package/build/lib/protocol/helpers.d.ts.map +1 -1
- package/build/lib/protocol/helpers.js +9 -8
- package/build/lib/protocol/helpers.js.map +1 -1
- package/build/lib/protocol/protocol.d.ts +1 -1
- package/build/lib/protocol/protocol.d.ts.map +1 -1
- package/build/lib/protocol/protocol.js +73 -61
- package/build/lib/protocol/protocol.js.map +1 -1
- package/build/lib/protocol/routes.d.ts +1 -1
- package/build/lib/protocol/routes.d.ts.map +1 -1
- package/build/lib/protocol/routes.js +16 -17
- package/build/lib/protocol/routes.js.map +1 -1
- package/build/lib/protocol/validators.d.ts.map +1 -1
- package/build/lib/protocol/validators.js +1 -5
- package/build/lib/protocol/validators.js.map +1 -1
- package/build/lib/test-pages/crash.d.ts.map +1 -0
- package/build/lib/test-pages/crash.js.map +1 -0
- package/build/lib/test-pages/env.d.ts +5 -0
- package/build/lib/test-pages/env.d.ts.map +1 -0
- package/build/lib/test-pages/env.js +12 -0
- package/build/lib/test-pages/env.js.map +1 -0
- package/build/lib/{express/static.d.ts → test-pages/handlers.d.ts} +1 -2
- package/build/lib/test-pages/handlers.d.ts.map +1 -0
- package/build/lib/{express/static.js → test-pages/handlers.js} +9 -12
- package/build/lib/test-pages/handlers.js.map +1 -0
- package/build/lib/test-pages/index.d.ts +6 -0
- package/build/lib/test-pages/index.d.ts.map +1 -0
- package/build/lib/test-pages/index.js +35 -0
- package/build/lib/test-pages/index.js.map +1 -0
- package/build/lib/test-pages/static-dir.d.ts +8 -0
- package/build/lib/test-pages/static-dir.d.ts.map +1 -0
- package/build/lib/test-pages/static-dir.js +24 -0
- package/build/lib/test-pages/static-dir.js.map +1 -0
- package/build/lib/test-pages/template.d.ts +3 -0
- package/build/lib/test-pages/template.d.ts.map +1 -0
- package/build/lib/test-pages/template.js +19 -0
- package/build/lib/test-pages/template.js.map +1 -0
- package/build/lib/utils.d.ts +14 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +55 -0
- package/build/lib/utils.js.map +1 -0
- package/lib/basedriver/capabilities.ts +126 -115
- package/lib/basedriver/commands/bidi.ts +11 -11
- package/lib/basedriver/commands/event.ts +17 -11
- package/lib/basedriver/commands/execute.ts +15 -12
- package/lib/basedriver/commands/find.ts +20 -12
- package/lib/basedriver/commands/log.ts +4 -3
- package/lib/basedriver/commands/timeout.ts +22 -14
- package/lib/basedriver/core.ts +26 -26
- package/lib/basedriver/device-settings.ts +7 -12
- package/lib/basedriver/driver.ts +62 -50
- package/lib/basedriver/extension-core.ts +60 -18
- package/lib/basedriver/helpers.ts +81 -52
- package/lib/basedriver/ipc.ts +198 -0
- package/lib/basedriver/validation.ts +37 -30
- package/lib/express/express-logging.ts +16 -20
- package/lib/express/idempotency.ts +9 -9
- package/lib/express/middleware.ts +14 -18
- package/lib/express/server.ts +118 -120
- package/lib/express/websocket.ts +11 -15
- package/lib/helpers/capabilities.ts +21 -16
- package/lib/helpers/extension-command-name.ts +3 -3
- package/lib/helpers/levenshtein-match.ts +20 -14
- package/lib/index.js +3 -12
- package/lib/jsonwp-proxy/protocol-converter.ts +58 -35
- package/lib/jsonwp-proxy/proxy-request.ts +26 -26
- package/lib/jsonwp-proxy/proxy.ts +74 -75
- package/lib/protocol/errors.ts +69 -88
- package/lib/protocol/helpers.ts +9 -5
- package/lib/protocol/protocol.ts +149 -107
- package/lib/protocol/routes.ts +17 -17
- package/lib/protocol/validators.ts +1 -3
- package/lib/test-pages/env.ts +9 -0
- package/lib/{express/static.ts → test-pages/handlers.ts} +10 -22
- package/lib/test-pages/index.ts +34 -0
- package/lib/test-pages/static-dir.ts +19 -0
- package/lib/test-pages/template.ts +17 -0
- package/lib/utils.ts +65 -0
- package/package.json +10 -13
- package/tsconfig.json +1 -0
- package/build/lib/express/crash.d.ts.map +0 -1
- package/build/lib/express/crash.js.map +0 -1
- package/build/lib/express/static.d.ts.map +0 -1
- package/build/lib/express/static.js.map +0 -1
- /package/build/lib/{express → test-pages}/crash.d.ts +0 -0
- /package/build/lib/{express → test-pages}/crash.js +0 -0
- /package/lib/{express → test-pages}/crash.ts +0 -0
- /package/{static → test-fixtures/static}/appium.png +0 -0
- /package/{static → test-fixtures/static}/favicon.ico +0 -0
- /package/{static → test-fixtures/static}/js/jquery.min.js +0 -0
- /package/{static → test-fixtures/static}/test/frameset.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig-app-banner.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig-scrollable.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig2.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig3.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig4.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig5.html +0 -0
- /package/{static → test-fixtures/static}/test/iframes.html +0 -0
- /package/{static → test-fixtures/static}/test/shadow-dom.html +0 -0
- /package/{static → test-fixtures/static}/test/subframe1.html +0 -0
- /package/{static → test-fixtures/static}/test/subframe2.html +0 -0
- /package/{static → test-fixtures/static}/test/subframe3.html +0 -0
- /package/{static → test-fixtures/static}/test/touch.html +0 -0
- /package/{static → test-fixtures/static}/test/welcome.html +0 -0
package/lib/protocol/errors.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
1
|
import {util, logger} from '@appium/support';
|
|
3
2
|
import {StatusCodes as HTTPStatusCodes} from 'http-status-codes';
|
|
4
3
|
import type {ErrorBiDiCommandResponse, Class} from '@appium/types';
|
|
@@ -22,13 +21,13 @@ class BaseError extends Error {
|
|
|
22
21
|
|
|
23
22
|
private _formatStack(): void {
|
|
24
23
|
// eslint-disable-next-line no-prototype-builtins
|
|
25
|
-
if (Error.hasOwnProperty('captureStackTrace') &&
|
|
24
|
+
if (Error.hasOwnProperty('captureStackTrace') && util.isEmpty(this.stack)) {
|
|
26
25
|
Error.captureStackTrace(this, this.constructor);
|
|
27
26
|
}
|
|
28
|
-
if (
|
|
27
|
+
if (typeof this.cause?.stack !== 'string') {
|
|
29
28
|
return;
|
|
30
29
|
}
|
|
31
|
-
if (
|
|
30
|
+
if (util.isEmpty(this.stack)) {
|
|
32
31
|
this.stack = this.cause.stack;
|
|
33
32
|
return;
|
|
34
33
|
}
|
|
@@ -77,7 +76,7 @@ export class ProtocolError extends BaseError {
|
|
|
77
76
|
bidiErrObject(id: string | number): ErrorBiDiCommandResponse {
|
|
78
77
|
// if we don't have an id, the client didn't send one, so we have nothing to send back.
|
|
79
78
|
// send back zero rather than making something up
|
|
80
|
-
const intId = (
|
|
79
|
+
const intId = (Number.isInteger(id) ? id : parseInt(`${id}`, 10) || 0) as number;
|
|
81
80
|
return {
|
|
82
81
|
id: intId,
|
|
83
82
|
type: 'error',
|
|
@@ -113,7 +112,6 @@ export class NoSuchDriverError extends ProtocolError {
|
|
|
113
112
|
static error() {
|
|
114
113
|
return 'invalid session id';
|
|
115
114
|
}
|
|
116
|
-
|
|
117
115
|
}
|
|
118
116
|
|
|
119
117
|
export class NoSuchElementError extends ProtocolError {
|
|
@@ -137,7 +135,6 @@ export class NoSuchElementError extends ProtocolError {
|
|
|
137
135
|
static error() {
|
|
138
136
|
return 'no such element';
|
|
139
137
|
}
|
|
140
|
-
|
|
141
138
|
}
|
|
142
139
|
|
|
143
140
|
/**
|
|
@@ -149,8 +146,7 @@ export class NoSuchElementError extends ProtocolError {
|
|
|
149
146
|
export class NoSuchShadowRootError extends ProtocolError {
|
|
150
147
|
constructor(message: string = '', cause?: Error) {
|
|
151
148
|
super(
|
|
152
|
-
message ||
|
|
153
|
-
'The element does not have a shadow root attached.',
|
|
149
|
+
message || 'The element does not have a shadow root attached.',
|
|
154
150
|
NoSuchShadowRootError.code(),
|
|
155
151
|
NoSuchShadowRootError.w3cStatus(),
|
|
156
152
|
NoSuchShadowRootError.error(),
|
|
@@ -170,7 +166,6 @@ export class NoSuchShadowRootError extends ProtocolError {
|
|
|
170
166
|
static w3cStatus() {
|
|
171
167
|
return HTTPStatusCodes.NOT_FOUND;
|
|
172
168
|
}
|
|
173
|
-
|
|
174
169
|
}
|
|
175
170
|
|
|
176
171
|
export class NoSuchFrameError extends ProtocolError {
|
|
@@ -195,7 +190,6 @@ export class NoSuchFrameError extends ProtocolError {
|
|
|
195
190
|
static w3cStatus() {
|
|
196
191
|
return HTTPStatusCodes.NOT_FOUND;
|
|
197
192
|
}
|
|
198
|
-
|
|
199
193
|
}
|
|
200
194
|
|
|
201
195
|
export class UnknownCommandError extends ProtocolError {
|
|
@@ -221,7 +215,6 @@ export class UnknownCommandError extends ProtocolError {
|
|
|
221
215
|
static error() {
|
|
222
216
|
return 'unknown command';
|
|
223
217
|
}
|
|
224
|
-
|
|
225
218
|
}
|
|
226
219
|
|
|
227
220
|
export class StaleElementReferenceError extends ProtocolError {
|
|
@@ -246,7 +239,6 @@ export class StaleElementReferenceError extends ProtocolError {
|
|
|
246
239
|
static error() {
|
|
247
240
|
return 'stale element reference';
|
|
248
241
|
}
|
|
249
|
-
|
|
250
242
|
}
|
|
251
243
|
|
|
252
244
|
export class ElementNotVisibleError extends ProtocolError {
|
|
@@ -271,7 +263,6 @@ export class ElementNotVisibleError extends ProtocolError {
|
|
|
271
263
|
static error() {
|
|
272
264
|
return 'element not visible';
|
|
273
265
|
}
|
|
274
|
-
|
|
275
266
|
}
|
|
276
267
|
|
|
277
268
|
export class InvalidElementStateError extends ProtocolError {
|
|
@@ -296,7 +287,6 @@ export class InvalidElementStateError extends ProtocolError {
|
|
|
296
287
|
static error() {
|
|
297
288
|
return 'invalid element state';
|
|
298
289
|
}
|
|
299
|
-
|
|
300
290
|
}
|
|
301
291
|
|
|
302
292
|
export class UnknownError extends ProtocolError {
|
|
@@ -319,7 +309,6 @@ export class UnknownError extends ProtocolError {
|
|
|
319
309
|
static error() {
|
|
320
310
|
return 'unknown error';
|
|
321
311
|
}
|
|
322
|
-
|
|
323
312
|
}
|
|
324
313
|
|
|
325
314
|
export class UnknownMethodError extends ProtocolError {
|
|
@@ -343,7 +332,6 @@ export class UnknownMethodError extends ProtocolError {
|
|
|
343
332
|
static error() {
|
|
344
333
|
return 'unknown method';
|
|
345
334
|
}
|
|
346
|
-
|
|
347
335
|
}
|
|
348
336
|
|
|
349
337
|
export class UnsupportedOperationError extends ProtocolError {
|
|
@@ -366,7 +354,6 @@ export class UnsupportedOperationError extends ProtocolError {
|
|
|
366
354
|
static error() {
|
|
367
355
|
return 'unsupported operation';
|
|
368
356
|
}
|
|
369
|
-
|
|
370
357
|
}
|
|
371
358
|
|
|
372
359
|
export class ElementIsNotSelectableError extends ProtocolError {
|
|
@@ -389,7 +376,6 @@ export class ElementIsNotSelectableError extends ProtocolError {
|
|
|
389
376
|
static w3cStatus() {
|
|
390
377
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
391
378
|
}
|
|
392
|
-
|
|
393
379
|
}
|
|
394
380
|
|
|
395
381
|
export class ElementClickInterceptedError extends ProtocolError {
|
|
@@ -414,7 +400,6 @@ export class ElementClickInterceptedError extends ProtocolError {
|
|
|
414
400
|
static w3cStatus() {
|
|
415
401
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
416
402
|
}
|
|
417
|
-
|
|
418
403
|
}
|
|
419
404
|
|
|
420
405
|
export class ElementNotInteractableError extends ProtocolError {
|
|
@@ -438,7 +423,6 @@ export class ElementNotInteractableError extends ProtocolError {
|
|
|
438
423
|
static w3cStatus() {
|
|
439
424
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
440
425
|
}
|
|
441
|
-
|
|
442
426
|
}
|
|
443
427
|
|
|
444
428
|
export class InsecureCertificateError extends ProtocolError {
|
|
@@ -459,7 +443,6 @@ export class InsecureCertificateError extends ProtocolError {
|
|
|
459
443
|
static w3cStatus() {
|
|
460
444
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
461
445
|
}
|
|
462
|
-
|
|
463
446
|
}
|
|
464
447
|
|
|
465
448
|
export class JavaScriptError extends ProtocolError {
|
|
@@ -482,7 +465,6 @@ export class JavaScriptError extends ProtocolError {
|
|
|
482
465
|
static error() {
|
|
483
466
|
return 'javascript error';
|
|
484
467
|
}
|
|
485
|
-
|
|
486
468
|
}
|
|
487
469
|
|
|
488
470
|
export class XPathLookupError extends ProtocolError {
|
|
@@ -505,7 +487,6 @@ export class XPathLookupError extends ProtocolError {
|
|
|
505
487
|
static error() {
|
|
506
488
|
return 'invalid selector';
|
|
507
489
|
}
|
|
508
|
-
|
|
509
490
|
}
|
|
510
491
|
|
|
511
492
|
export class TimeoutError extends ProtocolError {
|
|
@@ -528,7 +509,6 @@ export class TimeoutError extends ProtocolError {
|
|
|
528
509
|
static error() {
|
|
529
510
|
return 'timeout';
|
|
530
511
|
}
|
|
531
|
-
|
|
532
512
|
}
|
|
533
513
|
|
|
534
514
|
export class NoSuchWindowError extends ProtocolError {
|
|
@@ -553,7 +533,6 @@ export class NoSuchWindowError extends ProtocolError {
|
|
|
553
533
|
static w3cStatus() {
|
|
554
534
|
return HTTPStatusCodes.NOT_FOUND;
|
|
555
535
|
}
|
|
556
|
-
|
|
557
536
|
}
|
|
558
537
|
|
|
559
538
|
export class InvalidArgumentError extends ProtocolError {
|
|
@@ -576,7 +555,6 @@ export class InvalidArgumentError extends ProtocolError {
|
|
|
576
555
|
static w3cStatus() {
|
|
577
556
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
578
557
|
}
|
|
579
|
-
|
|
580
558
|
}
|
|
581
559
|
|
|
582
560
|
export class InvalidCookieDomainError extends ProtocolError {
|
|
@@ -601,7 +579,6 @@ export class InvalidCookieDomainError extends ProtocolError {
|
|
|
601
579
|
static w3cStatus() {
|
|
602
580
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
603
581
|
}
|
|
604
|
-
|
|
605
582
|
}
|
|
606
583
|
|
|
607
584
|
export class NoSuchCookieError extends ProtocolError {
|
|
@@ -625,7 +602,6 @@ export class NoSuchCookieError extends ProtocolError {
|
|
|
625
602
|
static error() {
|
|
626
603
|
return 'no such cookie';
|
|
627
604
|
}
|
|
628
|
-
|
|
629
605
|
}
|
|
630
606
|
|
|
631
607
|
export class UnableToSetCookieError extends ProtocolError {
|
|
@@ -648,7 +624,6 @@ export class UnableToSetCookieError extends ProtocolError {
|
|
|
648
624
|
static error() {
|
|
649
625
|
return 'unable to set cookie';
|
|
650
626
|
}
|
|
651
|
-
|
|
652
627
|
}
|
|
653
628
|
|
|
654
629
|
export class UnexpectedAlertOpenError extends ProtocolError {
|
|
@@ -671,7 +646,6 @@ export class UnexpectedAlertOpenError extends ProtocolError {
|
|
|
671
646
|
static error() {
|
|
672
647
|
return 'unexpected alert open';
|
|
673
648
|
}
|
|
674
|
-
|
|
675
649
|
}
|
|
676
650
|
|
|
677
651
|
export class NoAlertOpenError extends ProtocolError {
|
|
@@ -694,7 +668,6 @@ export class NoAlertOpenError extends ProtocolError {
|
|
|
694
668
|
static error() {
|
|
695
669
|
return 'no such alert';
|
|
696
670
|
}
|
|
697
|
-
|
|
698
671
|
}
|
|
699
672
|
|
|
700
673
|
export class NoSuchAlertError extends NoAlertOpenError {}
|
|
@@ -719,7 +692,6 @@ export class ScriptTimeoutError extends ProtocolError {
|
|
|
719
692
|
static error() {
|
|
720
693
|
return 'script timeout';
|
|
721
694
|
}
|
|
722
|
-
|
|
723
695
|
}
|
|
724
696
|
|
|
725
697
|
export class InvalidElementCoordinatesError extends ProtocolError {
|
|
@@ -742,7 +714,6 @@ export class InvalidElementCoordinatesError extends ProtocolError {
|
|
|
742
714
|
static error() {
|
|
743
715
|
return 'invalid coordinates';
|
|
744
716
|
}
|
|
745
|
-
|
|
746
717
|
}
|
|
747
718
|
|
|
748
719
|
export class InvalidCoordinatesError extends InvalidElementCoordinatesError {}
|
|
@@ -767,7 +738,6 @@ export class IMENotAvailableError extends ProtocolError {
|
|
|
767
738
|
static error() {
|
|
768
739
|
return 'unsupported operation';
|
|
769
740
|
}
|
|
770
|
-
|
|
771
741
|
}
|
|
772
742
|
|
|
773
743
|
export class IMEEngineActivationFailedError extends ProtocolError {
|
|
@@ -790,7 +760,6 @@ export class IMEEngineActivationFailedError extends ProtocolError {
|
|
|
790
760
|
static error() {
|
|
791
761
|
return 'unsupported operation';
|
|
792
762
|
}
|
|
793
|
-
|
|
794
763
|
}
|
|
795
764
|
|
|
796
765
|
export class InvalidSelectorError extends ProtocolError {
|
|
@@ -813,13 +782,12 @@ export class InvalidSelectorError extends ProtocolError {
|
|
|
813
782
|
static error() {
|
|
814
783
|
return 'invalid selector';
|
|
815
784
|
}
|
|
816
|
-
|
|
817
785
|
}
|
|
818
786
|
|
|
819
787
|
export class SessionNotCreatedError extends ProtocolError {
|
|
820
788
|
constructor(message: string = '', cause?: Error) {
|
|
821
789
|
super(
|
|
822
|
-
`A new session could not be created.${message ?
|
|
790
|
+
`A new session could not be created.${message ? ' Details: ' + message : ''}`,
|
|
823
791
|
SessionNotCreatedError.code(),
|
|
824
792
|
SessionNotCreatedError.w3cStatus(),
|
|
825
793
|
SessionNotCreatedError.error(),
|
|
@@ -836,7 +804,6 @@ export class SessionNotCreatedError extends ProtocolError {
|
|
|
836
804
|
static error() {
|
|
837
805
|
return 'session not created';
|
|
838
806
|
}
|
|
839
|
-
|
|
840
807
|
}
|
|
841
808
|
|
|
842
809
|
export class MoveTargetOutOfBoundsError extends ProtocolError {
|
|
@@ -859,7 +826,6 @@ export class MoveTargetOutOfBoundsError extends ProtocolError {
|
|
|
859
826
|
static error() {
|
|
860
827
|
return 'move target out of bounds';
|
|
861
828
|
}
|
|
862
|
-
|
|
863
829
|
}
|
|
864
830
|
|
|
865
831
|
export class NoSuchContextError extends ProtocolError {
|
|
@@ -876,7 +842,6 @@ export class NoSuchContextError extends ProtocolError {
|
|
|
876
842
|
static code() {
|
|
877
843
|
return 35;
|
|
878
844
|
}
|
|
879
|
-
|
|
880
845
|
}
|
|
881
846
|
|
|
882
847
|
export class InvalidContextError extends ProtocolError {
|
|
@@ -893,7 +858,6 @@ export class InvalidContextError extends ProtocolError {
|
|
|
893
858
|
static code() {
|
|
894
859
|
return 36;
|
|
895
860
|
}
|
|
896
|
-
|
|
897
861
|
}
|
|
898
862
|
|
|
899
863
|
// Aliases to UnknownMethodError
|
|
@@ -928,7 +892,6 @@ export class UnableToCaptureScreen extends ProtocolError {
|
|
|
928
892
|
static error() {
|
|
929
893
|
return 'unable to capture screen';
|
|
930
894
|
}
|
|
931
|
-
|
|
932
895
|
}
|
|
933
896
|
|
|
934
897
|
// Equivalent to W3C InvalidArgumentError
|
|
@@ -949,38 +912,37 @@ export class ProxyRequestError extends BaseError {
|
|
|
949
912
|
private readonly _w3cErrorStatus?: number;
|
|
950
913
|
private readonly _jwpError?: MJSONWPError;
|
|
951
914
|
|
|
952
|
-
constructor(
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
httpStatus?: number,
|
|
956
|
-
cause?: Error,
|
|
957
|
-
) {
|
|
958
|
-
const [responseErrorObj, originalMessage] = ProxyRequestError._parseHttpResponse(httpResponseData);
|
|
915
|
+
constructor(message: string, httpResponseData: any, httpStatus?: number, cause?: Error) {
|
|
916
|
+
const [responseErrorObj, originalMessage] =
|
|
917
|
+
ProxyRequestError._parseHttpResponse(httpResponseData);
|
|
959
918
|
super(
|
|
960
|
-
|
|
961
|
-
? `Proxy request unsuccessful.${originalMessage ?
|
|
919
|
+
util.isEmpty(message)
|
|
920
|
+
? `Proxy request unsuccessful.${originalMessage ? ' ' + originalMessage : ''}`
|
|
962
921
|
: message,
|
|
963
922
|
cause,
|
|
964
923
|
);
|
|
965
924
|
|
|
966
925
|
// If the response error is an object and value is an object, it's a W3C error (for JSONWP value is a string)
|
|
967
|
-
if (
|
|
968
|
-
|
|
926
|
+
if (
|
|
927
|
+
util.isPlainObject(responseErrorObj.value) &&
|
|
928
|
+
Object.hasOwn(responseErrorObj.value, 'error')
|
|
929
|
+
) {
|
|
930
|
+
this._w3cError = responseErrorObj.value as unknown as typeof this._w3cError;
|
|
969
931
|
this._w3cErrorStatus = httpStatus;
|
|
970
|
-
} else if (
|
|
971
|
-
this._jwpError = responseErrorObj;
|
|
932
|
+
} else if (Object.hasOwn(responseErrorObj, 'status')) {
|
|
933
|
+
this._jwpError = responseErrorObj as typeof this._jwpError;
|
|
972
934
|
}
|
|
973
935
|
}
|
|
974
936
|
|
|
975
937
|
private static _parseHttpResponse(data: any): [Record<string, any>, string] {
|
|
976
938
|
let responseErrorObj: Record<string, any> = util.safeJsonParse(data);
|
|
977
|
-
if (!
|
|
939
|
+
if (!util.isPlainObject(responseErrorObj)) {
|
|
978
940
|
responseErrorObj = {};
|
|
979
941
|
}
|
|
980
|
-
let errorMessage: string =
|
|
981
|
-
if (
|
|
942
|
+
let errorMessage: string = typeof data === 'string' ? data : '';
|
|
943
|
+
if (typeof responseErrorObj.value === 'string') {
|
|
982
944
|
errorMessage = responseErrorObj.value;
|
|
983
|
-
} else if (
|
|
945
|
+
} else if (typeof responseErrorObj.value?.message === 'string') {
|
|
984
946
|
errorMessage = responseErrorObj.value.message;
|
|
985
947
|
}
|
|
986
948
|
return [responseErrorObj, errorMessage];
|
|
@@ -991,7 +953,11 @@ export class ProxyRequestError extends BaseError {
|
|
|
991
953
|
// If it's MJSONWP error, returns actual error cause for request failure based on `jsonwp.status`
|
|
992
954
|
return errorFromMJSONWPStatusCode(this._jwpError.status, this._jwpError.value);
|
|
993
955
|
}
|
|
994
|
-
if (
|
|
956
|
+
if (
|
|
957
|
+
util.hasValue(this._w3cError) &&
|
|
958
|
+
typeof this._w3cErrorStatus === 'number' &&
|
|
959
|
+
this._w3cErrorStatus >= 300
|
|
960
|
+
) {
|
|
995
961
|
return errorFromW3CJsonCode(
|
|
996
962
|
this._w3cError.error,
|
|
997
963
|
this._w3cError.message || this.message,
|
|
@@ -1004,13 +970,13 @@ export class ProxyRequestError extends BaseError {
|
|
|
1004
970
|
|
|
1005
971
|
function generateBadParametersMessage(
|
|
1006
972
|
paramRequirements: ParameterRequirements,
|
|
1007
|
-
paramNames: string[]
|
|
973
|
+
paramNames: string[],
|
|
1008
974
|
): string {
|
|
1009
|
-
const toArray = function <T>
|
|
1010
|
-
if (
|
|
975
|
+
const toArray = function <T>(x: T | T[]): T[] {
|
|
976
|
+
if (x === undefined) {
|
|
1011
977
|
return [];
|
|
1012
978
|
}
|
|
1013
|
-
if (
|
|
979
|
+
if (Array.isArray(x)) {
|
|
1014
980
|
return x;
|
|
1015
981
|
}
|
|
1016
982
|
return [x];
|
|
@@ -1018,26 +984,30 @@ function generateBadParametersMessage(
|
|
|
1018
984
|
|
|
1019
985
|
const requiredParamNames = toArray(paramRequirements.required);
|
|
1020
986
|
const actualParamNames = toArray(paramNames);
|
|
1021
|
-
const missingRequiredParamNames =
|
|
987
|
+
const missingRequiredParamNames = requiredParamNames.filter(
|
|
988
|
+
(name) => !actualParamNames.includes(name),
|
|
989
|
+
);
|
|
1022
990
|
const resultLines: string[] = [];
|
|
1023
991
|
resultLines.push(
|
|
1024
|
-
|
|
992
|
+
util.isEmpty(missingRequiredParamNames)
|
|
1025
993
|
? // This should not happen
|
|
1026
994
|
'Some of the provided parameters are not known'
|
|
1027
995
|
: `The following required parameter${
|
|
1028
996
|
missingRequiredParamNames.length === 1 ? ' is' : 's are'
|
|
1029
997
|
} missing: ${JSON.stringify(missingRequiredParamNames)}`,
|
|
1030
998
|
);
|
|
1031
|
-
if (!
|
|
999
|
+
if (!util.isEmpty(requiredParamNames)) {
|
|
1032
1000
|
resultLines.push(`Known required parameters are: ${JSON.stringify(requiredParamNames)}`);
|
|
1033
1001
|
}
|
|
1034
|
-
const optionalParamNames =
|
|
1035
|
-
|
|
1002
|
+
const optionalParamNames = toArray(paramRequirements.optional).filter(
|
|
1003
|
+
(name): name is string => typeof name === 'string' && !['sessionId', 'id'].includes(name),
|
|
1004
|
+
);
|
|
1005
|
+
if (!util.isEmpty(optionalParamNames)) {
|
|
1036
1006
|
resultLines.push(`Known optional parameters are: ${JSON.stringify(optionalParamNames)}`);
|
|
1037
1007
|
}
|
|
1038
1008
|
resultLines.push(
|
|
1039
1009
|
`You have provided${
|
|
1040
|
-
|
|
1010
|
+
util.isEmpty(actualParamNames) ? ' none' : ': ' + JSON.stringify(paramNames)
|
|
1041
1011
|
}`,
|
|
1042
1012
|
);
|
|
1043
1013
|
return resultLines.join('\n');
|
|
@@ -1087,22 +1057,25 @@ export const errors = {
|
|
|
1087
1057
|
ProxyRequestError,
|
|
1088
1058
|
} as const;
|
|
1089
1059
|
|
|
1090
|
-
const jsonwpErrorCodeMap: Record<string, Class<ProtocolError>> =
|
|
1091
|
-
|
|
1060
|
+
const jsonwpErrorCodeMap: Record<string, Class<ProtocolError>> = Object.values(errors).reduce(
|
|
1061
|
+
(acc: Record<string, Class<ProtocolError>>, ErrorClass: any) => {
|
|
1092
1062
|
if ('code' in ErrorClass) {
|
|
1093
1063
|
acc[ErrorClass.code()] = ErrorClass;
|
|
1094
1064
|
}
|
|
1095
1065
|
return acc;
|
|
1096
|
-
},
|
|
1066
|
+
},
|
|
1067
|
+
{},
|
|
1068
|
+
);
|
|
1097
1069
|
|
|
1098
|
-
const w3cErrorCodeMap: Record<string, Class<ProtocolError>> =
|
|
1099
|
-
|
|
1070
|
+
const w3cErrorCodeMap: Record<string, Class<ProtocolError>> = Object.values(errors).reduce(
|
|
1071
|
+
(acc: Record<string, Class<ProtocolError>>, ErrorClass: any) => {
|
|
1100
1072
|
if ('error' in ErrorClass) {
|
|
1101
1073
|
acc[ErrorClass.error()] = ErrorClass;
|
|
1102
1074
|
}
|
|
1103
1075
|
return acc;
|
|
1104
|
-
},
|
|
1105
|
-
|
|
1076
|
+
},
|
|
1077
|
+
{},
|
|
1078
|
+
);
|
|
1106
1079
|
|
|
1107
1080
|
interface MJSONWPError {
|
|
1108
1081
|
status: number;
|
|
@@ -1134,7 +1107,10 @@ export function isErrorType<T>(err: any, type: Class<T>): err is T {
|
|
|
1134
1107
|
* @param value The error message, or an object with a `message` property
|
|
1135
1108
|
* @return The error that is associated with provided JSONWP status code
|
|
1136
1109
|
*/
|
|
1137
|
-
export function errorFromMJSONWPStatusCode(
|
|
1110
|
+
export function errorFromMJSONWPStatusCode(
|
|
1111
|
+
code: number,
|
|
1112
|
+
value: string | {message: string} = '',
|
|
1113
|
+
): ProtocolError {
|
|
1138
1114
|
const ErrorClass = jsonwpErrorCodeMap[code] ?? UnknownError;
|
|
1139
1115
|
mjsonwpLog.debug(`Matched JSONWP error code ${code} to ${ErrorClass.name}`);
|
|
1140
1116
|
// if `value` is an object, pull message from it, otherwise use the plain
|
|
@@ -1150,8 +1126,12 @@ export function errorFromMJSONWPStatusCode(code: number, value: string | {messag
|
|
|
1150
1126
|
* @param stacktrace an optional error stacktrace
|
|
1151
1127
|
* @return The error that is associated with the W3C error string
|
|
1152
1128
|
*/
|
|
1153
|
-
export function errorFromW3CJsonCode(
|
|
1154
|
-
|
|
1129
|
+
export function errorFromW3CJsonCode(
|
|
1130
|
+
signature: string,
|
|
1131
|
+
message: string,
|
|
1132
|
+
stacktrace?: string,
|
|
1133
|
+
): ProtocolError {
|
|
1134
|
+
const ErrorClass = w3cErrorCodeMap[signature.toLowerCase()] ?? UnknownError;
|
|
1155
1135
|
w3cLog.debug(`Matched W3C error code '${signature}' to ${ErrorClass.name}`);
|
|
1156
1136
|
const resultError = new ErrorClass(message);
|
|
1157
1137
|
resultError.stacktrace = stacktrace;
|
|
@@ -1163,26 +1143,27 @@ export function errorFromW3CJsonCode(signature: string, message: string, stacktr
|
|
|
1163
1143
|
*
|
|
1164
1144
|
* @param err The error that needs to be translated
|
|
1165
1145
|
*/
|
|
1166
|
-
export function getResponseForW3CError(err: any): [number, {
|
|
1167
|
-
const protocolErrorToResponse: (e: ProtocolError) => [number, {
|
|
1168
|
-
|
|
1146
|
+
export function getResponseForW3CError(err: any): [number, {value: W3CError}] {
|
|
1147
|
+
const protocolErrorToResponse: (e: ProtocolError) => [number, {value: W3CError}] = (
|
|
1148
|
+
e: ProtocolError,
|
|
1149
|
+
) => [
|
|
1169
1150
|
e.w3cStatus,
|
|
1170
1151
|
{
|
|
1171
1152
|
value: {
|
|
1172
1153
|
error: e.error,
|
|
1173
1154
|
message: e.message,
|
|
1174
1155
|
stacktrace: e.stacktrace || e.stack,
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1177
1158
|
];
|
|
1178
1159
|
|
|
1179
1160
|
// err is ProtocolError
|
|
1180
|
-
if (['error', 'w3cStatus'].every((prop) =>
|
|
1161
|
+
if (['error', 'w3cStatus'].every((prop) => Object.hasOwn(err, prop))) {
|
|
1181
1162
|
return protocolErrorToResponse(err);
|
|
1182
1163
|
}
|
|
1183
1164
|
|
|
1184
1165
|
// err is ProxyRequestError
|
|
1185
|
-
if (
|
|
1166
|
+
if (Object.hasOwn(err, 'getActualError') && typeof err.getActualError === 'function') {
|
|
1186
1167
|
return protocolErrorToResponse(err.getActualError());
|
|
1187
1168
|
}
|
|
1188
1169
|
|
package/lib/protocol/helpers.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {util} from '@appium/support';
|
|
2
2
|
import {duplicateKeys} from '../basedriver/helpers';
|
|
3
3
|
import {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY} from '../constants';
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ import {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY} from '../constants';
|
|
|
11
11
|
* @returns Either modified value or the same one if nothing has been modified
|
|
12
12
|
*/
|
|
13
13
|
export function formatResponseValue(resValue: object | undefined): object | null {
|
|
14
|
-
if (
|
|
14
|
+
if (resValue === undefined) {
|
|
15
15
|
// convert undefined to null
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
@@ -30,7 +30,11 @@ export function formatResponseValue(resValue: object | undefined): object | null
|
|
|
30
30
|
* @returns The fixed response body
|
|
31
31
|
*/
|
|
32
32
|
export function ensureW3cResponse(responseBody: Record<string, unknown>): Record<string, unknown> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
if (!util.isPlainObject(responseBody)) {
|
|
34
|
+
return responseBody;
|
|
35
|
+
}
|
|
36
|
+
const result = {...responseBody};
|
|
37
|
+
delete result.status;
|
|
38
|
+
delete result.sessionId;
|
|
39
|
+
return result;
|
|
36
40
|
}
|