@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.
Files changed (189) hide show
  1. package/build/lib/basedriver/capabilities.d.ts +1 -1
  2. package/build/lib/basedriver/capabilities.d.ts.map +1 -1
  3. package/build/lib/basedriver/capabilities.js +58 -50
  4. package/build/lib/basedriver/capabilities.js.map +1 -1
  5. package/build/lib/basedriver/commands/bidi.d.ts.map +1 -1
  6. package/build/lib/basedriver/commands/bidi.js +10 -14
  7. package/build/lib/basedriver/commands/bidi.js.map +1 -1
  8. package/build/lib/basedriver/commands/event.d.ts.map +1 -1
  9. package/build/lib/basedriver/commands/event.js +4 -7
  10. package/build/lib/basedriver/commands/event.js.map +1 -1
  11. package/build/lib/basedriver/commands/execute.js +3 -6
  12. package/build/lib/basedriver/commands/execute.js.map +1 -1
  13. package/build/lib/basedriver/commands/find.d.ts.map +1 -1
  14. package/build/lib/basedriver/commands/find.js +2 -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 -5
  18. package/build/lib/basedriver/commands/log.js.map +1 -1
  19. package/build/lib/basedriver/commands/timeout.d.ts.map +1 -1
  20. package/build/lib/basedriver/commands/timeout.js +9 -13
  21. package/build/lib/basedriver/commands/timeout.js.map +1 -1
  22. package/build/lib/basedriver/core.d.ts.map +1 -1
  23. package/build/lib/basedriver/core.js +17 -14
  24. package/build/lib/basedriver/core.js.map +1 -1
  25. package/build/lib/basedriver/device-settings.d.ts.map +1 -1
  26. package/build/lib/basedriver/device-settings.js +3 -7
  27. package/build/lib/basedriver/device-settings.js.map +1 -1
  28. package/build/lib/basedriver/driver.d.ts.map +1 -1
  29. package/build/lib/basedriver/driver.js +34 -38
  30. package/build/lib/basedriver/driver.js.map +1 -1
  31. package/build/lib/basedriver/extension-core.d.ts +4 -1
  32. package/build/lib/basedriver/extension-core.d.ts.map +1 -1
  33. package/build/lib/basedriver/extension-core.js +37 -13
  34. package/build/lib/basedriver/extension-core.js.map +1 -1
  35. package/build/lib/basedriver/helpers.d.ts.map +1 -1
  36. package/build/lib/basedriver/helpers.js +47 -33
  37. package/build/lib/basedriver/helpers.js.map +1 -1
  38. package/build/lib/basedriver/ipc.d.ts +36 -0
  39. package/build/lib/basedriver/ipc.d.ts.map +1 -0
  40. package/build/lib/basedriver/ipc.js +157 -0
  41. package/build/lib/basedriver/ipc.js.map +1 -0
  42. package/build/lib/basedriver/validation.d.ts.map +1 -1
  43. package/build/lib/basedriver/validation.js +27 -29
  44. package/build/lib/basedriver/validation.js.map +1 -1
  45. package/build/lib/express/express-logging.d.ts +0 -1
  46. package/build/lib/express/express-logging.d.ts.map +1 -1
  47. package/build/lib/express/express-logging.js +11 -11
  48. package/build/lib/express/express-logging.js.map +1 -1
  49. package/build/lib/express/idempotency.js +3 -6
  50. package/build/lib/express/idempotency.js.map +1 -1
  51. package/build/lib/express/middleware.d.ts.map +1 -1
  52. package/build/lib/express/middleware.js +6 -10
  53. package/build/lib/express/middleware.js.map +1 -1
  54. package/build/lib/express/server.d.ts +1 -1
  55. package/build/lib/express/server.d.ts.map +1 -1
  56. package/build/lib/express/server.js +82 -73
  57. package/build/lib/express/server.js.map +1 -1
  58. package/build/lib/express/websocket.d.ts.map +1 -1
  59. package/build/lib/express/websocket.js +6 -9
  60. package/build/lib/express/websocket.js.map +1 -1
  61. package/build/lib/helpers/capabilities.d.ts.map +1 -1
  62. package/build/lib/helpers/capabilities.js +14 -17
  63. package/build/lib/helpers/capabilities.js.map +1 -1
  64. package/build/lib/helpers/extension-command-name.js +2 -5
  65. package/build/lib/helpers/extension-command-name.js.map +1 -1
  66. package/build/lib/helpers/levenshtein-match.d.ts.map +1 -1
  67. package/build/lib/helpers/levenshtein-match.js +6 -7
  68. package/build/lib/helpers/levenshtein-match.js.map +1 -1
  69. package/build/lib/index.d.ts +2 -1
  70. package/build/lib/index.d.ts.map +1 -1
  71. package/build/lib/index.js +6 -16
  72. package/build/lib/index.js.map +1 -1
  73. package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
  74. package/build/lib/jsonwp-proxy/protocol-converter.js +21 -18
  75. package/build/lib/jsonwp-proxy/protocol-converter.js.map +1 -1
  76. package/build/lib/jsonwp-proxy/proxy-request.d.ts +2 -2
  77. package/build/lib/jsonwp-proxy/proxy-request.d.ts.map +1 -1
  78. package/build/lib/jsonwp-proxy/proxy-request.js +25 -21
  79. package/build/lib/jsonwp-proxy/proxy-request.js.map +1 -1
  80. package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
  81. package/build/lib/jsonwp-proxy/proxy.js +45 -36
  82. package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
  83. package/build/lib/protocol/errors.d.ts.map +1 -1
  84. package/build/lib/protocol/errors.js +33 -37
  85. package/build/lib/protocol/errors.js.map +1 -1
  86. package/build/lib/protocol/helpers.d.ts.map +1 -1
  87. package/build/lib/protocol/helpers.js +9 -8
  88. package/build/lib/protocol/helpers.js.map +1 -1
  89. package/build/lib/protocol/protocol.d.ts +1 -1
  90. package/build/lib/protocol/protocol.d.ts.map +1 -1
  91. package/build/lib/protocol/protocol.js +73 -61
  92. package/build/lib/protocol/protocol.js.map +1 -1
  93. package/build/lib/protocol/routes.d.ts +1 -1
  94. package/build/lib/protocol/routes.d.ts.map +1 -1
  95. package/build/lib/protocol/routes.js +16 -17
  96. package/build/lib/protocol/routes.js.map +1 -1
  97. package/build/lib/protocol/validators.d.ts.map +1 -1
  98. package/build/lib/protocol/validators.js +1 -5
  99. package/build/lib/protocol/validators.js.map +1 -1
  100. package/build/lib/test-pages/crash.d.ts.map +1 -0
  101. package/build/lib/test-pages/crash.js.map +1 -0
  102. package/build/lib/test-pages/env.d.ts +5 -0
  103. package/build/lib/test-pages/env.d.ts.map +1 -0
  104. package/build/lib/test-pages/env.js +12 -0
  105. package/build/lib/test-pages/env.js.map +1 -0
  106. package/build/lib/{express/static.d.ts → test-pages/handlers.d.ts} +1 -2
  107. package/build/lib/test-pages/handlers.d.ts.map +1 -0
  108. package/build/lib/{express/static.js → test-pages/handlers.js} +9 -12
  109. package/build/lib/test-pages/handlers.js.map +1 -0
  110. package/build/lib/test-pages/index.d.ts +6 -0
  111. package/build/lib/test-pages/index.d.ts.map +1 -0
  112. package/build/lib/test-pages/index.js +35 -0
  113. package/build/lib/test-pages/index.js.map +1 -0
  114. package/build/lib/test-pages/static-dir.d.ts +8 -0
  115. package/build/lib/test-pages/static-dir.d.ts.map +1 -0
  116. package/build/lib/test-pages/static-dir.js +24 -0
  117. package/build/lib/test-pages/static-dir.js.map +1 -0
  118. package/build/lib/test-pages/template.d.ts +3 -0
  119. package/build/lib/test-pages/template.d.ts.map +1 -0
  120. package/build/lib/test-pages/template.js +19 -0
  121. package/build/lib/test-pages/template.js.map +1 -0
  122. package/build/lib/utils.d.ts +14 -0
  123. package/build/lib/utils.d.ts.map +1 -0
  124. package/build/lib/utils.js +55 -0
  125. package/build/lib/utils.js.map +1 -0
  126. package/lib/basedriver/capabilities.ts +126 -115
  127. package/lib/basedriver/commands/bidi.ts +11 -11
  128. package/lib/basedriver/commands/event.ts +17 -11
  129. package/lib/basedriver/commands/execute.ts +15 -12
  130. package/lib/basedriver/commands/find.ts +20 -12
  131. package/lib/basedriver/commands/log.ts +4 -3
  132. package/lib/basedriver/commands/timeout.ts +22 -14
  133. package/lib/basedriver/core.ts +26 -26
  134. package/lib/basedriver/device-settings.ts +7 -12
  135. package/lib/basedriver/driver.ts +62 -50
  136. package/lib/basedriver/extension-core.ts +60 -18
  137. package/lib/basedriver/helpers.ts +81 -52
  138. package/lib/basedriver/ipc.ts +198 -0
  139. package/lib/basedriver/validation.ts +37 -30
  140. package/lib/express/express-logging.ts +16 -20
  141. package/lib/express/idempotency.ts +9 -9
  142. package/lib/express/middleware.ts +14 -18
  143. package/lib/express/server.ts +118 -120
  144. package/lib/express/websocket.ts +11 -15
  145. package/lib/helpers/capabilities.ts +21 -16
  146. package/lib/helpers/extension-command-name.ts +3 -3
  147. package/lib/helpers/levenshtein-match.ts +20 -14
  148. package/lib/index.js +3 -12
  149. package/lib/jsonwp-proxy/protocol-converter.ts +58 -35
  150. package/lib/jsonwp-proxy/proxy-request.ts +26 -26
  151. package/lib/jsonwp-proxy/proxy.ts +74 -75
  152. package/lib/protocol/errors.ts +69 -88
  153. package/lib/protocol/helpers.ts +9 -5
  154. package/lib/protocol/protocol.ts +149 -107
  155. package/lib/protocol/routes.ts +17 -17
  156. package/lib/protocol/validators.ts +1 -3
  157. package/lib/test-pages/env.ts +9 -0
  158. package/lib/{express/static.ts → test-pages/handlers.ts} +10 -22
  159. package/lib/test-pages/index.ts +34 -0
  160. package/lib/test-pages/static-dir.ts +19 -0
  161. package/lib/test-pages/template.ts +17 -0
  162. package/lib/utils.ts +65 -0
  163. package/package.json +10 -13
  164. package/tsconfig.json +1 -0
  165. package/build/lib/express/crash.d.ts.map +0 -1
  166. package/build/lib/express/crash.js.map +0 -1
  167. package/build/lib/express/static.d.ts.map +0 -1
  168. package/build/lib/express/static.js.map +0 -1
  169. /package/build/lib/{express → test-pages}/crash.d.ts +0 -0
  170. /package/build/lib/{express → test-pages}/crash.js +0 -0
  171. /package/lib/{express → test-pages}/crash.ts +0 -0
  172. /package/{static → test-fixtures/static}/appium.png +0 -0
  173. /package/{static → test-fixtures/static}/favicon.ico +0 -0
  174. /package/{static → test-fixtures/static}/js/jquery.min.js +0 -0
  175. /package/{static → test-fixtures/static}/test/frameset.html +0 -0
  176. /package/{static → test-fixtures/static}/test/guinea-pig-app-banner.html +0 -0
  177. /package/{static → test-fixtures/static}/test/guinea-pig-scrollable.html +0 -0
  178. /package/{static → test-fixtures/static}/test/guinea-pig.html +0 -0
  179. /package/{static → test-fixtures/static}/test/guinea-pig2.html +0 -0
  180. /package/{static → test-fixtures/static}/test/guinea-pig3.html +0 -0
  181. /package/{static → test-fixtures/static}/test/guinea-pig4.html +0 -0
  182. /package/{static → test-fixtures/static}/test/guinea-pig5.html +0 -0
  183. /package/{static → test-fixtures/static}/test/iframes.html +0 -0
  184. /package/{static → test-fixtures/static}/test/shadow-dom.html +0 -0
  185. /package/{static → test-fixtures/static}/test/subframe1.html +0 -0
  186. /package/{static → test-fixtures/static}/test/subframe2.html +0 -0
  187. /package/{static → test-fixtures/static}/test/subframe3.html +0 -0
  188. /package/{static → test-fixtures/static}/test/touch.html +0 -0
  189. /package/{static → test-fixtures/static}/test/welcome.html +0 -0
