@appium/base-driver 10.7.0 → 10.7.2

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 (159) hide show
  1. package/README.md +2 -2
  2. package/build/lib/basedriver/capabilities.d.ts +1 -1
  3. package/build/lib/basedriver/capabilities.d.ts.map +1 -1
  4. package/build/lib/basedriver/capabilities.js +4 -8
  5. package/build/lib/basedriver/capabilities.js.map +1 -1
  6. package/build/lib/basedriver/commands/bidi.d.ts.map +1 -1
  7. package/build/lib/basedriver/commands/bidi.js +1 -3
  8. package/build/lib/basedriver/commands/bidi.js.map +1 -1
  9. package/build/lib/basedriver/commands/event.d.ts.map +1 -1
  10. package/build/lib/basedriver/commands/event.js.map +1 -1
  11. package/build/lib/basedriver/commands/execute.d.ts.map +1 -1
  12. package/build/lib/basedriver/commands/execute.js +1 -1
  13. package/build/lib/basedriver/commands/execute.js.map +1 -1
  14. package/build/lib/basedriver/commands/find.d.ts.map +1 -1
  15. package/build/lib/basedriver/commands/find.js.map +1 -1
  16. package/build/lib/basedriver/commands/log.d.ts.map +1 -1
  17. package/build/lib/basedriver/commands/log.js +1 -2
  18. package/build/lib/basedriver/commands/log.js.map +1 -1
  19. package/build/lib/basedriver/commands/mixin.d.ts.map +1 -1
  20. package/build/lib/basedriver/commands/mixin.js.map +1 -1
  21. package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
  22. package/build/lib/basedriver/commands/timeout.js +1 -1
  23. package/build/lib/basedriver/commands/timeout.js.map +1 -1
  24. package/build/lib/basedriver/core.d.ts +1 -2
  25. package/build/lib/basedriver/core.d.ts.map +1 -1
  26. package/build/lib/basedriver/core.js +6 -10
  27. package/build/lib/basedriver/core.js.map +1 -1
  28. package/build/lib/basedriver/device-settings.d.ts +1 -1
  29. package/build/lib/basedriver/device-settings.d.ts.map +1 -1
  30. package/build/lib/basedriver/device-settings.js +2 -3
  31. package/build/lib/basedriver/device-settings.js.map +1 -1
  32. package/build/lib/basedriver/driver.d.ts +1 -2
  33. package/build/lib/basedriver/driver.d.ts.map +1 -1
  34. package/build/lib/basedriver/driver.js +6 -11
  35. package/build/lib/basedriver/driver.js.map +1 -1
  36. package/build/lib/basedriver/extension-core.d.ts.map +1 -1
  37. package/build/lib/basedriver/extension-core.js +1 -1
  38. package/build/lib/basedriver/extension-core.js.map +1 -1
  39. package/build/lib/basedriver/helpers.d.ts.map +1 -1
  40. package/build/lib/basedriver/helpers.js +6 -11
  41. package/build/lib/basedriver/helpers.js.map +1 -1
  42. package/build/lib/basedriver/ipc.d.ts +1 -1
  43. package/build/lib/basedriver/ipc.d.ts.map +1 -1
  44. package/build/lib/basedriver/ipc.js +3 -5
  45. package/build/lib/basedriver/ipc.js.map +1 -1
  46. package/build/lib/basedriver/validation.d.ts.map +1 -1
  47. package/build/lib/basedriver/validation.js +1 -2
  48. package/build/lib/basedriver/validation.js.map +1 -1
  49. package/build/lib/express/express-logging.d.ts.map +1 -1
  50. package/build/lib/express/express-logging.js +4 -2
  51. package/build/lib/express/express-logging.js.map +1 -1
  52. package/build/lib/express/idempotency.d.ts +1 -1
  53. package/build/lib/express/idempotency.d.ts.map +1 -1
  54. package/build/lib/express/idempotency.js +6 -9
  55. package/build/lib/express/idempotency.js.map +1 -1
  56. package/build/lib/express/middleware.d.ts +1 -1
  57. package/build/lib/express/middleware.d.ts.map +1 -1
  58. package/build/lib/express/middleware.js +1 -1
  59. package/build/lib/express/middleware.js.map +1 -1
  60. package/build/lib/express/server.d.ts +2 -2
  61. package/build/lib/express/server.d.ts.map +1 -1
  62. package/build/lib/express/server.js +8 -9
  63. package/build/lib/express/server.js.map +1 -1
  64. package/build/lib/express/websocket.d.ts.map +1 -1
  65. package/build/lib/express/websocket.js.map +1 -1
  66. package/build/lib/helpers/capabilities.d.ts +1 -1
  67. package/build/lib/helpers/capabilities.d.ts.map +1 -1
  68. package/build/lib/helpers/capabilities.js.map +1 -1
  69. package/build/lib/helpers/extension-command-name.d.ts.map +1 -1
  70. package/build/lib/helpers/extension-command-name.js.map +1 -1
  71. package/build/lib/helpers/levenshtein-match.d.ts.map +1 -1
  72. package/build/lib/helpers/levenshtein-match.js +1 -4
  73. package/build/lib/helpers/levenshtein-match.js.map +1 -1
  74. package/build/lib/index.d.ts +21 -18
  75. package/build/lib/index.d.ts.map +1 -1
  76. package/build/lib/index.js +9 -12
  77. package/build/lib/index.js.map +1 -1
  78. package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
  79. package/build/lib/jsonwp-proxy/protocol-converter.js +6 -15
  80. package/build/lib/jsonwp-proxy/protocol-converter.js.map +1 -1
  81. package/build/lib/jsonwp-proxy/proxy.d.ts +3 -3
  82. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
  83. package/build/lib/jsonwp-proxy/proxy.js +17 -19
  84. package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
  85. package/build/lib/jsonwp-status/status.d.ts.map +1 -1
  86. package/build/lib/jsonwp-status/status.js.map +1 -1
  87. package/build/lib/protocol/errors.d.ts +1 -1
  88. package/build/lib/protocol/errors.d.ts.map +1 -1
  89. package/build/lib/protocol/errors.js +11 -28
  90. package/build/lib/protocol/errors.js.map +1 -1
  91. package/build/lib/protocol/helpers.d.ts.map +1 -1
  92. package/build/lib/protocol/helpers.js.map +1 -1
  93. package/build/lib/protocol/index.d.ts +4 -4
  94. package/build/lib/protocol/index.d.ts.map +1 -1
  95. package/build/lib/protocol/index.js +12 -12
  96. package/build/lib/protocol/index.js.map +1 -1
  97. package/build/lib/protocol/protocol.d.ts +1 -1
  98. package/build/lib/protocol/protocol.d.ts.map +1 -1
  99. package/build/lib/protocol/protocol.js +16 -30
  100. package/build/lib/protocol/protocol.js.map +1 -1
  101. package/build/lib/protocol/routes.d.ts +1 -1
  102. package/build/lib/protocol/routes.d.ts.map +1 -1
  103. package/build/lib/protocol/routes.js +5 -15
  104. package/build/lib/protocol/routes.js.map +1 -1
  105. package/build/lib/test-pages/handlers.d.ts.map +1 -1
  106. package/build/lib/test-pages/handlers.js +2 -2
  107. package/build/lib/test-pages/handlers.js.map +1 -1
  108. package/build/lib/test-pages/index.d.ts +1 -1
  109. package/build/lib/test-pages/index.d.ts.map +1 -1
  110. package/build/lib/test-pages/index.js +4 -4
  111. package/build/lib/test-pages/index.js.map +1 -1
  112. package/build/lib/test-pages/static-dir.d.ts.map +1 -1
  113. package/build/lib/test-pages/static-dir.js +5 -6
  114. package/build/lib/test-pages/static-dir.js.map +1 -1
  115. package/build/lib/test-pages/template.d.ts.map +1 -1
  116. package/build/lib/test-pages/template.js.map +1 -1
  117. package/build/lib/utils.d.ts.map +1 -1
  118. package/build/lib/utils.js.map +1 -1
  119. package/lib/basedriver/capabilities.ts +14 -37
  120. package/lib/basedriver/commands/bidi.ts +4 -14
  121. package/lib/basedriver/commands/event.ts +9 -15
  122. package/lib/basedriver/commands/execute.ts +5 -14
  123. package/lib/basedriver/commands/find.ts +3 -10
  124. package/lib/basedriver/commands/log.ts +2 -2
  125. package/lib/basedriver/commands/mixin.ts +1 -0
  126. package/lib/basedriver/commands/timeout.ts +5 -9
  127. package/lib/basedriver/core.ts +9 -15
  128. package/lib/basedriver/device-settings.ts +6 -9
  129. package/lib/basedriver/driver.ts +24 -48
  130. package/lib/basedriver/extension-core.ts +7 -12
  131. package/lib/basedriver/helpers.ts +18 -45
  132. package/lib/basedriver/ipc.ts +13 -18
  133. package/lib/basedriver/validation.ts +6 -16
  134. package/lib/express/express-logging.ts +11 -11
  135. package/lib/express/idempotency.ts +10 -19
  136. package/lib/express/middleware.ts +10 -18
  137. package/lib/express/server.ts +29 -38
  138. package/lib/express/websocket.ts +7 -13
  139. package/lib/helpers/capabilities.ts +2 -3
  140. package/lib/helpers/extension-command-name.ts +2 -4
  141. package/lib/helpers/levenshtein-match.ts +2 -7
  142. package/lib/{index.js → index.ts} +7 -9
  143. package/lib/jsonwp-proxy/protocol-converter.ts +24 -88
  144. package/lib/jsonwp-proxy/proxy.ts +34 -62
  145. package/lib/jsonwp-status/status.ts +5 -10
  146. package/lib/protocol/errors.ts +24 -70
  147. package/lib/protocol/helpers.ts +1 -0
  148. package/lib/protocol/index.ts +20 -26
  149. package/lib/protocol/protocol.ts +38 -82
  150. package/lib/protocol/routes.ts +8 -21
  151. package/lib/test-pages/handlers.ts +4 -2
  152. package/lib/test-pages/index.ts +5 -3
  153. package/lib/test-pages/static-dir.ts +6 -6
  154. package/lib/test-pages/template.ts +1 -3
  155. package/lib/utils.ts +1 -4
  156. package/package.json +29 -32
  157. package/tsconfig.json +14 -9
  158. package/LICENSE +0 -201
  159. package/index.js +0 -1
