@appium/base-driver 9.15.0 → 9.16.1

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 (43) hide show
  1. package/build/lib/basedriver/commands/execute.d.ts.map +1 -1
  2. package/build/lib/basedriver/commands/execute.js +24 -2
  3. package/build/lib/basedriver/commands/execute.js.map +1 -1
  4. package/build/lib/basedriver/driver.d.ts +7 -1
  5. package/build/lib/basedriver/driver.d.ts.map +1 -1
  6. package/build/lib/basedriver/driver.js +8 -0
  7. package/build/lib/basedriver/driver.js.map +1 -1
  8. package/build/lib/express/server.d.ts +23 -17
  9. package/build/lib/express/server.d.ts.map +1 -1
  10. package/build/lib/express/server.js +15 -3
  11. package/build/lib/express/server.js.map +1 -1
  12. package/build/lib/index.d.ts +1 -0
  13. package/build/lib/index.d.ts.map +1 -1
  14. package/build/lib/index.js +4 -1
  15. package/build/lib/index.js.map +1 -1
  16. package/build/lib/jsonwp-proxy/proxy.d.ts +15 -3
  17. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
  18. package/build/lib/jsonwp-proxy/proxy.js +43 -50
  19. package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
  20. package/build/lib/protocol/bidi-commands.js +3 -2
  21. package/build/lib/protocol/bidi-commands.js.map +1 -1
  22. package/build/lib/protocol/index.d.ts +3 -1
  23. package/build/lib/protocol/index.d.ts.map +1 -1
  24. package/build/lib/protocol/index.js +3 -1
  25. package/build/lib/protocol/index.js.map +1 -1
  26. package/build/lib/protocol/protocol.d.ts +5 -3
  27. package/build/lib/protocol/protocol.d.ts.map +1 -1
  28. package/build/lib/protocol/protocol.js +10 -11
  29. package/build/lib/protocol/protocol.js.map +1 -1
  30. package/build/lib/protocol/routes.d.ts +639 -604
  31. package/build/lib/protocol/routes.d.ts.map +1 -1
  32. package/build/lib/protocol/routes.js +399 -355
  33. package/build/lib/protocol/routes.js.map +1 -1
  34. package/lib/basedriver/commands/execute.ts +27 -2
  35. package/lib/basedriver/driver.ts +10 -0
  36. package/lib/express/server.js +24 -6
  37. package/lib/index.js +3 -0
  38. package/lib/jsonwp-proxy/proxy.js +52 -58
  39. package/lib/protocol/bidi-commands.js +1 -3
  40. package/lib/protocol/index.js +4 -0
  41. package/lib/protocol/protocol.js +5 -6
  42. package/lib/protocol/routes.js +410 -365
  43. package/package.json +6 -11
@@ -10,6 +10,11 @@ const lodash_1 = __importDefault(require("lodash"));
10
10
  const support_1 = require("@appium/support");
11
11
  const constants_1 = require("../constants");
12
12
  const path_to_regexp_1 = require("path-to-regexp");