@@ -5,7 +5,6 @@ import type {BaseDriver} from '../driver';
5
5
  import {mixin} from './mixin';
6
6
 
7
7
  declare module '../driver' {
8
-
9
8
  interface BaseDriver<C extends Constraints> extends IFindCommands {}
10
9
  }
11
10
 
@@ -14,21 +13,21 @@ async function findElOrEls<C extends Constraints>(
14
13
  strategy: string,
15
14
  selector: string,
16
15
  mult: true,
17
- context?: any
16
+ context?: any,
18
17
  ): Promise<Element[]>;
19
18
  async function findElOrEls<C extends Constraints>(
20
19
  this: BaseDriver<C>,
21
20
  strategy: string,
22
21
  selector: string,
23
22
  mult: false,
24
- context?: any
23
+ context?: any,
25
24
  ): Promise<Element>;
26
25
  async function findElOrEls<C extends Constraints>(
27
26
  this: BaseDriver<C>,
28
27
  strategy: string,
29
28
  selector: string,
30
29
  mult: boolean,
31
- context?: any
30
+ context?: any,
32
31
  ): Promise<Element[] | Element> {
33
32
  throw new errors.NotImplementedError('Not implemented yet for find.');
34
33
  }
@@ -38,21 +37,21 @@ async function findElOrElsWithProcessing<C extends Constraints>(
38
37
  strategy: string,
39
38
  selector: string,
40
39
  mult: true,
41
- context?: any
40
+ context?: any,
42
41
  ): Promise<Element[]>;