@@ -1,38 +1,31 @@
1
- import type {
2
- AppiumLogger,
3
- HTTPBody,
4
- HTTPHeaders,
5
- HTTPMethod,
6
- ProxyOptions,
7
- ProxyResponse,
8
- } from '@appium/types';
1
+ import http from 'node:http';
2
+ import https from 'node:https';
3
+ import nodeUrl from 'node:url';
4
+
9
5
  import {logger, util} from '@appium/support';
6
+ import type {AppiumLogger, HTTPBody, HTTPHeaders, HTTPMethod, ProxyOptions, ProxyResponse} from '@appium/types';
7
+ import type {AxiosError, AxiosResponse, RawAxiosRequestConfig} from 'axios';
8
+ import type {Request, Response} from 'express';
9
+ import {match as pathToRegexMatch} from 'path-to-regexp';
10
+
11
+ import {DEFAULT_BASE_PATH, MAX_LOG_BODY_LENGTH, PROTOCOLS} from '../constants';
10
12
  import {getSummaryByCode} from '../jsonwp-status/status';
13
+ import {isSessionCommand, routeToCommandName} from '../protocol';
11
14
  import {
12
- errors,
13
- isErrorType,
14
15
  errorFromMJSONWPStatusCode,
15
16
  errorFromW3CJsonCode,
17
+ errors,
16
18
  getResponseForW3CError,
19
+ isErrorType,
17
20
  } from '../protocol/errors';