13
+ const lru_cache_1 = require("lru-cache");
14
+ /** @type {LRUCache<string, string>} */
15
+ const COMMAND_NAMES_CACHE = new lru_cache_1.LRUCache({
16
+ max: 1024,
17
+ });
13
18
  const SET_ALERT_TEXT_PAYLOAD_PARAMS = {
14
19
  validate: (jsonObj) => !support_1.util.hasValue(jsonObj.value) &&
15
20
  !support_1.util.hasValue(jsonObj.text) &&
@@ -25,6 +30,11 @@ const SET_ALERT_TEXT_PAYLOAD_PARAMS = {
25
30
  * @satisfies {import('@appium/types').MethodMap<import('../basedriver/driver').BaseDriver>}
26
31
  */
27
32
  exports.METHOD_MAP = ({
33
+ //
34
+ // W3C WebDriver (and deprecated MJSONWP that will be removed in Appium 3)
35
+ // https://www.w3.org/TR/webdriver1/
36
+ // https://www.w3.org/TR/webdriver2/
37
+ //
28
38
  '/status': {
29
39
  GET: { command: 'getStatus' },
30
40
  },
@@ -32,6 +42,7 @@ exports.METHOD_MAP = ({
32
42
  POST: {
33
43
  command: 'createSession',
34
44
  payloadParams: {
45
+ // TODO: Appium 3 will accept only 'capabilities'.
35
46
  validate: (jsonObj) => !jsonObj.capabilities &&
36
47
  !jsonObj.desiredCapabilities &&
37
48
  'we require one of "desiredCapabilities" or "capabilities" object',
@@ -39,11 +50,8 @@ exports.METHOD_MAP = ({
39
50
  },
40
51
  },
41
52
  },
42
- '/sessions': {
43
- GET: { command: 'getSessions' },
44
- },
45
53
  '/session/:sessionId': {
46
- GET: { command: 'getSession' },
54
+ GET: { command: 'getSession', deprecated: true },
47
55
  DELETE: { command: 'deleteSession' },
48
56
  },
49
57
  '/session/:sessionId/timeouts': {
@@ -60,7 +68,7 @@ exports.METHOD_MAP = ({
60
68
  }
61
69
  }
62
70
  else {
63
- // MJSONWP
71
+ // TODO: Remove in Appium 3
64
72
  if (!support_1.util.hasValue(jsonObj.type) || !support_1.util.hasValue(jsonObj.ms)) {
65
73
  return 'MJSONWP protocol requires type and ms';
66
74
  }
@@ -70,25 +78,6 @@ exports.METHOD_MAP = ({
70
78
  },
71
79
  },
72
80
  },
73
- '/session/:sessionId/timeouts/async_script': {
74
- POST: { command: 'asyncScriptTimeout', payloadParams: { required: ['ms'] }, deprecated: true },
75
- },
76
- '/session/:sessionId/timeouts/implicit_wait': {
77
- POST: { command: 'implicitWait', payloadParams: { required: ['ms'] }, deprecated: true },
78
- },
79
- // JSONWP
80
- '/session/:sessionId/window_handle': {
81
- GET: { command: 'getWindowHandle' },
82
- },
83
- // W3C
84
- '/session/:sessionId/window/handle': {
85
- GET: { command: 'getWindowHandle' },
86
- },
87
- // JSONWP
88
- '/session/:sessionId/window_handles': {
89
- GET: { command: 'getWindowHandles' },
90
- },
91
- // W3C
92
81
  '/session/:sessionId/window/handles': {
93
82
  GET: { command: 'getWindowHandles' },
94
83
  },
@@ -105,39 +94,9 @@ exports.METHOD_MAP = ({
105
94
  '/session/:sessionId/refresh': {
106
95
  POST: { command: 'refresh' },
107
96
  },
108
- // MJSONWP
109
- '/session/:sessionId/execute': {
110
- POST: { command: 'execute', payloadParams: { required: ['script', 'args'] } },
111
- },
112
- // MJSONWP
113
- '/session/:sessionId/execute_async': {
114
- POST: {
115
- command: 'executeAsync',
116
- payloadParams: { required: ['script', 'args'] },
117
- },
118
- },
119
97
  '/session/:sessionId/screenshot': {
120
98
  GET: { command: 'getScreenshot' },
121
99
  },
122
- '/session/:sessionId/ime/available_engines': {
123
- GET: { command: 'availableIMEEngines', deprecated: true },
124
- },
125
- '/session/:sessionId/ime/active_engine': {
126
- GET: { command: 'getActiveIMEEngine', deprecated: true },
127
- },
128
- '/session/:sessionId/ime/activated': {
129
- GET: { command: 'isIMEActivated', deprecated: true },
130
- },
131
- '/session/:sessionId/ime/deactivate': {
132
- POST: { command: 'deactivateIMEEngine', deprecated: true },
133
- },
134
- '/session/:sessionId/ime/activate': {
135
- POST: {
136
- command: 'activateIMEEngine',
137
- payloadParams: { required: ['engine'] },
138
- deprecated: true,
139
- },
140
- },
141
100
  '/session/:sessionId/frame': {
142
101
  POST: { command: 'setFrame', payloadParams: { required: ['id'] } },
143
102
  },
@@ -149,6 +108,7 @@ exports.METHOD_MAP = ({
149
108
  POST: {
150
109
  command: 'setWindow',
151
110
  payloadParams: {
111
+ // TODO: Appium 3 will only accept 'handle'. 'name' will be ginored.
152
112
  optional: ['name', 'handle'],
153
113
  // Return both values to match W3C and JSONWP protocols
154
114
  makeArgs: (jsonObj) => {
@@ -167,15 +127,17 @@ exports.METHOD_MAP = ({
167
127
  },
168
128
  DELETE: { command: 'closeWindow' },
169
129
  },
170
- '/session/:sessionId/window/:windowhandle/size': {
171
- GET: { command: 'getWindowSize', deprecated: true },
130
+ '/session/:sessionId/window/maximize': {
131
+ POST: { command: 'maximizeWindow' },
172
132
  },
173
- '/session/:sessionId/window/:windowhandle/position': {
174
- POST: { deprecated: true },
175
- GET: { deprecated: true },
133
+ '/session/:sessionId/window/minimize': {
134
+ POST: { command: 'minimizeWindow' },
176
135
  },
177
- '/session/:sessionId/window/:windowhandle/maximize': {
178
- POST: { command: 'maximizeWindow' },
136
+ '/session/:sessionId/window/fullscreen': {
137
+ POST: { command: 'fullScreenWindow' },
138
+ },
139
+ '/session/:sessionId/window/new': {
140
+ POST: { command: 'createNewWindow', payloadParams: { optional: ['type'] } },
179
141
  },
180
142
  '/session/:sessionId/cookie': {
181
143
  GET: { command: 'getCookies' },
@@ -206,7 +168,7 @@ exports.METHOD_MAP = ({
206
168
  },
207
169
  '/session/:sessionId/element/active': {
208
170
  GET: { command: 'active' }, // W3C: https://w3c.github.io/webdriver/webdriver-spec.html#dfn-get-active-element
209
- POST: { command: 'active' },
171
+ POST: { command: 'active', deprecated: true },
210
172
  },
211
173
  '/session/:sessionId/element/:elementId': {
212
174
  GET: {},
@@ -226,9 +188,6 @@ exports.METHOD_MAP = ({
226
188
  '/session/:sessionId/element/:elementId/click': {
227
189
  POST: { command: 'click' },
228
190
  },
229
- '/session/:sessionId/element/:elementId/submit': {
230
- POST: { command: 'submit', deprecated: true },
231
- },
232
191
  '/session/:sessionId/element/:elementId/text': {
233
192
  GET: { command: 'getText' },
234
193
  },
@@ -239,6 +198,7 @@ exports.METHOD_MAP = ({
239
198
  validate: (jsonObj) => !support_1.util.hasValue(jsonObj.value) &&
240
199
  !support_1.util.hasValue(jsonObj.text) &&
241
200
  'we require one of "text" or "value" params',
201
+ // TODO: Appium 3 will accept only 'value'.
242
202
  optional: ['value', 'text'],
243
203
  // override the default argument constructor because of the special
244
204
  // logic here. Basically we want to accept either a value (old JSONWP)
@@ -249,9 +209,6 @@ exports.METHOD_MAP = ({
249
209
  },
250
210
  },
251
211
  },
252
- '/session/:sessionId/keys': {
253
- POST: { command: 'keys', payloadParams: { required: ['value'] }, deprecated: true },
254
- },
255
212
  '/session/:sessionId/element/:elementId/name': {
256
213
  GET: { command: 'getName' },
257
214
  },
@@ -267,21 +224,9 @@ exports.METHOD_MAP = ({
267
224
  '/session/:sessionId/element/:elementId/attribute/:name': {
268
225
  GET: { command: 'getAttribute' },
269
226
  },
270
- '/session/:sessionId/element/:elementId/equals/:otherId': {
271
- GET: { command: 'equalsElement', deprecated: true },
272
- },
273
227
  '/session/:sessionId/element/:elementId/displayed': {
274
228
  GET: { command: 'elementDisplayed' },
275
229
  },
276
- '/session/:sessionId/element/:elementId/location': {
277
- GET: { command: 'getLocation', deprecated: true },
278
- },
279
- '/session/:sessionId/element/:elementId/location_in_view': {
280
- GET: { command: 'getLocationInView', deprecated: true },
281
- },
282
- '/session/:sessionId/element/:elementId/size': {
283
- GET: { command: 'getSize', deprecated: true },
284
- },
285
230
  '/session/:sessionId/element/:elementId/shadow': {
286
231
  GET: { command: 'elementShadowRoot' },
287
232
  },
@@ -300,12 +245,8 @@ exports.METHOD_MAP = ({
300
245
  '/session/:sessionId/element/:elementId/css/:propertyName': {
301
246
  GET: { command: 'getCssProperty' },
302
247
  },
303
- '/session/:sessionId/orientation': {
304
- GET: { command: 'getOrientation' },
305
- POST: {
306
- command: 'setOrientation',
307
- payloadParams: { required: ['orientation'] },
308
- },
248
+ '/session/:sessionId/element/:elementId/property/:name': {
249
+ GET: { command: 'getProperty' },
309
250
  },
310
251
  // w3c v2 https://www.w3.org/TR/webdriver2/#get-computed-role
311
252
  'session/:sessionId/element/:elementId/computedrole': {
@@ -315,10 +256,331 @@ exports.METHOD_MAP = ({
315
256
  'session/:sessionId/element/:elementId/computedlabel': {
316
257
  GET: { command: 'getComputedLabel' },
317
258
  },
259
+ '/session/:sessionId/actions': {
260
+ POST: { command: 'performActions', payloadParams: { required: ['actions'] } },
261
+ DELETE: { command: 'releaseActions' },
262
+ },
263
+ '/session/:sessionId/alert/text': {
264
+ GET: { command: 'getAlertText' },
265
+ POST: {
266
+ command: 'setAlertText',
267
+ payloadParams: SET_ALERT_TEXT_PAYLOAD_PARAMS,
268
+ },
269
+ },
270
+ '/session/:sessionId/alert/accept': {
271
+ POST: { command: 'postAcceptAlert' },
272
+ },
273
+ '/session/:sessionId/alert/dismiss': {
274
+ POST: { command: 'postDismissAlert' },
275
+ },
276
+ '/session/:sessionId/element/:elementId/rect': {
277
+ GET: { command: 'getElementRect' },
278
+ },
279
+ '/session/:sessionId/execute/sync': {
280
+ POST: { command: 'execute', payloadParams: { required: ['script', 'args'] } },
281
+ },
282
+ '/session/:sessionId/execute/async': {
283
+ POST: {
284
+ command: 'executeAsync',
285
+ payloadParams: { required: ['script', 'args'] },
286
+ },
287
+ },
288
+ '/session/:sessionId/element/:elementId/screenshot': {
289
+ GET: { command: 'getElementScreenshot' },
290
+ },
291
+ '/session/:sessionId/window/rect': {
292
+ GET: { command: 'getWindowRect' },
293
+ POST: {
294
+ command: 'setWindowRect',
295
+ payloadParams: { optional: ['x', 'y', 'width', 'height'] },
296
+ },
297
+ },
298
+ //
299
+ // Appium specific
300
+ //
301
+ '/session/:sessionId/ime/available_engines': {
302
+ GET: { command: 'availableIMEEngines' },
303
+ },
304
+ '/session/:sessionId/ime/active_engine': {
305
+ GET: { command: 'getActiveIMEEngine' },
306
+ },
307
+ '/session/:sessionId/ime/activated': {
308
+ GET: { command: 'isIMEActivated' },
309
+ },
310
+ '/session/:sessionId/ime/deactivate': {
311
+ POST: { command: 'deactivateIMEEngine' },
312
+ },
313
+ '/session/:sessionId/ime/activate': {
314
+ POST: { command: 'activateIMEEngine', payloadParams: { required: ['engine'] } },
315
+ },
318
316
  '/session/:sessionId/rotation': {
319
317
  GET: { command: 'getRotation' },
320
318
  POST: { command: 'setRotation', payloadParams: { required: ['x', 'y', 'z'] } },
321
319
  },
320
+ '/session/:sessionId/location': {
321
+ GET: { command: 'getGeoLocation' },
322
+ POST: { command: 'setGeoLocation', payloadParams: { required: ['location'] } },
323
+ },
324
+ '/session/:sessionId/orientation': {
325
+ GET: { command: 'getOrientation' },
326
+ POST: {
327
+ command: 'setOrientation',
328
+ payloadParams: { required: ['orientation'] }
329
+ },
330
+ },
331
+ '/session/:sessionId/context': {
332
+ GET: { command: 'getCurrentContext' },
333
+ POST: { command: 'setContext', payloadParams: { required: ['name'] } },
334
+ },
335
+ '/session/:sessionId/contexts': {
336
+ GET: { command: 'getContexts' },
337
+ },
338
+ '/session/:sessionId/network_connection': {
339
+ GET: { command: 'getNetworkConnection' },
340
+ POST: {
341
+ command: 'setNetworkConnection',
342
+ payloadParams: { unwrap: 'parameters', required: ['type'] },
343
+ },
344
+ },
345
+ '/session/:sessionId/receive_async_response': {
346
+ POST: {
347
+ command: 'receiveAsyncResponse',
348
+ payloadParams: { required: ['status', 'value'] },
349
+ },
350
+ },
351
+ '/appium/sessions': {
352
+ GET: { command: 'getAppiumSessions' },
353
+ },
354
+ '/session/:sessionId/appium/capabilities': {
355
+ GET: { command: 'getAppiumSessionCapabilities' }
356
+ },
357
+ '/session/:sessionId/appium/device/system_time': {
358
+ GET: { command: 'getDeviceTime', payloadParams: { optional: ['format'] } },
359
+ POST: { command: 'getDeviceTime', payloadParams: { optional: ['format'] } },
360
+ },
361
+ // #region Applications Management
362
+ '/session/:sessionId/appium/device/install_app': {
363
+ POST: {
364
+ command: 'installApp',
365
+ payloadParams: {
366
+ required: ['appPath'],
367
+ optional: ['options'],
368
+ },
369
+ },
370
+ },
371
+ '/session/:sessionId/appium/device/activate_app': {
372
+ POST: {
373
+ command: 'activateApp',
374
+ payloadParams: {
375
+ required: [['appId'], ['bundleId']],
376
+ optional: ['options'],
377
+ },
378
+ },
379
+ },
380
+ '/session/:sessionId/appium/device/remove_app': {
381
+ POST: {
382
+ command: 'removeApp',
383
+ payloadParams: {
384
+ required: [['appId'], ['bundleId']],
385
+ optional: ['options'],
386
+ },
387
+ },
388
+ },
389
+ '/session/:sessionId/appium/device/terminate_app': {
390
+ POST: {
391
+ command: 'terminateApp',
392
+ payloadParams: {
393
+ required: [['appId'], ['bundleId']],
394
+ optional: ['options'],
395
+ },
396
+ },
397
+ },
398
+ '/session/:sessionId/appium/device/app_installed': {
399
+ POST: {
400
+ command: 'isAppInstalled',
401
+ payloadParams: {
402
+ required: [['appId'], ['bundleId']],
403
+ },
404
+ },
405
+ },
406
+ '/session/:sessionId/appium/device/app_state': {
407
+ GET: {
408
+ command: 'queryAppState',
409
+ payloadParams: {
410
+ required: [['appId'], ['bundleId']],
411
+ },
412
+ },
413
+ POST: {
414
+ command: 'queryAppState',
415
+ payloadParams: {
416
+ required: [['appId'], ['bundleId']],
417
+ },
418
+ deprecated: true,
419
+ },
420
+ },
421
+ // #endregion
422
+ '/session/:sessionId/appium/device/hide_keyboard': {
423
+ POST: {
424
+ command: 'hideKeyboard',
425
+ payloadParams: { optional: ['strategy', 'key', 'keyCode', 'keyName'] },
426
+ },
427
+ },
428
+ '/session/:sessionId/appium/device/is_keyboard_shown': {
429
+ GET: { command: 'isKeyboardShown' },
430
+ },
431
+ '/session/:sessionId/appium/device/push_file': {
432
+ POST: { command: 'pushFile', payloadParams: { required: ['path', 'data'] } },
433
+ },
434
+ '/session/:sessionId/appium/device/pull_file': {
435
+ POST: { command: 'pullFile', payloadParams: { required: ['path'] } },
436
+ },
437
+ '/session/:sessionId/appium/device/pull_folder': {
438
+ POST: { command: 'pullFolder', payloadParams: { required: ['path'] } },
439
+ },
440
+ '/session/:sessionId/appium/settings': {
441
+ POST: { command: 'updateSettings', payloadParams: { required: ['settings'] } },
442
+ GET: { command: 'getSettings' },
443
+ },
444
+ '/session/:sessionId/appium/events': {
445
+ POST: { command: 'getLogEvents', payloadParams: { optional: ['type'] } },
446
+ },
447
+ '/session/:sessionId/appium/log_event': {
448
+ POST: {
449
+ command: 'logCustomEvent',
450
+ payloadParams: { required: ['vendor', 'event'] },
451
+ },
452
+ },
453
+ // #region Inspector
454
+ '/session/:sessionId/appium/commands': {
455
+ GET: { command: 'listCommands' },
456
+ },
457
+ '/session/:sessionId/appium/extensions': {
458
+ GET: { command: 'listExtensions' },
459
+ },
460
+ // #endregion
461
+ //
462
+ // 3rd party vendor/protcol support
463
+ //
464
+ // #region Selenium/Chromium browsers
465
+ '/session/:sessionId/se/log': {
466
+ POST: { command: 'getLog', payloadParams: { required: ['type'] } },
467
+ },
468
+ '/session/:sessionId/se/log/types': {
469
+ GET: { command: 'getLogTypes' },
470
+ },
471
+ // #endregion
472
+ // #region chromium devtools
473
+ // https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/server/http_handler.cc
474
+ '/session/:sessionId/:vendor/cdp/execute': {
475
+ POST: { command: 'executeCdp', payloadParams: { required: ['cmd', 'params'] } },
476
+ },
477
+ // #endregion
478
+ // #region Webauthn
479
+ // https://www.w3.org/TR/webauthn-2/#sctn-automation-add-virtual-authenticator
480
+ '/session/:sessionId/webauthn/authenticator': {
481
+ POST: {
482
+ command: 'addVirtualAuthenticator',
483
+ payloadParams: {
484
+ required: ['protocol', 'transport'],
485
+ optional: ['hasResidentKey', 'hasUserVerification', 'isUserConsenting', 'isUserVerified'],
486
+ },
487
+ },
488
+ },
489
+ '/session/:sessionId/webauthn/authenticator/:authenticatorId': {
490
+ DELETE: {
491
+ command: 'removeVirtualAuthenticator',
492
+ },
493
+ },
494
+ '/session/:sessionId/webauthn/authenticator/:authenticatorId/credential': {
495
+ POST: {
496
+ command: 'addAuthCredential',
497
+ payloadParams: {
498
+ required: ['credentialId', 'isResidentCredential', 'rpId', 'privateKey'],
499
+ optional: ['userHandle', 'signCount'],
500
+ },
501
+ },
502
+ },
503
+ '/session/:sessionId/webauthn/authenticator/:authenticatorId/credentials': {
504
+ GET: { command: 'getAuthCredential' },
505
+ DELETE: { command: 'removeAllAuthCredentials' },
506
+ },
507
+ '/session/:sessionId/webauthn/authenticator/:authenticatorId/credentials/:credentialId': {
508
+ DELETE: { command: 'removeAuthCredential' },
509
+ },
510
+ '/session/:sessionId/webauthn/authenticator/:authenticatorId/uv': {
511
+ POST: {
512
+ command: 'setUserAuthVerified',
513
+ payloadParams: {
514
+ required: ['isUserVerified'],
515
+ },
516
+ },
517
+ },
518
+ // #endregion
519
+ //
520
+ // Endpoints deprecated entirely
521
+ //
522
+ // #region MJSONWP
523
+ '/sessions': {
524
+ GET: { command: 'getSessions', deprecated: true },
525
+ },
526
+ '/session/:sessionId/timeouts/async_script': {
527
+ POST: { command: 'asyncScriptTimeout', payloadParams: { required: ['ms'] }, deprecated: true },
528
+ },
529
+ '/session/:sessionId/timeouts/implicit_wait': {
530
+ POST: { command: 'implicitWait', payloadParams: { required: ['ms'] }, deprecated: true },
531
+ },
532
+ '/session/:sessionId/window_handle': {
533
+ GET: { command: 'getWindowHandle', deprecated: true },
534
+ },
535
+ // Only 'window/handles' exists in W3C WebDriver spec.
536
+ '/session/:sessionId/window/handle': {
537
+ GET: { command: 'getWindowHandle', deprecated: true },
538
+ },
539
+ '/session/:sessionId/window_handles': {
540
+ GET: { command: 'getWindowHandles', deprecated: true },
541
+ },
542
+ '/session/:sessionId/execute': {
543
+ POST: {
544
+ command: 'execute',
545
+ payloadParams: { required: ['script', 'args'] },
546
+ deprecated: true
547
+ },
548
+ },
549
+ '/session/:sessionId/execute_async': {
550
+ POST: {
551
+ command: 'executeAsync',
552
+ payloadParams: { required: ['script', 'args'] },
553
+ deprecated: true
554
+ },
555
+ },
556
+ '/session/:sessionId/window/:windowhandle/size': {
557
+ GET: { command: 'getWindowSize', deprecated: true },
558
+ },
559
+ '/session/:sessionId/window/:windowhandle/position': {
560
+ POST: { deprecated: true },
561
+ GET: { deprecated: true },
562
+ },
563
+ '/session/:sessionId/window/:windowhandle/maximize': {
564
+ POST: { command: 'maximizeWindow', deprecated: true },
565
+ },
566
+ '/session/:sessionId/element/:elementId/submit': {
567
+ POST: { command: 'submit', deprecated: true },
568
+ },
569
+ '/session/:sessionId/keys': {
570
+ POST: { command: 'keys', payloadParams: { required: ['value'] }, deprecated: true },
571
+ },
572
+ '/session/:sessionId/element/:elementId/equals/:otherId': {
573
+ GET: { command: 'equalsElement', deprecated: true },
574
+ },
575
+ '/session/:sessionId/element/:elementId/location': {
576
+ GET: { command: 'getLocation', deprecated: true },
577
+ },
578
+ '/session/:sessionId/element/:elementId/location_in_view': {
579
+ GET: { command: 'getLocationInView', deprecated: true },
580
+ },
581
+ '/session/:sessionId/element/:elementId/size': {
582
+ GET: { command: 'getSize', deprecated: true },
583
+ },
322
584
  '/session/:sessionId/moveto': {
323
585
  POST: {
324
586
  command: 'moveTo',
@@ -354,11 +616,7 @@ exports.METHOD_MAP = ({
354
616
  POST: { deprecated: true },
355
617
  },
356
618
  '/session/:sessionId/touch/doubleclick': {
357
- POST: {},
358
- },
359
- '/session/:sessionId/actions': {
360
- POST: { command: 'performActions', payloadParams: { required: ['actions'] } },
361
- DELETE: { command: 'releaseActions' },
619
+ POST: { deprecated: true },
362
620
  },
363
621
  '/session/:sessionId/touch/longclick': {
364
622
  POST: {
@@ -374,11 +632,7 @@ exports.METHOD_MAP = ({
374
632
  optional: ['element', 'xspeed', 'yspeed', 'xoffset', 'yoffset', 'speed'],
375
633
  },
376
634
  deprecated: true,
377
- },
378
- },
379
- '/session/:sessionId/location': {
380
- GET: { command: 'getGeoLocation' },
381
- POST: { command: 'setGeoLocation', payloadParams: { required: ['location'] } },
635
+ },
382
636
  },
383
637
  '/session/:sessionId/local_storage': {
384
638
  GET: { deprecated: true },
@@ -404,45 +658,32 @@ exports.METHOD_MAP = ({
404
658
  '/session/:sessionId/session_storage/size': {
405
659
  GET: { deprecated: true },
406
660
  },
407
- // Selenium 4 clients
408
- '/session/:sessionId/se/log': {
409
- POST: { command: 'getLog', payloadParams: { required: ['type'] } },
410
- },
411
- // Selenium 4 clients
412
- '/session/:sessionId/se/log/types': {
413
- GET: { command: 'getLogTypes' },
414
- },
415
- // mjsonwire, appium clients
416
- '/session/:sessionId/log': {
417
- POST: { command: 'getLog', payloadParams: { required: ['type'] } },
661
+ '/session/:sessionId/application_cache/status': {
662
+ GET: { deprecated: true },
418
663
  },
419
- // mjsonwire, appium clients
420
- '/session/:sessionId/log/types': {
421
- GET: { command: 'getLogTypes' },
664
+ '/session/:sessionId/alert_text': {
665
+ GET: { command: 'getAlertText', deprecated: true },
666
+ POST: {
667
+ command: 'setAlertText',
668
+ payloadParams: SET_ALERT_TEXT_PAYLOAD_PARAMS,
669
+ deprecated: true
670
+ },
422
671
  },
423
- '/session/:sessionId/application_cache/status': {
424
- GET: {},
672
+ '/session/:sessionId/accept_alert': {
673
+ POST: { command: 'postAcceptAlert', deprecated: true },
425
674
  },
426
- //
427
- // mjsonwire
428
- //
429
- '/session/:sessionId/context': {
430
- GET: { command: 'getCurrentContext' },
431
- POST: { command: 'setContext', payloadParams: { required: ['name'] } },
675
+ '/session/:sessionId/dismiss_alert': {
676
+ POST: { command: 'postDismissAlert', deprecated: true },
432
677
  },
433
- '/session/:sessionId/contexts': {
434
- GET: { command: 'getContexts' },
678
+ // Pre-W3C endpoint for element screenshot
679
+ '/session/:sessionId/screenshot/:elementId': {
680
+ GET: { command: 'getElementScreenshot', deprecated: true },
435
681
  },
682
+ // #endregion
683
+ // #region Appium specific
436
684
  '/session/:sessionId/element/:elementId/pageIndex': {
437
685
  GET: { command: 'getPageIndex', deprecated: true },
438
686
  },
439
- '/session/:sessionId/network_connection': {
440
- GET: { command: 'getNetworkConnection' },
441
- POST: {
442
- command: 'setNetworkConnection',
443
- payloadParams: { unwrap: 'parameters', required: ['type'] },
444
- },
445
- },
446
687
  '/session/:sessionId/touch/perform': {
447
688
  POST: {
448
689
  command: 'performTouch',
@@ -457,19 +698,9 @@ exports.METHOD_MAP = ({
457
698
  deprecated: true,
458
699
  },
459
700
  },
460
- '/session/:sessionId/receive_async_response': {
461
- POST: {
462
- command: 'receiveAsyncResponse',
463
- payloadParams: { required: ['status', 'value'] },
464
- },
465
- },
466
701
  '/session/:sessionId/appium/device/shake': {
467
702
  POST: { command: 'mobileShake', deprecated: true },
468
703
  },
469
- '/session/:sessionId/appium/device/system_time': {
470
- GET: { command: 'getDeviceTime', payloadParams: { optional: ['format'] } },
471
- POST: { command: 'getDeviceTime', payloadParams: { optional: ['format'] } },
472
- },
473
704
  '/session/:sessionId/appium/device/lock': {
474
705
  POST: { command: 'lock', payloadParams: { optional: ['seconds'] }, deprecated: true },
475
706
  },
@@ -573,85 +804,6 @@ exports.METHOD_MAP = ({
573
804
  '/session/:sessionId/appium/device/current_package': {
574
805
  GET: { command: 'getCurrentPackage', deprecated: true },
575
806
  },
576
- //region Applications Management
577
- '/session/:sessionId/appium/device/install_app': {
578
- POST: {
579
- command: 'installApp',
580
- payloadParams: {
581
- required: ['appPath'],
582
- optional: ['options'],
583
- },
584
- },
585
- },
586
- '/session/:sessionId/appium/device/activate_app': {
587
- POST: {
588
- command: 'activateApp',
589
- payloadParams: {
590
- required: [['appId'], ['bundleId']],
591
- optional: ['options'],
592
- },
593
- },
594
- },
595
- '/session/:sessionId/appium/device/remove_app': {
596
- POST: {
597
- command: 'removeApp',
598
- payloadParams: {
599
- required: [['appId'], ['bundleId']],
600
- optional: ['options'],
601
- },
602
- },
603
- },
604
- '/session/:sessionId/appium/device/terminate_app': {
605
- POST: {
606
- command: 'terminateApp',
607
- payloadParams: {
608
- required: [['appId'], ['bundleId']],
609
- optional: ['options'],
610
- },
611
- },
612
- },
613
- '/session/:sessionId/appium/device/app_installed': {
614
- POST: {
615
- command: 'isAppInstalled',
616
- payloadParams: {
617
- required: [['appId'], ['bundleId']],
618
- },
619
- },
620
- },
621
- '/session/:sessionId/appium/device/app_state': {
622
- GET: {
623
- command: 'queryAppState',
624
- payloadParams: {
625
- required: [['appId'], ['bundleId']],
626
- },
627
- },
628
- POST: {
629
- command: 'queryAppState',
630
- payloadParams: {
631
- required: [['appId'], ['bundleId']],
632
- },
633
- deprecated: true,
634
- },
635
- },
636
- //endregion
637
- '/session/:sessionId/appium/device/hide_keyboard': {
638
- POST: {
639
- command: 'hideKeyboard',
640
- payloadParams: { optional: ['strategy', 'key', 'keyCode', 'keyName'] },
641
- },
642
- },
643
- '/session/:sessionId/appium/device/is_keyboard_shown': {
644
- GET: { command: 'isKeyboardShown' },
645
- },
646
- '/session/:sessionId/appium/device/push_file': {
647
- POST: { command: 'pushFile', payloadParams: { required: ['path', 'data'] } },
648
- },
649
- '/session/:sessionId/appium/device/pull_file': {
650
- POST: { command: 'pullFile', payloadParams: { required: ['path'] } },
651
- },
652
- '/session/:sessionId/appium/device/pull_folder': {
653
- POST: { command: 'pullFolder', payloadParams: { required: ['path'] } },
654
- },
655
807
  '/session/:sessionId/appium/device/toggle_airplane_mode': {
656
808
  POST: { command: 'toggleFlightMode', deprecated: true },
657
809
  },
@@ -741,10 +893,6 @@ exports.METHOD_MAP = ({
741
893
  deprecated: true,
742
894
  },
743
895
  },
744
- '/session/:sessionId/appium/settings': {
745
- POST: { command: 'updateSettings', payloadParams: { required: ['settings'] } },
746
- GET: { command: 'getSettings' },
747
- },
748
896
  '/session/:sessionId/appium/receive_async_response': {
749
897
  POST: {
750
898
  command: 'receiveAsyncResponse',
@@ -752,93 +900,6 @@ exports.METHOD_MAP = ({
752
900
  deprecated: true,
753
901
  },
754
902
  },
755
- '/session/:sessionId/appium/events': {
756
- POST: { command: 'getLogEvents', payloadParams: { optional: ['type'] } },
757
- },
758
- '/session/:sessionId/appium/log_event': {
759
- POST: {
760
- command: 'logCustomEvent',
761
- payloadParams: { required: ['vendor', 'event'] },
762
- },
763
- },
764
- /*
765
- * The W3C spec has some changes to the wire protocol.
766
- * https://w3c.github.io/webdriver/webdriver-spec.html
767
- * Begin to add those changes here, keeping the old version
768
- * since clients still implement them.
769
- */
770
- // MJSONWP
771
- '/session/:sessionId/alert_text': {
772
- GET: { command: 'getAlertText' },
773
- POST: {
774
- command: 'setAlertText',
775
- payloadParams: SET_ALERT_TEXT_PAYLOAD_PARAMS,
776
- },
777
- },
778
- // MJSONWP
779
- '/session/:sessionId/accept_alert': {
780
- POST: { command: 'postAcceptAlert' },
781
- },
782
- // MJSONWP
783
- '/session/:sessionId/dismiss_alert': {
784
- POST: { command: 'postDismissAlert' },
785
- },
786
- // https://w3c.github.io/webdriver/webdriver-spec.html#user-prompts
787
- '/session/:sessionId/alert/text': {
788
- GET: { command: 'getAlertText' },
789
- POST: {
790
- command: 'setAlertText',
791
- payloadParams: SET_ALERT_TEXT_PAYLOAD_PARAMS,
792
- },
793
- },
794
- '/session/:sessionId/alert/accept': {
795
- POST: { command: 'postAcceptAlert' },
796
- },
797
- '/session/:sessionId/alert/dismiss': {
798
- POST: { command: 'postDismissAlert' },
799
- },
800
- // https://w3c.github.io/webdriver/webdriver-spec.html#get-element-rect
801
- '/session/:sessionId/element/:elementId/rect': {
802
- GET: { command: 'getElementRect' },
803
- },
804
- '/session/:sessionId/execute/sync': {
805
- POST: { command: 'execute', payloadParams: { required: ['script', 'args'] } },
806
- },
807
- '/session/:sessionId/execute/async': {
808
- POST: {
809
- command: 'executeAsync',
810
- payloadParams: { required: ['script', 'args'] },
811
- },
812
- },
813
- // Pre-W3C endpoint for element screenshot
814
- '/session/:sessionId/screenshot/:elementId': {
815
- GET: { command: 'getElementScreenshot' },
816
- },
817
- '/session/:sessionId/element/:elementId/screenshot': {
818
- GET: { command: 'getElementScreenshot' },
819
- },
820
- '/session/:sessionId/window/rect': {
821
- GET: { command: 'getWindowRect' },
822
- POST: {
823
- command: 'setWindowRect',
824
- payloadParams: { optional: ['x', 'y', 'width', 'height'] },
825
- },
826
- },
827
- '/session/:sessionId/window/maximize': {
828
- POST: { command: 'maximizeWindow' },
829
- },
830
- '/session/:sessionId/window/minimize': {
831
- POST: { command: 'minimizeWindow' },
832
- },
833
- '/session/:sessionId/window/fullscreen': {
834
- POST: { command: 'fullScreenWindow' },
835
- },
836
- '/session/:sessionId/window/new': {
837
- POST: { command: 'createNewWindow', payloadParams: { optional: ['type'] } },
838
- },
839
- '/session/:sessionId/element/:elementId/property/:name': {
840
- GET: { command: 'getProperty' },
841
- },
842
903
  '/session/:sessionId/appium/device/set_clipboard': {
843
904
  POST: {
844
905
  command: 'setClipboard',
@@ -858,52 +919,15 @@ exports.METHOD_MAP = ({
858
919
  deprecated: true,
859
920
  },
860
921
  },
861
- // chromium devtools
862
- // https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/server/http_handler.cc
863
- '/session/:sessionId/:vendor/cdp/execute': {
864
- POST: { command: 'executeCdp', payloadParams: { required: ['cmd', 'params'] } },
865
- },
866
- //region Webauthn
867
- // https://www.w3.org/TR/webauthn-2/#sctn-automation-add-virtual-authenticator
868
- '/session/:sessionId/webauthn/authenticator': {
869
- POST: {
870
- command: 'addVirtualAuthenticator',
871
- payloadParams: {
872
- required: ['protocol', 'transport'],
873
- optional: ['hasResidentKey', 'hasUserVerification', 'isUserConsenting', 'isUserVerified'],
874
- },
875
- },
876
- },
877
- '/session/:sessionId/webauthn/authenticator/:authenticatorId': {
878
- DELETE: {
879
- command: 'removeVirtualAuthenticator',
880
- },
881
- },
882
- '/session/:sessionId/webauthn/authenticator/:authenticatorId/credential': {
883
- POST: {
884
- command: 'addAuthCredential',
885
- payloadParams: {
886
- required: ['credentialId', 'isResidentCredential', 'rpId', 'privateKey'],
887
- optional: ['userHandle', 'signCount'],
888
- },
889
- },
890
- },
891
- '/session/:sessionId/webauthn/authenticator/:authenticatorId/credentials': {
892
- GET: { command: 'getAuthCredential' },
893
- DELETE: { command: 'removeAllAuthCredentials' },
894
- },
895
- '/session/:sessionId/webauthn/authenticator/:authenticatorId/credentials/:credentialId': {
896
- DELETE: { command: 'removeAuthCredential' },
922
+ // #endregion
923
+ // #region JSONWP
924
+ '/session/:sessionId/log': {
925
+ POST: { command: 'getLog', payloadParams: { required: ['type'] }, deprecated: true },
897
926
  },
898
- '/session/:sessionId/webauthn/authenticator/:authenticatorId/uv': {
899
- POST: {
900
- command: 'setUserAuthVerified',
901
- payloadParams: {
902
- required: ['isUserVerified'],
903
- },
904
- },
927
+ '/session/:sessionId/log/types': {
928
+ GET: { command: 'getLogTypes', deprecated: true },
905
929
  },
906
- //endregion
930
+ // #endregion
907
931
  });
908
932
  // driver command names
909
933
  exports.ALL_COMMANDS = lodash_1.default.flatMap(lodash_1.default.values(exports.METHOD_MAP).map(lodash_1.default.values))
@@ -912,7 +936,7 @@ exports.ALL_COMMANDS = lodash_1.default.flatMap(lodash_1.default.values(exports.
912
936
  /**
913
937
  *
914
938
  * @param {string} endpoint
915
- * @param {import('@appium/types').HTTPMethod} method
939
+ * @param {import('@appium/types').HTTPMethod} [method]
916
940
  * @param {string} [basePath=DEFAULT_BASE_PATH]
917
941
  * @returns {string|undefined}
918
942
  */
@@ -930,23 +954,43 @@ function routeToCommandName(endpoint, method, basePath = constants_1.DEFAULT_BAS
930
954
  catch (err) {
931
955
  throw new Error(`'${endpoint}' cannot be translated to a command name: ${err.message}`);
932
956
  }
957
+ const normalizedMethod = lodash_1.default.toUpper(method);
958
+ const cacheKey = toCommandNameCacheKey(normalizedPathname, normalizedMethod);
959
+ if (COMMAND_NAMES_CACHE.has(cacheKey)) {
960
+ return COMMAND_NAMES_CACHE.get(cacheKey) || undefined;
961
+ }
933
962
  /** @type {string[]} */
934
963
  const possiblePathnames = [];
935
964
  if (!normalizedPathname.startsWith('/session/')) {
936
965
  possiblePathnames.push(`/session/any-session-id${normalizedPathname}`);
937
966
  }
938
967
  possiblePathnames.push(normalizedPathname);
939
- const normalizedMethod = lodash_1.default.toUpper(method);
940
968
  for (const [routePath, routeSpec] of lodash_1.default.toPairs(exports.METHOD_MAP)) {
941
969
  const routeMatcher = (0, path_to_regexp_1.match)(routePath);
942
970
  if (possiblePathnames.some((pp) => routeMatcher(pp))) {
943
- const commandName = routeSpec?.[normalizedMethod]?.command;
971
+ const commandForAnyMethod = () => lodash_1.default.first((lodash_1.default.keys(routeSpec) ?? []).map((key) => routeSpec[key]?.command));
972
+ const commandName = normalizedMethod
973
+ ? routeSpec?.[normalizedMethod]?.command
974
+ : commandForAnyMethod();
944
975
  if (commandName) {
976
+ COMMAND_NAMES_CACHE.set(cacheKey, commandName);
945
977
  return commandName;
946
978
  }
947
979
  }
948
980
  }
981
+ // storing an empty string means we did not find any match for this set of arguments
982
+ // and we want to cache this result
983
+ COMMAND_NAMES_CACHE.set(cacheKey, '');
984
+ }
985
+ /**
986
+ *
987
+ * @param {string} endpoint
988
+ * @param {string} [method]
989
+ * @returns {string}
990
+ */
991
+ function toCommandNameCacheKey(endpoint, method) {
992
+ return `${endpoint}:${method ?? ''}`;
949
993
  }
950
994
  // driver commands that do not require a session to already exist
951
- exports.NO_SESSION_ID_COMMANDS = ['createSession', 'getStatus', 'getSessions'];
995
+ exports.NO_SESSION_ID_COMMANDS = ['createSession', 'getStatus', 'getSessions', 'getAppiumSessions'];
952
996
  //# sourceMappingURL=routes.js.map