43
42
  async function findElOrElsWithProcessing<C extends Constraints>(
44
43
  this: BaseDriver<C>,
45
44
  strategy: string,
46
45
  selector: string,
47
46
  mult: false,
48
- context?: any
47
+ context?: any,
49
48
  ): Promise<Element>;
50
49
  async function findElOrElsWithProcessing<C extends Constraints>(
51
50
  this: BaseDriver<C>,
52
51
  strategy: string,
53
52
  selector: string,
54
53
  mult: boolean,
55
- context?: any
54
+ context?: any,
56
55
  ): Promise<Element[] | Element> {
57
56
  this.validateLocatorStrategy(strategy);
58
57
  try {
@@ -61,7 +60,8 @@ async function findElOrElsWithProcessing<C extends Constraints>(
61
60
  } catch (err) {
62
61
  if (this.opts.printPageSourceOnFindFailure) {
63
62
  const src = await this.getPageSource();
64
- this.log.debug(`Error finding element${mult ? 's' : ''}: ${err.message}`);
63
+ const message = err instanceof Error ? err.message : String(err);
64
+ this.log.debug(`Error finding element${mult ? 's' : ''}: ${message}`);
65
65
  this.log.debug(`Page source requested through 'printPageSourceOnFindFailure':`);
66
66
  this.log.debug(src);
67
67
  }
@@ -71,11 +71,19 @@ async function findElOrElsWithProcessing<C extends Constraints>(
71
71
  }
72
72
 
73
73
  const FindCommands: IFindCommands = {
74
- async findElement<C extends Constraints>(this: BaseDriver<C>, strategy, selector) {
74
+ async findElement<C extends Constraints>(
75
+ this: BaseDriver<C>,
76
+ strategy: string,
77
+ selector: string,
78
+ ) {
75
79
  return await this.findElOrElsWithProcessing(strategy, selector, false);
76
80
  },
77
81
 
78
- async findElements<C extends Constraints>(this: BaseDriver<C>, strategy, selector) {
82
+ async findElements<C extends Constraints>(
83
+ this: BaseDriver<C>,
84
+ strategy: string,
85
+ selector: string,
86
+ ) {
79
87
  return await this.findElOrElsWithProcessing(strategy, selector, true);
80
88
  },
81
89
 
@@ -83,7 +91,7 @@ const FindCommands: IFindCommands = {
83
91
  this: BaseDriver<C>,
84
92
  strategy: string,
85
93
  selector: string,
86
- elementId: string
94
+ elementId: string,
87
95
  ) {
88
96
  return await this.findElOrElsWithProcessing(strategy, selector, false, elementId);
89
97
  },
@@ -92,7 +100,7 @@ const FindCommands: IFindCommands = {
92
100
  this: BaseDriver<C>,
93
101
  strategy: string,
94
102
  selector: string,
95
- elementId: string
103
+ elementId: string,
96
104
  ) {
97
105
  return await this.findElOrElsWithProcessing(strategy, selector, true, elementId);
98
106
  },
@@ -1,5 +1,4 @@
1
1
  import type {Constraints, Driver, ILogCommands} from '@appium/types';
2
- import _ from 'lodash';
3
2
  import type {BaseDriver} from '../driver';
4
3
  import {mixin} from './mixin';
5
4
 
@@ -20,10 +19,12 @@ const LogCommands: ILogCommands = {
20
19
  this.log.debug(`Retrieving '${String(logType)}' logs`);
21
20
 
22
21
  if (!(logType in this.supportedLogTypes)) {
23
- const logsTypesWithDescriptions = _.mapValues(this.supportedLogTypes, 'description');
22
+ const logsTypesWithDescriptions = Object.fromEntries(
23
+ Object.entries(this.supportedLogTypes).map(([key, value]) => [key, value.description]),
24
+ );
24
25
  throw new Error(
25
26
  `Unsupported log type '${String(logType)}'. ` +
26
- `Supported types: ${JSON.stringify(logsTypesWithDescriptions)}`
27
+ `Supported types: ${JSON.stringify(logsTypesWithDescriptions)}`,
27
28
  );
28
29
  }
29
30
 
@@ -1,5 +1,4 @@
1
1
  import {waitForCondition} from 'asyncbox';
2
- import _ from 'lodash';
3
2
  import {util} from '@appium/support';
4
3
  import {errors} from '../../protocol';
5
4
  import type {BaseDriver} from '../driver';
@@ -14,27 +13,36 @@ declare module '../driver' {
14
13
  const MIN_TIMEOUT = 0;
15
14
 
16
15
  const TimeoutCommands: ITimeoutCommands = {
17
- async timeouts<C extends Constraints>(this: BaseDriver<C>, type, ms, script, pageLoad, implicit) {
18
- if (type && _.isString(type) && util.hasValue(ms)) {
16
+ async timeouts<C extends Constraints>(
17
+ this: BaseDriver<C>,
18
+ type?: string,
19
+ ms?: number | string,
20
+ script?: number,
21
+ pageLoad?: number,
22
+ implicit?: number,
23
+ ) {
24
+ if (type && typeof type === 'string' && util.hasValue(ms)) {
19
25
  // legacy stuff with some Appium-specific additions
20
26
  this.log.debug(`Timeout arguments: ${JSON.stringify({type, ms})}}`);
21
27
  switch (type) {
22
28
  case 'command':
23
- return void (await this.newCommandTimeout(ms));
29
+ return void (await this.newCommandTimeout(this.parseTimeoutArgument(ms)));
24
30
  case 'implicit':
25
- return void (await this.implicitWaitW3C(ms));
31
+ return void (await this.implicitWaitW3C(this.parseTimeoutArgument(ms)));
26
32
  case 'page load':
27
- return void (await this.pageLoadTimeoutW3C(ms));
33
+ return void (await this.pageLoadTimeoutW3C(this.parseTimeoutArgument(ms)));
28
34
  case 'script':
29
- return void (await this.scriptTimeoutW3C(ms));
35
+ return void (await this.scriptTimeoutW3C(this.parseTimeoutArgument(ms)));
30
36
  default:
31
37
  throw new Error(`'${type}' type is not supported for the timeout API`);
32
38
  }
33
39
  }
34
40
 
35
41
  this.log.debug(`W3C timeout argument: ${JSON.stringify({script, pageLoad, implicit})}}`);
36
- if ([script, pageLoad, implicit].every(_.isNil)) {
37
- throw new errors.InvalidArgumentError('W3C protocol expects any of script, pageLoad or implicit to be set');
42
+ if ([script, pageLoad, implicit].every((value) => value == null)) {
43
+ throw new errors.InvalidArgumentError(
44
+ 'W3C protocol expects any of script, pageLoad or implicit to be set',
45
+ );
38
46
  }
39
47
  if (util.hasValue(script)) {
40
48
  await this.scriptTimeoutW3C(script);
@@ -47,7 +55,7 @@ const TimeoutCommands: ITimeoutCommands = {
47
55
  }
48
56
  },
49
57
 
50
- async getTimeouts() {
58
+ async getTimeouts<C extends Constraints>(this: BaseDriver<C>) {
51
59
  return {
52
60
  command: this.newCommandTimeoutMs,
53
61
  implicit: this.implicitWaitMs,
@@ -82,7 +90,7 @@ const TimeoutCommands: ITimeoutCommands = {
82
90
  if (this.managedDrivers?.length) {
83
91
  this.log.debug('Setting implicit wait on managed drivers');
84
92
  for (const driver of this.managedDrivers) {
85
- if (_.isFunction(driver.setImplicitWait)) {
93
+ if (typeof driver.setImplicitWait === 'function') {
86
94
  driver.setImplicitWait(ms);
87
95
  }
88
96
  }
@@ -95,7 +103,7 @@ const TimeoutCommands: ITimeoutCommands = {
95
103
  if (this.managedDrivers?.length) {
96
104
  this.log.debug('Setting new command timeout on managed drivers');
97
105
  for (const driver of this.managedDrivers) {
98
- if (_.isFunction(driver.setNewCommandTimeout)) {
106
+ if (typeof driver.setNewCommandTimeout === 'function') {
99
107
  driver.setNewCommandTimeout(ms);
100
108
  }
101
109
  }
@@ -104,7 +112,7 @@ const TimeoutCommands: ITimeoutCommands = {
104
112
 
105
113
  async implicitWaitForCondition<C extends Constraints>(
106
114
  this: BaseDriver<C>,
107
- condFn: (...args: any[]) => Promise<any>
115
+ condFn: (...args: any[]) => Promise<any>,
108
116
  ) {
109
117
  this.log.debug(`Waiting up to ${this.implicitWaitMs} ms for condition`);
110
118
  const wrappedCondFn = async (...args: any[]) => {
@@ -122,7 +130,7 @@ const TimeoutCommands: ITimeoutCommands = {
122
130
 
123
131
  parseTimeoutArgument<C extends Constraints>(this: BaseDriver<C>, ms: number | string) {
124
132
  const duration = parseInt(String(ms), 10);
125
- if (_.isNaN(duration) || duration < MIN_TIMEOUT) {
133
+ if (Number.isNaN(duration) || duration < MIN_TIMEOUT) {
126
134
  throw new errors.UnknownError(`Invalid timeout value '${ms}'`);
127
135
  }
128
136
  return duration;
@@ -12,12 +12,9 @@ import type {
12
12
  StringRecord,
13
13
  } from '@appium/types';
14
14
  import AsyncLock from 'async-lock';
15
- import _ from 'lodash';
15
+ import {util} from '@appium/support';
16
16
  import os from 'node:os';
17
- import {
18
- DEFAULT_BASE_PATH,
19
- PROTOCOLS,
20
- } from '../constants';
17
+ import {DEFAULT_BASE_PATH, PROTOCOLS} from '../constants';
21
18
  import {errors} from '../protocol';
22
19
  import {DeviceSettings} from './device-settings';
23
20
  import * as helpers from './helpers';
@@ -31,7 +28,8 @@ const ALL_DRIVERS_MATCH = '*';
31
28
  const FEATURE_NAME_SEPARATOR = ':';
32
29
 
33
30
  export class DriverCore<const C extends Constraints, Settings extends StringRecord = StringRecord>
34
- extends ExtensionCore implements Core<C, Settings>
31
+ extends ExtensionCore
32
+ implements Core<C, Settings>
35
33
  {
36
34
  /**
37
35
  * Make the basedriver version available so for any driver which inherits from this package, we
@@ -41,7 +39,7 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
41
39
 
42
40
  sessionId: string | null;
43
41
 
44
- sessionCreationTimestampMs: number;
42
+ sessionCreationTimestampMs!: number;
45
43
 
46
44
  opts: DriverOpts<C>;
47
45
 
@@ -104,7 +102,6 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
104
102
  super();
105
103
  this._log = this.log; // TODO: remove references to this._log and use this.log instead
106
104
 
107
-
108
105
  // setup state
109
106
  this.opts = opts as DriverOpts<C>;
110
107
 
@@ -116,7 +113,7 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
116
113
  this.shouldValidateCaps = shouldValidateCaps;
117
114
 
118
115
  // keeping track of initial opts
119
- this.initialOpts = _.cloneDeep(opts);
116
+ this.initialOpts = structuredClone(opts);
120
117
 
121
118
  this.sessionId = null;
122
119
  this.helpers = helpers;
@@ -166,7 +163,7 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
166
163
  * inadvertently change data outside of logEvent
167
164
  */
168
165
  get eventHistory() {
169
- return _.cloneDeep(this._eventHistory);
166
+ return structuredClone(this._eventHistory);
170
167
  }
171
168
 
172
169
  /**
@@ -263,7 +260,7 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
263
260
  isFeatureEnabled(name: string): boolean {
264
261
  // automationName comparison is case-insensitive,
265
262
  // while feature name is case-sensitive
266
- const currentAutomationName = _.toLower(this.opts.automationName);
263
+ const currentAutomationName = String(this.opts.automationName).toLowerCase();
267
264
 
268
265
  const parseFullName = (fullName: string) => {
269
266
  const separatorPos = fullName.indexOf(FEATURE_NAME_SEPARATOR);
@@ -273,27 +270,31 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
273
270
  // but better be safe than sorry
274
271
  throw new Error(
275
272
  `The full feature name must include both the automation name ` +
276
- `'${this.opts.automationName}' or the '${ALL_DRIVERS_MATCH}' ` +
277
- `wildcard to apply the feature to all installed drivers, and ` +
278
- `the feature name split by a colon. Got '${fullName}' instead`
273
+ `'${this.opts.automationName}' or the '${ALL_DRIVERS_MATCH}' ` +
274
+ `wildcard to apply the feature to all installed drivers, and ` +
275
+ `the feature name split by a colon. Got '${fullName}' instead`,
279
276
  );
280
277
  }
281
278
  return [
282
- _.toLower(fullName.substring(0, separatorPos)),
283
- fullName.substring(separatorPos + 1)
279
+ fullName.substring(0, separatorPos).toLowerCase(),
280
+ fullName.substring(separatorPos + 1),
284
281
  ];
285
282
  };
286
283
  const parseFullNames = (fullNames: string[]) => fullNames.map(parseFullName);
287
- const matches = ([automationName, featureName]: [string, string]) =>
288
- [currentAutomationName, ALL_DRIVERS_MATCH].includes(automationName) && featureName === name;
284
+ const matches = (pair: string[]) => {
285
+ const [automationName, featureName] = pair;
286
+ return (
287
+ [currentAutomationName, ALL_DRIVERS_MATCH].includes(automationName) && featureName === name
288
+ );
289
+ };
289
290
 
290
291
  // if we have explicitly denied this feature, return false immediately
291
- if (!_.isEmpty(this.denyInsecure) && parseFullNames(this.denyInsecure).some(matches)) {
292
+ if (!util.isEmpty(this.denyInsecure) && parseFullNames(this.denyInsecure).some(matches)) {
292
293
  return false;
293
294
  }
294
295
 
295
296
  // if we specifically have allowed the feature, return true
296
- if (!_.isEmpty(this.allowInsecure) && parseFullNames(this.allowInsecure).some(matches)) {
297
+ if (!util.isEmpty(this.allowInsecure) && parseFullNames(this.allowInsecure).some(matches)) {
297
298
  return true;
298
299
  }
299
300
 
@@ -332,7 +333,7 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
332
333
  validStrategies = validStrategies.concat(this.webLocatorStrategies);
333
334
  }
334
335
 
335
- if (!_.includes(validStrategies, strategy)) {
336
+ if (!validStrategies.includes(strategy)) {
336
337
  throw new errors.InvalidSelectorError(
337
338
  `Locator Strategy '${strategy}' is not supported for this session`,
338
339
  );
@@ -370,17 +371,17 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
370
371
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
371
372
  proxyRouteIsAvoided(sessionId: string, method: HTTPMethod, url: string, body?: any): boolean {
372
373
  for (const avoidSchema of this.getProxyAvoidList(sessionId)) {
373
- if (!_.isArray(avoidSchema) || avoidSchema.length !== 2) {
374
+ if (!Array.isArray(avoidSchema) || avoidSchema.length !== 2) {
374
375
  throw new Error('Proxy avoidance must be a list of pairs');
375
376
  }
376
377
  const [avoidMethod, avoidPathRegex] = avoidSchema;
377
- if (!_.includes(['GET', 'POST', 'DELETE'], avoidMethod)) {
378
+ if (!['GET', 'POST', 'DELETE'].includes(avoidMethod)) {
378
379
  throw new Error(`Unrecognized proxy avoidance method '${avoidMethod}'`);
379
380
  }
380
- if (!_.isRegExp(avoidPathRegex)) {
381
+ if (!(avoidPathRegex instanceof RegExp)) {
381
382
  throw new Error('Proxy avoidance path must be a regular expression');
382
383
  }
383
- const normalizedUrl = url.replace(new RegExp(`^${_.escapeRegExp(this.basePath)}`), '');
384
+ const normalizedUrl = url.replace(new RegExp(`^${util.escapeRegExp(this.basePath)}`), '');
384
385
  if (avoidMethod === method && avoidPathRegex.test(normalizedUrl)) {
385
386
  return true;
386
387
  }
@@ -406,5 +407,4 @@ export class DriverCore<const C extends Constraints, Settings extends StringReco
406
407
  this.noCommandTimer = null;
407
408
  }
408
409
  }
409
-
410
410
  }
@@ -1,6 +1,5 @@
1
- import _ from 'lodash';
1
+ import {util, node} from '@appium/support';
2
2
  import {log} from './logger';
3
- import {node, util} from '@appium/support';
4
3
  import {errors} from '../protocol/errors';
5
4
  import type {StringRecord, IDeviceSettings, SettingsUpdateListener} from '@appium/types';
6
5
 
@@ -24,7 +23,7 @@ export class DeviceSettings<T extends StringRecord = StringRecord> implements ID
24
23
  */
25
24
  constructor(
26
25
  defaultSettings: T = {} as T,
27
- onSettingsUpdate: SettingsUpdateListener<T> = async () => {}
26
+ onSettingsUpdate: SettingsUpdateListener<T> = async () => {},
28
27
  ) {
29
28
  this._settings = {...defaultSettings};
30
29
  this._onSettingsUpdate = onSettingsUpdate;
@@ -36,32 +35,28 @@ export class DeviceSettings<T extends StringRecord = StringRecord> implements ID
36
35
  * @param newSettings - New settings to merge (must be plain object; total size remains bounded).
37
36
  */
38
37
  async update(newSettings: T): Promise<void> {
39
- if (!_.isPlainObject(newSettings)) {
38
+ if (!util.isPlainObject(newSettings)) {
40
39
  throw new errors.InvalidArgumentError(
41
40
  `Settings update should be called with valid JSON. Got ` +
42
- `${JSON.stringify(newSettings)} instead`
41
+ `${JSON.stringify(newSettings)} instead`,
43
42
  );
44
43
  }
45
44
 
46
45
  if (node.getObjectSize({...this._settings, ...newSettings}) >= MAX_SETTINGS_SIZE) {
47
46
  throw new errors.InvalidArgumentError(
48
47
  `New settings cannot be applied, because the overall ` +
49
- `object size exceeds the allowed limit of ${util.toReadableSizeString(MAX_SETTINGS_SIZE)}`
48
+ `object size exceeds the allowed limit of ${util.toReadableSizeString(MAX_SETTINGS_SIZE)}`,
50
49
  );
51
50
  }
52
51
 
53
52
  for (const prop in newSettings) {
54
- if (!_.isUndefined(this._settings[prop])) {
53
+ if (this._settings[prop] !== undefined) {
55
54
  if (this._settings[prop] === newSettings[prop]) {
56
55
  log.debug(`The value of '${prop}' setting did not change. Skipping the update for it`);
57
56
  continue;
58
57
  }
59
58
  }
60
- await this._onSettingsUpdate(
61
- prop as keyof T,
62
- newSettings[prop],
63
- this._settings[prop]
64
- );
59
+ await this._onSettingsUpdate(prop as keyof T, newSettings[prop], this._settings[prop]);
65
60
  this._settings[prop] = newSettings[prop];
66
61
  }
67
62
  }