18
- import {isSessionCommand, routeToCommandName} from '../protocol';
19
- import {MAX_LOG_BODY_LENGTH, DEFAULT_BASE_PATH, PROTOCOLS} from '../constants';
20
- import {ProtocolConverter} from './protocol-converter';
21
+ import {ensureW3cResponse, formatResponseValue} from '../protocol/helpers';
21
22
  import {omit, pick} from '../utils';
22
- import {formatResponseValue, ensureW3cResponse} from '../protocol/helpers';
23
- import http from 'node:http';
24
- import https from 'node:https';
25
- import {match as pathToRegexMatch} from 'path-to-regexp';
26
- import nodeUrl from 'node:url';
23
+ import {ProtocolConverter} from './protocol-converter';
27
24
  import {ProxyRequest} from './proxy-request';
28
- import type {Request, Response} from 'express';
29
- import type {AxiosError, AxiosResponse, RawAxiosRequestConfig} from 'axios';
30
25
 
31
26
  const DEFAULT_LOG = logger.getLogger('WD Proxy');
32
27
  const DEFAULT_REQUEST_TIMEOUT = 240000;
33
- const COMMAND_WITH_SESSION_ID_MATCHER = pathToRegexMatch(
34
- '{/*prefix}/session/:sessionId{/*command}',
35
- );
28
+ const COMMAND_WITH_SESSION_ID_MATCHER = pathToRegexMatch('{/*prefix}/session/:sessionId{/*command}');
36
29
 
37
30
  const {MJSONWP, W3C} = PROTOCOLS;
38
31
 
@@ -69,10 +62,10 @@ export class JWProxy {
69
62
  private readonly _log: AppiumLogger | undefined;
70
63
 
71
64
  constructor(opts: ProxyOptions = {}) {
72
- const filteredOptsWithoutLog = omit(
73
- pick(opts as Record<string, unknown>, ALLOWED_OPTS),
74
- 'log',
75
- ) as Omit<ProxyOptions, 'log'>;
65
+ const filteredOptsWithoutLog = omit(pick(opts as Record<string, unknown>, ALLOWED_OPTS), 'log') as Omit<
66
+ ProxyOptions,
67
+ 'log'
68
+ >;
76
69
  const options = {
77
70
  scheme: 'http',
78
71
  server: 'localhost',
@@ -177,11 +170,7 @@ export class JWProxy {
177
170
  /**
178
171
  * Proxies a raw WebDriver command to the downstream server.
179
172
  */
180
- async proxy(
181
- url: string,
182
- method: string,
183
- body: HTTPBody = null,
184
- ): Promise<[ProxyResponse, HTTPBody]> {
173
+ async proxy(url: string, method: string, body: HTTPBody = null): Promise<[ProxyResponse, HTTPBody]> {
185
174
  method = method.toUpperCase();
186
175
  const newUrl = this.getUrlForProxy(url, method as HTTPMethod);
187
176
  const truncateBody = (content: unknown): string =>
@@ -214,10 +203,9 @@ export class JWProxy {
214
203
  (error as Error).message,
215
204
  logger.markSensitive(truncateBody(body)),
216
205
  );
217
- throw new Error(
218
- 'Cannot interpret the request body as valid JSON. Check the server log for more details.',
219
- {cause: error},
220
- );
206
+ throw new Error('Cannot interpret the request body as valid JSON. Check the server log for more details.', {
207
+ cause: error,
208
+ });
221
209
  }
222
210
  } else {
223
211
  reqOpts.data = body;
@@ -253,7 +241,7 @@ export class JWProxy {
253
241
  // If it cannot be coerced to an object then the response is wrong
254
242
  throwProxyError(data);
255
243
  }
256
- this.log.debug(`Got response with status ${status}: ${truncateBody(data)}`);
244
+ this.log.debug(`Got response with status ${status}: %s`, logger.markSensitive(truncateBody(data)));
257
245
  isResponseLogged = true;
258
246
  const isSessionCreationRequest = url.endsWith('/session') && method === 'POST';
259
247
  if (isSessionCreationRequest) {
@@ -281,11 +269,12 @@ export class JWProxy {
281
269
  let proxyErrorMsg = err.message;
282
270
  if (util.hasValue(err.response)) {
283
271
  if (!isResponseLogged) {
284
- const error = truncateBody(err.response.data);
272
+ const error = logger.markSensitive(truncateBody(err.response.data));
285
273
  this.log.info(
286
274
  util.hasValue(err.response.status)
287
- ? `Got response with status ${err.response.status}: ${error}`
288
- : `Got response with unknown status: ${error}`,
275
+ ? `Got response with status ${err.response.status}: %s`
276
+ : `Got response with unknown status: %s`,
277
+ error,
289
278
  );
290
279
  }
291
280
  } else {
@@ -311,11 +300,7 @@ export class JWProxy {
311
300
  /**
312
301
  * Proxies a command identified by its HTTP method and URL to the downstream server.
313
302
  */
314
- async proxyCommand(
315
- url: string,
316
- method: HTTPMethod,
317
- body: HTTPBody = null,
318
- ): Promise<[ProxyResponse, HTTPBody]> {
303
+ async proxyCommand(url: string, method: HTTPMethod, body: HTTPBody = null): Promise<[ProxyResponse, HTTPBody]> {
319
304
  const parsedUrl = this._parseUrl(url);
320
305
  const normalizedPathname = this._toNormalizedPathname(parsedUrl);
321
306
  const commandName = normalizedPathname ? routeToCommandName(normalizedPathname, method) : '';
@@ -355,9 +340,7 @@ export class JWProxy {
355
340
  }
356
341
  throw errorFromMJSONWPStatusCode(
357
342
  status,
358
- util.isEmpty(message)
359
- ? getSummaryByCode(status)
360
- : (message as string | {message: string}),
343
+ util.isEmpty(message) ? getSummaryByCode(status) : (message as string | {message: string}),
361
344
  );
362
345
  }
363
346
  } else if (protocol === W3C) {
@@ -401,11 +384,7 @@ export class JWProxy {
401
384
  let statusCode: number;
402
385
  let resBodyObj: HTTPBody;
403
386
  try {
404
- const [response, body] = await this.proxyCommand(
405
- req.originalUrl,
406
- req.method as HTTPMethod,
407
- req.body,
408
- );
387
+ const [response, body] = await this.proxyCommand(req.originalUrl, req.method as HTTPMethod, req.body);
409
388
  statusCode = response.statusCode;
410
389
  resBodyObj = body;
411
390
  } catch (err: unknown) {
@@ -483,15 +462,8 @@ export class JWProxy {
483
462
  // This is needed for the backward compatibility
484
463
  // if drivers don't set reqBasePath properly
485
464
  if (!this.reqBasePath) {
486
- if (
487
- match &&
488
- match.params &&
489
- Array.isArray((match.params as Record<string, unknown>).prefix)
490
- ) {
491
- pathname = pathname.replace(
492
- `/${((match.params as Record<string, unknown>).prefix as string[]).join('/')}`,
493
- '',
494
- );
465
+ if (match && match.params && Array.isArray((match.params as Record<string, unknown>).prefix)) {
466
+ pathname = pathname.replace(`/${((match.params as Record<string, unknown>).prefix as string[]).join('/')}`, '');
495
467
  } else if (pathname.startsWith('/wd/hub')) {
496
468
  pathname = pathname.replace('/wd/hub', '');
497
469
  }
@@ -13,8 +13,7 @@ export const codes = {
13
13
  },
14
14
  NoSuchFrame: {
15
15
  code: 8,
16
- summary:
17
- 'A request to switch to a frame could not be satisfied because the frame could not be found.',
16
+ summary: 'A request to switch to a frame could not be satisfied because the frame could not be found.',
18
17
  },
19
18
  UnknownCommand: {
20
19
  code: 9,
@@ -23,13 +22,11 @@ export const codes = {
23
22
  },
24
23
  StaleElementReference: {
25
24
  code: 10,
26
- summary:
27
- 'An element command failed because the referenced element is no longer attached to the DOM.',
25
+ summary: 'An element command failed because the referenced element is no longer attached to the DOM.',
28
26
  },
29
27
  ElementNotVisible: {
30
28
  code: 11,
31
- summary:
32
- 'An element command could not be completed because the element is not visible on the page.',
29
+ summary: 'An element command could not be completed because the element is not visible on the page.',
33
30
  },
34
31
  InvalidElementState: {
35
32
  code: 12,
@@ -58,13 +55,11 @@ export const codes = {
58
55
  },
59
56
  NoSuchWindow: {
60
57
  code: 23,
61
- summary:
62
- 'A request to switch to a different window could not be satisfied because the window could not be found.',
58
+ summary: 'A request to switch to a different window could not be satisfied because the window could not be found.',
63
59
  },
64
60
  InvalidCookieDomain: {
65
61
  code: 24,
66
- summary:
67
- 'An illegal attempt was made to set a cookie under a different domain than the current page.',
62
+ summary: 'An illegal attempt was made to set a cookie under a different domain than the current page.',
68
63
  },
69
64
  UnableToSetCookie: {
70
65
  code: 25,
@@ -1,6 +1,6 @@
1
- import {util, logger} from '@appium/support';
1
+ import {logger, util} from '@appium/support';
2
+ import type {Class, ErrorBiDiCommandResponse} from '@appium/types';
2
3
  import {StatusCodes as HTTPStatusCodes} from 'http-status-codes';
3
- import type {ErrorBiDiCommandResponse, Class} from '@appium/types';
4
4
 
5
5
  const mjsonwpLog = logger.getLogger('MJSONWP');
6
6
  const w3cLog = logger.getLogger('W3C');
@@ -45,13 +45,7 @@ export class ProtocolError extends BaseError {
45
45
  public w3cStatus: number;
46
46
  protected _stacktrace: string | undefined;
47
47
 
48
- constructor(
49
- msg: string,
50
- jsonwpCode: number,
51
- w3cStatus: number,
52
- w3cErrorSignature: string,
53
- cause?: Error,
54
- ) {
48
+ constructor(msg: string, jsonwpCode: number, w3cStatus: number, w3cErrorSignature: string, cause?: Error) {
55
49
  super(msg, cause);
56
50
  this.jsonwpCode = jsonwpCode ?? UnknownError.code();
57
51
  this.error = w3cErrorSignature ?? UnknownError.error();
@@ -117,8 +111,7 @@ export class NoSuchDriverError extends ProtocolError {
117
111
  export class NoSuchElementError extends ProtocolError {
118
112
  constructor(message: string = '', cause?: Error) {
119
113
  super(
120
- message ||
121
- 'An element could not be located on the page using the given ' + 'search parameters.',
114
+ message || 'An element could not be located on the page using the given ' + 'search parameters.',
122
115
  NoSuchElementError.code(),
123
116
  NoSuchElementError.w3cStatus(),
124
117
  NoSuchElementError.error(),
@@ -171,9 +164,7 @@ export class NoSuchShadowRootError extends ProtocolError {
171
164
  export class NoSuchFrameError extends ProtocolError {
172
165
  constructor(message: string = '', cause?: Error) {
173
166
  super(
174
- message ||
175
- 'A request to switch to a frame could not be satisfied because ' +
176
- 'the frame could not be found.',
167
+ message || 'A request to switch to a frame could not be satisfied because ' + 'the frame could not be found.',
177
168
  NoSuchFrameError.code(),
178
169
  NoSuchFrameError.w3cStatus(),
179
170
  NoSuchFrameError.error(),
@@ -220,9 +211,7 @@ export class UnknownCommandError extends ProtocolError {
220
211
  export class StaleElementReferenceError extends ProtocolError {
221
212
  constructor(message: string = '', cause?: Error) {
222
213
  super(
223
- message ||
224
- 'An element command failed because the referenced element is no ' +
225
- 'longer attached to the DOM.',
214
+ message || 'An element command failed because the referenced element is no ' + 'longer attached to the DOM.',
226
215
  StaleElementReferenceError.code(),
227
216
  StaleElementReferenceError.w3cStatus(),
228
217
  StaleElementReferenceError.error(),
@@ -244,9 +233,7 @@ export class StaleElementReferenceError extends ProtocolError {
244
233
  export class ElementNotVisibleError extends ProtocolError {
245
234
  constructor(message: string = '', cause?: Error) {
246
235
  super(
247
- message ||
248
- 'An element command could not be completed because the element is ' +
249
- 'not visible on the page.',
236
+ message || 'An element command could not be completed because the element is ' + 'not visible on the page.',
250
237
  ElementNotVisibleError.code(),
251
238
  ElementNotVisibleError.w3cStatus(),
252
239
  ElementNotVisibleError.error(),
@@ -314,8 +301,7 @@ export class UnknownError extends ProtocolError {
314
301
  export class UnknownMethodError extends ProtocolError {
315
302
  constructor(message: string = '', cause?: Error) {
316
303
  super(
317
- message ||
318
- 'The requested command matched a known URL but did not match an method for that URL',
304
+ message || 'The requested command matched a known URL but did not match an method for that URL',
319
305
  UnknownMethodError.code(),
320
306
  UnknownMethodError.w3cStatus(),
321
307
  UnknownMethodError.error(),
@@ -405,8 +391,7 @@ export class ElementClickInterceptedError extends ProtocolError {
405
391
  export class ElementNotInteractableError extends ProtocolError {
406
392
  constructor(message: string = '', cause?: Error) {
407
393
  super(
408
- message ||
409
- 'A command could not be completed because the element is not pointer- or keyboard interactable',
394
+ message || 'A command could not be completed because the element is not pointer- or keyboard interactable',
410
395
  ElementNotInteractableError.code(),
411
396
  ElementNotInteractableError.w3cStatus(),
412
397
  ElementNotInteractableError.error(),
@@ -515,8 +500,7 @@ export class NoSuchWindowError extends ProtocolError {
515
500
  constructor(message: string = '', cause?: Error) {
516
501
  super(
517
502
  message ||
518
- 'A request to switch to a different window could not be satisfied ' +
519
- 'because the window could not be found.',
503
+ 'A request to switch to a different window could not be satisfied ' + 'because the window could not be found.',
520
504
  NoSuchWindowError.code(),
521
505
  NoSuchWindowError.w3cStatus(),
522
506
  NoSuchWindowError.error(),
@@ -560,9 +544,7 @@ export class InvalidArgumentError extends ProtocolError {
560
544
  export class InvalidCookieDomainError extends ProtocolError {
561
545
  constructor(message: string = '', cause?: Error) {
562
546
  super(
563
- message ||
564
- 'An illegal attempt was made to set a cookie under a different ' +
565
- 'domain than the current page.',
547
+ message || 'An illegal attempt was made to set a cookie under a different ' + 'domain than the current page.',
566
548
  InvalidCookieDomainError.code(),
567
549
  InvalidCookieDomainError.w3cStatus(),
568
550
  InvalidCookieDomainError.error(),
@@ -913,20 +895,14 @@ export class ProxyRequestError extends BaseError {
913
895
  private readonly _jwpError?: MJSONWPError;
914
896
 
915
897
  constructor(message: string, httpResponseData: any, httpStatus?: number, cause?: Error) {
916
- const [responseErrorObj, originalMessage] =
917
- ProxyRequestError._parseHttpResponse(httpResponseData);
898
+ const [responseErrorObj, originalMessage] = ProxyRequestError._parseHttpResponse(httpResponseData);
918
899
  super(
919
- util.isEmpty(message)
920
- ? `Proxy request unsuccessful.${originalMessage ? ' ' + originalMessage : ''}`
921
- : message,
900
+ util.isEmpty(message) ? `Proxy request unsuccessful.${originalMessage ? ' ' + originalMessage : ''}` : message,
922
901
  cause,
923
902
  );
924
903
 
925
904
  // If the response error is an object and value is an object, it's a W3C error (for JSONWP value is a string)
926
- if (
927
- util.isPlainObject(responseErrorObj.value) &&
928
- Object.hasOwn(responseErrorObj.value, 'error')
929
- ) {
905
+ if (util.isPlainObject(responseErrorObj.value) && Object.hasOwn(responseErrorObj.value, 'error')) {
930
906
  this._w3cError = responseErrorObj.value as unknown as typeof this._w3cError;
931
907
  this._w3cErrorStatus = httpStatus;
932
908
  } else if (Object.hasOwn(responseErrorObj, 'status')) {
@@ -953,11 +929,7 @@ export class ProxyRequestError extends BaseError {
953
929
  // If it's MJSONWP error, returns actual error cause for request failure based on `jsonwp.status`
954
930
  return errorFromMJSONWPStatusCode(this._jwpError.status, this._jwpError.value);
955
931
  }
956
- if (
957
- util.hasValue(this._w3cError) &&
958
- typeof this._w3cErrorStatus === 'number' &&
959
- this._w3cErrorStatus >= 300
960
- ) {
932
+ if (util.hasValue(this._w3cError) && typeof this._w3cErrorStatus === 'number' && this._w3cErrorStatus >= 300) {
961
933
  return errorFromW3CJsonCode(
962
934
  this._w3cError.error,
963
935
  this._w3cError.message || this.message,
@@ -968,10 +940,7 @@ export class ProxyRequestError extends BaseError {
968
940
  }
969
941
  }
970
942
 
971
- function generateBadParametersMessage(
972
- paramRequirements: ParameterRequirements,
973
- paramNames: string[],
974
- ): string {
943
+ function generateBadParametersMessage(paramRequirements: ParameterRequirements, paramNames: string[]): string {
975
944
  const toArray = function <T>(x: T | T[]): T[] {
976
945
  if (x === undefined) {
977
946
  return [];
@@ -984,17 +953,15 @@ function generateBadParametersMessage(
984
953
 
985
954
  const requiredParamNames = toArray(paramRequirements.required);
986
955
  const actualParamNames = toArray(paramNames);
987
- const missingRequiredParamNames = requiredParamNames.filter(
988
- (name) => !actualParamNames.includes(name),
989
- );
956
+ const missingRequiredParamNames = requiredParamNames.filter((name) => !actualParamNames.includes(name));
990
957
  const resultLines: string[] = [];
991
958
  resultLines.push(
992
959
  util.isEmpty(missingRequiredParamNames)
993
960
  ? // This should not happen
994
961
  'Some of the provided parameters are not known'
995
- : `The following required parameter${
996
- missingRequiredParamNames.length === 1 ? ' is' : 's are'
997
- } missing: ${JSON.stringify(missingRequiredParamNames)}`,
962
+ : `The following required parameter${missingRequiredParamNames.length === 1 ? ' is' : 's are'} missing: ${JSON.stringify(
963
+ missingRequiredParamNames,
964
+ )}`,
998
965
  );
999
966
  if (!util.isEmpty(requiredParamNames)) {
1000
967
  resultLines.push(`Known required parameters are: ${JSON.stringify(requiredParamNames)}`);
@@ -1005,11 +972,7 @@ function generateBadParametersMessage(
1005
972
  if (!util.isEmpty(optionalParamNames)) {
1006
973
  resultLines.push(`Known optional parameters are: ${JSON.stringify(optionalParamNames)}`);
1007
974
  }
1008
- resultLines.push(
1009
- `You have provided${
1010
- util.isEmpty(actualParamNames) ? ' none' : ': ' + JSON.stringify(paramNames)
1011
- }`,
1012
- );
975
+ resultLines.push(`You have provided${util.isEmpty(actualParamNames) ? ' none' : ': ' + JSON.stringify(paramNames)}`);
1013
976
  return resultLines.join('\n');
1014
977
  }
1015
978
 
@@ -1107,10 +1070,7 @@ export function isErrorType<T>(err: any, type: Class<T>): err is T {
1107
1070
  * @param value The error message, or an object with a `message` property
1108
1071
  * @return The error that is associated with provided JSONWP status code
1109
1072
  */
1110
- export function errorFromMJSONWPStatusCode(
1111
- code: number,
1112
- value: string | {message: string} = '',
1113
- ): ProtocolError {
1073
+ export function errorFromMJSONWPStatusCode(code: number, value: string | {message: string} = ''): ProtocolError {
1114
1074
  const ErrorClass = jsonwpErrorCodeMap[code] ?? UnknownError;
1115
1075
  mjsonwpLog.debug(`Matched JSONWP error code ${code} to ${ErrorClass.name}`);
1116
1076
  // if `value` is an object, pull message from it, otherwise use the plain
@@ -1126,11 +1086,7 @@ export function errorFromMJSONWPStatusCode(
1126
1086
  * @param stacktrace an optional error stacktrace
1127
1087
  * @return The error that is associated with the W3C error string
1128
1088
  */
1129
- export function errorFromW3CJsonCode(
1130
- signature: string,
1131
- message: string,
1132
- stacktrace?: string,
1133
- ): ProtocolError {
1089
+ export function errorFromW3CJsonCode(signature: string, message: string, stacktrace?: string): ProtocolError {
1134
1090
  const ErrorClass = w3cErrorCodeMap[signature.toLowerCase()] ?? UnknownError;
1135
1091
  w3cLog.debug(`Matched W3C error code '${signature}' to ${ErrorClass.name}`);
1136
1092
  const resultError = new ErrorClass(message);
@@ -1144,9 +1100,7 @@ export function errorFromW3CJsonCode(
1144
1100
  * @param err The error that needs to be translated
1145
1101
  */
1146
1102
  export function getResponseForW3CError(err: any): [number, {value: W3CError}] {
1147
- const protocolErrorToResponse: (e: ProtocolError) => [number, {value: W3CError}] = (
1148
- e: ProtocolError,
1149
- ) => [
1103
+ const protocolErrorToResponse: (e: ProtocolError) => [number, {value: W3CError}] = (e: ProtocolError) => [
1150
1104
  e.w3cStatus,
1151
1105
  {
1152
1106
  value: {
@@ -1,4 +1,5 @@
1
1
  import {util} from '@appium/support';
2
+
2
3
  import {duplicateKeys} from '../basedriver/helpers';
3
4
  import {MJSONWP_ELEMENT_KEY, W3C_ELEMENT_KEY} from '../constants';
4
5
 
@@ -1,44 +1,38 @@
1
+ import {errorFromMJSONWPStatusCode, errorFromW3CJsonCode, errors, getResponseForW3CError, isErrorType} from './errors';
1
2
  import {
2
- isSessionCommand,
3
- routeConfiguringFunction,
4
- determineProtocol,
3
+ checkParams,
5
4
  CREATE_SESSION_COMMAND,
6
5
  DELETE_SESSION_COMMAND,
6
+ determineProtocol,
7
7
  GET_STATUS_COMMAND,
8
+ isSessionCommand,
8
9
  LIST_DRIVER_COMMANDS_COMMAND,
9
10
  LIST_DRIVER_EXTENSIONS_COMMAND,
10
11
  makeArgs,
11
- checkParams,
12
+ routeConfiguringFunction,
12
13
  validateExecuteMethodParams,
13
14
  } from './protocol';
14
- import {NO_SESSION_ID_COMMANDS, ALL_COMMANDS, METHOD_MAP, routeToCommandName} from './routes';
15
- import {
16
- errors,
17
- isErrorType,
18
- errorFromMJSONWPStatusCode,
19
- errorFromW3CJsonCode,
20
- getResponseForW3CError,
21
- } from './errors';
15
+ import {ALL_COMMANDS, METHOD_MAP, NO_SESSION_ID_COMMANDS, routeToCommandName} from './routes';
22
16
 
23
17
  export {
24
- routeConfiguringFunction,
25
- errors,
26
- isErrorType,
27
- makeArgs,
28
- checkParams,
29
- validateExecuteMethodParams,
30
- errorFromMJSONWPStatusCode,
31
- errorFromW3CJsonCode,
32
18
  ALL_COMMANDS,
33
- METHOD_MAP,
34
- routeToCommandName,
35
- NO_SESSION_ID_COMMANDS,
36
- isSessionCommand,
37
- determineProtocol,
19
+ checkParams,
38
20
  CREATE_SESSION_COMMAND,
39
21
  DELETE_SESSION_COMMAND,
22
+ determineProtocol,
23
+ errorFromMJSONWPStatusCode,
24
+ errorFromW3CJsonCode,
25
+ errors,
40
26
  GET_STATUS_COMMAND,
27
+ getResponseForW3CError,
28
+ isErrorType,
29
+ isSessionCommand,
41
30
  LIST_DRIVER_COMMANDS_COMMAND,
42
31
  LIST_DRIVER_EXTENSIONS_COMMAND,
43
- getResponseForW3CError,
32
+ makeArgs,
33
+ METHOD_MAP,
34
+ NO_SESSION_ID_COMMANDS,
35
+ routeConfiguringFunction,
36
+ routeToCommandName,
37
+ validateExecuteMethodParams,
44
38
  };