appium-xcuitest-driver 10.8.3 → 10.9.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 (218) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/lib/app-utils.d.ts +2 -2
  3. package/build/lib/app-utils.d.ts.map +1 -1
  4. package/build/lib/app-utils.js +4 -1
  5. package/build/lib/app-utils.js.map +1 -1
  6. package/build/lib/commands/app-management.js +2 -2
  7. package/build/lib/commands/app-management.js.map +1 -1
  8. package/build/lib/commands/appearance.js +2 -2
  9. package/build/lib/commands/appearance.js.map +1 -1
  10. package/build/lib/commands/biometric.js +3 -3
  11. package/build/lib/commands/biometric.js.map +1 -1
  12. package/build/lib/commands/certificate.d.ts.map +1 -1
  13. package/build/lib/commands/certificate.js +9 -3
  14. package/build/lib/commands/certificate.js.map +1 -1
  15. package/build/lib/commands/context.d.ts +5 -5
  16. package/build/lib/commands/context.d.ts.map +1 -1
  17. package/build/lib/commands/context.js +6 -6
  18. package/build/lib/commands/context.js.map +1 -1
  19. package/build/lib/commands/file-movement.d.ts.map +1 -1
  20. package/build/lib/commands/file-movement.js +7 -7
  21. package/build/lib/commands/file-movement.js.map +1 -1
  22. package/build/lib/commands/general.js +1 -1
  23. package/build/lib/commands/general.js.map +1 -1
  24. package/build/lib/commands/gesture.js +1 -1
  25. package/build/lib/commands/gesture.js.map +1 -1
  26. package/build/lib/commands/keychains.js +1 -1
  27. package/build/lib/commands/keychains.js.map +1 -1
  28. package/build/lib/commands/localization.js +1 -1
  29. package/build/lib/commands/localization.js.map +1 -1
  30. package/build/lib/commands/location.js +1 -1
  31. package/build/lib/commands/location.js.map +1 -1
  32. package/build/lib/commands/log.js +7 -7
  33. package/build/lib/commands/log.js.map +1 -1
  34. package/build/lib/commands/memory.js +1 -1
  35. package/build/lib/commands/memory.js.map +1 -1
  36. package/build/lib/commands/notifications.js +1 -1
  37. package/build/lib/commands/notifications.js.map +1 -1
  38. package/build/lib/commands/pasteboard.js +2 -2
  39. package/build/lib/commands/pasteboard.js.map +1 -1
  40. package/build/lib/commands/pcap.js +1 -1
  41. package/build/lib/commands/pcap.js.map +1 -1
  42. package/build/lib/commands/performance.d.ts.map +1 -1
  43. package/build/lib/commands/performance.js +13 -4
  44. package/build/lib/commands/performance.js.map +1 -1
  45. package/build/lib/commands/permissions.js +2 -2
  46. package/build/lib/commands/permissions.js.map +1 -1
  47. package/build/lib/commands/proxy-helper.d.ts.map +1 -1
  48. package/build/lib/commands/proxy-helper.js +0 -3
  49. package/build/lib/commands/proxy-helper.js.map +1 -1
  50. package/build/lib/commands/screenshots.js +1 -1
  51. package/build/lib/commands/screenshots.js.map +1 -1
  52. package/build/lib/commands/simctl.d.ts +1 -1
  53. package/build/lib/commands/simctl.d.ts.map +1 -1
  54. package/build/lib/commands/simctl.js +1 -1
  55. package/build/lib/commands/simctl.js.map +1 -1
  56. package/build/lib/commands/web.js +1 -1
  57. package/build/lib/commands/web.js.map +1 -1
  58. package/build/lib/commands/xctest-record-screen.js +2 -2
  59. package/build/lib/commands/xctest-record-screen.js.map +1 -1
  60. package/build/lib/desired-caps.d.ts +383 -507
  61. package/build/lib/desired-caps.d.ts.map +1 -1
  62. package/build/lib/desired-caps.js +6 -10
  63. package/build/lib/desired-caps.js.map +1 -1
  64. package/build/lib/device/clients/base-device-client.d.ts.map +1 -0
  65. package/build/lib/device/clients/base-device-client.js.map +1 -0
  66. package/build/lib/{real-device-clients → device/clients}/py-ios-device-client.d.ts +1 -1
  67. package/build/lib/device/clients/py-ios-device-client.d.ts.map +1 -0
  68. package/build/lib/device/clients/py-ios-device-client.js.map +1 -0
  69. package/build/lib/device/device-connections-factory.d.ts +18 -0
  70. package/build/lib/device/device-connections-factory.d.ts.map +1 -0
  71. package/build/lib/{device-connections-factory.js → device/device-connections-factory.js} +57 -41
  72. package/build/lib/device/device-connections-factory.js.map +1 -0
  73. package/build/lib/{device-log → device/log}/helpers.d.ts +1 -1
  74. package/build/lib/device/log/helpers.d.ts.map +1 -0
  75. package/build/lib/device/log/helpers.js.map +1 -0
  76. package/build/lib/{device-log → device/log}/ios-crash-log.d.ts +1 -1
  77. package/build/lib/device/log/ios-crash-log.d.ts.map +1 -0
  78. package/build/lib/{device-log → device/log}/ios-crash-log.js +1 -1
  79. package/build/lib/device/log/ios-crash-log.js.map +1 -0
  80. package/build/lib/device/log/ios-device-log.d.ts.map +1 -0
  81. package/build/lib/device/log/ios-device-log.js.map +1 -0
  82. package/build/lib/{device-log → device/log}/ios-log.d.ts +1 -1
  83. package/build/lib/device/log/ios-log.d.ts.map +1 -0
  84. package/build/lib/device/log/ios-log.js.map +1 -0
  85. package/build/lib/device/log/ios-performance-log.d.ts.map +1 -0
  86. package/build/lib/device/log/ios-performance-log.js.map +1 -0
  87. package/build/lib/device/log/ios-simulator-log.d.ts.map +1 -0
  88. package/build/lib/device/log/ios-simulator-log.js.map +1 -0
  89. package/build/lib/{device-log → device/log}/line-consuming-log.d.ts +1 -1
  90. package/build/lib/device/log/line-consuming-log.d.ts.map +1 -0
  91. package/build/lib/device/log/line-consuming-log.js.map +1 -0
  92. package/build/lib/{device-log → device/log}/safari-console-log.d.ts +1 -1
  93. package/build/lib/device/log/safari-console-log.d.ts.map +1 -0
  94. package/build/lib/device/log/safari-console-log.js.map +1 -0
  95. package/build/lib/device/log/safari-network-log.d.ts.map +1 -0
  96. package/build/lib/device/log/safari-network-log.js.map +1 -0
  97. package/build/lib/device/real-device-management.d.ts +146 -0
  98. package/build/lib/device/real-device-management.d.ts.map +1 -0
  99. package/build/lib/device/real-device-management.js +728 -0
  100. package/build/lib/device/real-device-management.js.map +1 -0
  101. package/build/lib/device/simulator-management.d.ts +65 -0
  102. package/build/lib/device/simulator-management.d.ts.map +1 -0
  103. package/build/lib/{simulator-management.js → device/simulator-management.js} +24 -43
  104. package/build/lib/device/simulator-management.js.map +1 -0
  105. package/build/lib/driver.d.ts +129 -1385
  106. package/build/lib/driver.d.ts.map +1 -1
  107. package/build/lib/driver.js +476 -600
  108. package/build/lib/driver.js.map +1 -1
  109. package/build/lib/method-map.d.ts +1 -1
  110. package/build/lib/method-map.d.ts.map +1 -1
  111. package/build/lib/method-map.js +2 -2
  112. package/build/lib/method-map.js.map +1 -1
  113. package/lib/app-utils.js +5 -1
  114. package/lib/commands/app-management.js +2 -2
  115. package/lib/commands/appearance.js +2 -2
  116. package/lib/commands/biometric.js +3 -3
  117. package/lib/commands/certificate.js +9 -3
  118. package/lib/commands/context.js +6 -6
  119. package/lib/commands/file-movement.js +11 -7
  120. package/lib/commands/general.js +1 -1
  121. package/lib/commands/gesture.js +1 -1
  122. package/lib/commands/keychains.js +1 -1
  123. package/lib/commands/localization.js +1 -1
  124. package/lib/commands/location.js +1 -1
  125. package/lib/commands/log.js +7 -7
  126. package/lib/commands/memory.js +1 -1
  127. package/lib/commands/notifications.js +1 -1
  128. package/lib/commands/pasteboard.js +2 -2
  129. package/lib/commands/pcap.js +1 -1
  130. package/lib/commands/performance.js +12 -1
  131. package/lib/commands/permissions.js +2 -2
  132. package/lib/commands/proxy-helper.js +0 -3
  133. package/lib/commands/screenshots.js +1 -1
  134. package/lib/commands/simctl.js +1 -1
  135. package/lib/commands/web.js +1 -1
  136. package/lib/commands/xctest-record-screen.js +2 -2
  137. package/lib/{desired-caps.js → desired-caps.ts} +7 -6
  138. package/lib/{real-device-clients → device/clients}/py-ios-device-client.ts +1 -1
  139. package/lib/{device-connections-factory.js → device/device-connections-factory.ts} +96 -60
  140. package/lib/{device-log → device/log}/helpers.ts +1 -1
  141. package/lib/{device-log → device/log}/ios-crash-log.ts +3 -3
  142. package/lib/{device-log → device/log}/ios-log.ts +1 -1
  143. package/lib/{device-log → device/log}/line-consuming-log.ts +1 -1
  144. package/lib/{device-log → device/log}/safari-console-log.ts +1 -1
  145. package/lib/device/real-device-management.ts +819 -0
  146. package/lib/{simulator-management.js → device/simulator-management.ts} +69 -62
  147. package/lib/{driver.js → driver.ts} +619 -713
  148. package/lib/{method-map.js → method-map.ts} +5 -2
  149. package/npm-shrinkwrap.json +5 -5
  150. package/package.json +1 -1
  151. package/build/lib/device-connections-factory.d.ts +0 -13
  152. package/build/lib/device-connections-factory.d.ts.map +0 -1
  153. package/build/lib/device-connections-factory.js.map +0 -1
  154. package/build/lib/device-log/helpers.d.ts.map +0 -1
  155. package/build/lib/device-log/helpers.js.map +0 -1
  156. package/build/lib/device-log/ios-crash-log.d.ts.map +0 -1
  157. package/build/lib/device-log/ios-crash-log.js.map +0 -1
  158. package/build/lib/device-log/ios-device-log.d.ts.map +0 -1
  159. package/build/lib/device-log/ios-device-log.js.map +0 -1
  160. package/build/lib/device-log/ios-log.d.ts.map +0 -1
  161. package/build/lib/device-log/ios-log.js.map +0 -1
  162. package/build/lib/device-log/ios-performance-log.d.ts.map +0 -1
  163. package/build/lib/device-log/ios-performance-log.js.map +0 -1
  164. package/build/lib/device-log/ios-simulator-log.d.ts.map +0 -1
  165. package/build/lib/device-log/ios-simulator-log.js.map +0 -1
  166. package/build/lib/device-log/line-consuming-log.d.ts.map +0 -1
  167. package/build/lib/device-log/line-consuming-log.js.map +0 -1
  168. package/build/lib/device-log/safari-console-log.d.ts.map +0 -1
  169. package/build/lib/device-log/safari-console-log.js.map +0 -1
  170. package/build/lib/device-log/safari-network-log.d.ts.map +0 -1
  171. package/build/lib/device-log/safari-network-log.js.map +0 -1
  172. package/build/lib/ios-fs-helpers.d.ts +0 -75
  173. package/build/lib/ios-fs-helpers.d.ts.map +0 -1
  174. package/build/lib/ios-fs-helpers.js +0 -370
  175. package/build/lib/ios-fs-helpers.js.map +0 -1
  176. package/build/lib/real-device-clients/base-device-client.d.ts.map +0 -1
  177. package/build/lib/real-device-clients/base-device-client.js.map +0 -1
  178. package/build/lib/real-device-clients/py-ios-device-client.d.ts.map +0 -1
  179. package/build/lib/real-device-clients/py-ios-device-client.js.map +0 -1
  180. package/build/lib/real-device-management.d.ts +0 -53
  181. package/build/lib/real-device-management.d.ts.map +0 -1
  182. package/build/lib/real-device-management.js +0 -128
  183. package/build/lib/real-device-management.js.map +0 -1
  184. package/build/lib/real-device.d.ts +0 -112
  185. package/build/lib/real-device.d.ts.map +0 -1
  186. package/build/lib/real-device.js +0 -352
  187. package/build/lib/real-device.js.map +0 -1
  188. package/build/lib/simulator-management.d.ts +0 -96
  189. package/build/lib/simulator-management.d.ts.map +0 -1
  190. package/build/lib/simulator-management.js.map +0 -1
  191. package/build/lib/xcrun.d.ts +0 -3
  192. package/build/lib/xcrun.d.ts.map +0 -1
  193. package/build/lib/xcrun.js +0 -17
  194. package/build/lib/xcrun.js.map +0 -1
  195. package/lib/ios-fs-helpers.js +0 -355
  196. package/lib/real-device-management.js +0 -133
  197. package/lib/real-device.js +0 -347
  198. package/lib/xcrun.js +0 -16
  199. /package/build/lib/{real-device-clients → device/clients}/base-device-client.d.ts +0 -0
  200. /package/build/lib/{real-device-clients → device/clients}/base-device-client.js +0 -0
  201. /package/build/lib/{real-device-clients → device/clients}/py-ios-device-client.js +0 -0
  202. /package/build/lib/{device-log → device/log}/helpers.js +0 -0
  203. /package/build/lib/{device-log → device/log}/ios-device-log.d.ts +0 -0
  204. /package/build/lib/{device-log → device/log}/ios-device-log.js +0 -0
  205. /package/build/lib/{device-log → device/log}/ios-log.js +0 -0
  206. /package/build/lib/{device-log → device/log}/ios-performance-log.d.ts +0 -0
  207. /package/build/lib/{device-log → device/log}/ios-performance-log.js +0 -0
  208. /package/build/lib/{device-log → device/log}/ios-simulator-log.d.ts +0 -0
  209. /package/build/lib/{device-log → device/log}/ios-simulator-log.js +0 -0
  210. /package/build/lib/{device-log → device/log}/line-consuming-log.js +0 -0
  211. /package/build/lib/{device-log → device/log}/safari-console-log.js +0 -0
  212. /package/build/lib/{device-log → device/log}/safari-network-log.d.ts +0 -0
  213. /package/build/lib/{device-log → device/log}/safari-network-log.js +0 -0
  214. /package/lib/{real-device-clients → device/clients}/base-device-client.ts +0 -0
  215. /package/lib/{device-log → device/log}/ios-device-log.ts +0 -0
  216. /package/lib/{device-log → device/log}/ios-performance-log.ts +0 -0
  217. /package/lib/{device-log → device/log}/ios-simulator-log.ts +0 -0
  218. /package/lib/{device-log → device/log}/safari-network-log.ts +0 -0
@@ -1,13 +1,13 @@
1
1
  import _ from 'lodash';
2
2
  import B from 'bluebird';
3
3
  import {DEFAULT_WS_PATHNAME_PREFIX} from 'appium/driver';
4
- import {IOSCrashLog} from '../device-log/ios-crash-log';
5
- import {IOSSimulatorLog} from '../device-log/ios-simulator-log';
6
- import {IOSDeviceLog} from '../device-log/ios-device-log';
4
+ import {IOSCrashLog} from '../device/log/ios-crash-log';
5
+ import {IOSSimulatorLog} from '../device/log/ios-simulator-log';
6
+ import {IOSDeviceLog} from '../device/log/ios-device-log';
7
7
  import WebSocket from 'ws';
8
- import { SafariConsoleLog } from '../device-log/safari-console-log';
9
- import { SafariNetworkLog } from '../device-log/safari-network-log';
10
- import { toLogEntry } from '../device-log/helpers';
8
+ import { SafariConsoleLog } from '../device/log/safari-console-log';
9
+ import { SafariNetworkLog } from '../device/log/safari-network-log';
10
+ import { toLogEntry } from '../device/log/helpers';
11
11
  import { NATIVE_WIN } from '../utils';
12
12
  import { BIDI_EVENT_NAME } from './bidi/constants';
13
13
  import { makeLogEntryAddedEvent } from './bidi/models';
@@ -119,7 +119,7 @@ export async function startLogCapture() {
119
119
  [this.logs.syslog,] = assignBiDiLogListener.bind(this)(
120
120
  this.isRealDevice()
121
121
  ? new IOSDeviceLog({
122
- udid: this.opts.udid,
122
+ udid: /** @type {string} */ (this.opts.udid),
123
123
  showLogs: this.opts.showIOSLog,
124
124
  log: this.log,
125
125
  })
@@ -14,7 +14,7 @@ export async function mobileSendMemoryWarning(bundleId) {
14
14
  throw new Error('Memory warning simulation is only supported on real devices');
15
15
  }
16
16
 
17
- const device = /** @type {import('../real-device').RealDevice} */ (this.device);
17
+ const device = /** @type {import('../device/real-device-management').RealDevice} */ (this.device);
18
18
 
19
19
  const appInfos = await device.devicectl.listApps(bundleId);
20
20
  if (_.isEmpty(appInfos)) {
@@ -34,7 +34,7 @@ export async function mobilePushNotification(bundleId, payload) {
34
34
  `Got ${JSON.stringify(payload.aps)} instead`,
35
35
  );
36
36
  }
37
- return await /** @type {import('../driver').Simulator} */ (this.device).pushNotification({
37
+ return await /** @type {import('appium-ios-simulator').Simulator} */ (this.device).pushNotification({
38
38
  ...payload,
39
39
  'Simulator Target Bundle': bundleId,
40
40
  });
@@ -16,7 +16,7 @@ export async function mobileSetPasteboard(content, encoding = 'utf8') {
16
16
  // can be empty string
17
17
  throw new Error('Pasteboard content is mandatory to set');
18
18
  }
19
- return await /** @type {import('../driver').Simulator} */ (this.device).simctl.setPasteboard(
19
+ return await /** @type {import('appium-ios-simulator').Simulator} */ (this.device).simctl.setPasteboard(
20
20
  content, /** @type {BufferEncoding} */ (encoding)
21
21
  );
22
22
  }
@@ -34,7 +34,7 @@ export async function mobileGetPasteboard(encoding = 'utf8') {
34
34
  if (!this.isSimulator()) {
35
35
  throw new Error('Getting pasteboard content is not supported on real devices');
36
36
  }
37
- return await /** @type {import('../driver').Simulator} */ (this.device).simctl.getPasteboard(encoding);
37
+ return await /** @type {import('appium-ios-simulator').Simulator} */ (this.device).simctl.getPasteboard(encoding);
38
38
  }
39
39
 
40
40
  /**
@@ -1,4 +1,4 @@
1
- import { Pyidevice } from '../real-device-clients/py-ios-device-client';
1
+ import { Pyidevice } from '../device/clients/py-ios-device-client';
2
2
  import {fs, tempDir, util} from 'appium/support';
3
3
  import {encodeBase64OrUpload} from '../utils';
4
4
  import {errors} from 'appium/driver';
@@ -3,7 +3,6 @@ import path from 'path';
3
3
  import {fs, zip, logger, util, tempDir} from 'appium/support';
4
4
  import {SubProcess, exec} from 'teen_process';
5
5
  import {encodeBase64OrUpload} from '../utils';
6
- import { XCRUN, requireXcrun } from '../xcrun';
7
6
  import {waitForCondition} from 'asyncbox';
8
7
  import B from 'bluebird';
9
8
 
@@ -20,6 +19,7 @@ const DEFAULT_EXT = '.trace';
20
19
  const DEFAULT_PID = 'current';
21
20
  const INSTRUMENTS = 'instruments';
22
21
  const XCTRACE = 'xctrace';
22
+ const XCRUN = 'xcrun';
23
23
 
24
24
  /**
25
25
  * Starts performance profiling for the device under test.
@@ -387,6 +387,17 @@ export class PerfRecorder {
387
387
  }
388
388
  }
389
389
 
390
+ async function requireXcrun() {
391
+ try {
392
+ return await fs.which(XCRUN);
393
+ } catch {
394
+ throw new Error(
395
+ `${XCRUN} has not been found in PATH. ` +
396
+ `Please make sure XCode development tools are installed`,
397
+ );
398
+ }
399
+ }
400
+
390
401
  /**
391
402
  * @typedef {import('../driver').XCUITestDriver} XCUITestDriver
392
403
  */
@@ -55,7 +55,7 @@ export async function mobileGetPermission(bundleId, service) {
55
55
  assertSimulator(this);
56
56
 
57
57
  return /** @type {import('./types').PermissionState} */ (
58
- await /** @type {import('../driver').Simulator} */ (this.device).getPermission(
58
+ await /** @type {import('appium-ios-simulator').Simulator} */ (this.device).getPermission(
59
59
  bundleId, String(service)
60
60
  )
61
61
  );
@@ -77,7 +77,7 @@ export async function mobileSetPermissions(access, bundleId) {
77
77
  }
78
78
  assertSimulator(this);
79
79
 
80
- await /** @type {import('../driver').Simulator} */ (this.device).setPermissions(bundleId, access);
80
+ await /** @type {import('appium-ios-simulator').Simulator} */ (this.device).setPermissions(bundleId, access);
81
81
  }
82
82
 
83
83
  /**
@@ -69,9 +69,6 @@ export async function proxyCommand(url, method, body, isSessionCommand = true) {
69
69
  );
70
70
  }
71
71
 
72
- if (!this.wda) {
73
- throw new Error('Cannot call proxyCommand without WDA driver active');
74
- }
75
72
  const proxy = isSessionCommand ? this.wda.jwproxy : this.wda.noSessionProxy;
76
73
  if (!proxy) {
77
74
  throw new Error('Cannot call proxyCommand without WDA proxy active');
@@ -60,7 +60,7 @@ export async function getScreenshot() {
60
60
  // simulator attempt
61
61
  if (this.isSimulator()) {
62
62
  this.log.info(`Falling back to 'simctl io screenshot' API`);
63
- const payload = await /** @type {import('../driver').Simulator} */ (this.device).simctl.getScreenshot();
63
+ const payload = await /** @type {import('appium-ios-simulator').Simulator} */ (this.device).simctl.getScreenshot();
64
64
  if (!payload) {
65
65
  throw new errors.UnableToCaptureScreen();
66
66
  }
@@ -53,7 +53,7 @@ export async function mobileSimctl(command, args = [], timeout = undefined) {
53
53
  `Available subcommands are ${SUBCOMMANDS_HAS_DEVICE.join(',')}`);
54
54
  }
55
55
 
56
- return await /** @type {import('./../driver').Simulator} */ (this.device).simctl.exec(
56
+ return await /** @type {import('appium-ios-simulator').Simulator} */ (this.device).simctl.exec(
57
57
  command,
58
58
  {args: [this.opts.udid, ...args], timeout}
59
59
  );
@@ -960,7 +960,7 @@ export async function mobileUpdateSafariPreferences(preferences) {
960
960
  }
961
961
 
962
962
  this.log.debug(`About to update Safari preferences: ${JSON.stringify(preferences)}`);
963
- await /** @type {import('../driver').Simulator} */ (this.device).updateSafariSettings(preferences);
963
+ await /** @type {import('appium-ios-simulator').Simulator} */ (this.device).updateSafariSettings(preferences);
964
964
  }
965
965
 
966
966
  /**
@@ -32,7 +32,7 @@ const SUBDIRECTORY = 'Attachments';
32
32
  * @returns {Promise<string>} The full path to the screen recording movie
33
33
  */
34
34
  async function retrieveRecodingFromSimulator(uuid) {
35
- const device = /** @type {import('../driver').Simulator} */ (this.device);
35
+ const device = /** @type {import('appium-ios-simulator').Simulator} */ (this.device);
36
36
  const dataRoot = /** @type {string} */ (device.getDir());
37
37
  // On Simulators the path looks like
38
38
  // $HOME/Library/Developer/CoreSimulator/Devices/F8E1968A-8443-4A9A-AB86-27C54C36A2F6/data/Containers/Data/InternalDaemon/4E3FE8DF-AD0A-41DA-B6EC-C35E5798C219/Attachments/A044DAF7-4A58-4CD5-95C3-29B4FE80C377
@@ -58,7 +58,7 @@ async function retrieveRecodingFromSimulator(uuid) {
58
58
  * @returns {Promise<string>} The full path to the screen recording movie
59
59
  */
60
60
  async function retrieveRecodingFromRealDevice(uuid) {
61
- const device = /** @type {import('../real-device').RealDevice} */ (this.device);
61
+ const device = /** @type {import('../device/real-device-management').RealDevice} */ (this.device);
62
62
 
63
63
  const fileNames = await device.devicectl.listFiles(DOMAIN_TYPE, DOMAIN_IDENTIFIER, {
64
64
  username: USERNAME,
@@ -1,8 +1,10 @@
1
+ import type {Constraints} from '@appium/types';
2
+
1
3
  // These platform names should be valid in simulator name
2
- const PLATFORM_NAME_IOS = 'iOS';
3
- const PLATFORM_NAME_TVOS = 'tvOS';
4
+ export const PLATFORM_NAME_IOS = 'iOS';
5
+ export const PLATFORM_NAME_TVOS = 'tvOS';
4
6
 
5
- const desiredCapConstraints = /** @type {const} */ ({
7
+ export const desiredCapConstraints = {
6
8
  platformName: {
7
9
  // override
8
10
  presence: true,
@@ -391,7 +393,6 @@ const desiredCapConstraints = /** @type {const} */ ({
391
393
  isString: true,
392
394
  inclusionCaseInsensitive: ['none', 'eager', 'normal']
393
395
  }
394
- });
396
+ } as const satisfies Constraints;
395
397
 
396
- export {desiredCapConstraints, PLATFORM_NAME_IOS, PLATFORM_NAME_TVOS};
397
- export default desiredCapConstraints;
398
+ export type XCUITestDriverConstraints = typeof desiredCapConstraints;
@@ -4,7 +4,7 @@ import path from 'path';
4
4
  import { BaseDeviceClient } from './base-device-client';
5
5
  import type { BaseDeviceClientOptions, InstallProfileArgs } from './base-device-client';
6
6
  import type { TeenProcessExecResult } from 'teen_process';
7
- import type { CertificateList } from '../commands/types';
7
+ import type { CertificateList } from '../../commands/types';
8
8
 
9
9
  // https://github.com/YueChen-C/py-ios-device
10
10
 
@@ -5,30 +5,39 @@ import {logger, util, timing} from 'appium/support';
5
5
  import {utilities} from 'appium-ios-device';
6
6
  import {checkPortStatus} from 'portscanner';
7
7
  import {waitForCondition} from 'asyncbox';
8
+ import type { AppiumLogger } from '@appium/types';
8
9
 
9
10
  const LOCALHOST = '127.0.0.1';
10
11
 
11
12
  class iProxy {
12
- constructor(udid, localport, deviceport) {
13
- this.localport = parseInt(localport, 10);
14
- this.deviceport = parseInt(deviceport, 10);
13
+ private readonly localport: number;
14
+ private readonly deviceport: number;
15
+ private readonly udid: string;
16
+ private localServer: net.Server | null;
17
+ private readonly log: AppiumLogger;
18
+ private onBeforeProcessExit: (() => void) | null;
19
+
20
+ constructor(udid: string, localport: string | number, deviceport: string | number) {
21
+ this.localport = parseInt(String(localport), 10);
22
+ this.deviceport = parseInt(String(deviceport), 10);
15
23
  this.udid = udid;
16
24
  this.localServer = null;
17
25
  this.log = logger.getLogger(`iProxy@${udid.substring(0, 8)}:${this.localport}`);
26
+ this.onBeforeProcessExit = null;
18
27
  }
19
28
 
20
- async start() {
29
+ async start(): Promise<void> {
21
30
  if (this.localServer) {
22
31
  return;
23
32
  }
24
33
 
25
- this.localServer = net.createServer(async (localSocket) => {
26
- let remoteSocket;
34
+ this.localServer = net.createServer(async (localSocket: net.Socket) => {
35
+ let remoteSocket: any;
27
36
  try {
28
37
  // We can only connect to the remote socket after the local socket connection succeeds
29
38
  remoteSocket = await utilities.connectPort(this.udid, this.deviceport);
30
39
  } catch (e) {
31
- this.log.debug(e.message);
40
+ this.log.debug((e as Error).message);
32
41
  localSocket.destroy();
33
42
  return;
34
43
  }
@@ -42,19 +51,23 @@ class iProxy {
42
51
  localSocket.destroy();
43
52
  });
44
53
  // not all remote socket errors are critical for the user
45
- remoteSocket.on('error', (e) => this.log.debug(e));
54
+ remoteSocket.on('error', (e: Error) => this.log.debug(e));
46
55
  localSocket.once('end', destroyCommChannel);
47
56
  localSocket.once('close', () => {
48
57
  destroyCommChannel();
49
58
  remoteSocket.destroy();
50
59
  });
51
- localSocket.on('error', (e) => this.log.warn(e.message));
60
+ localSocket.on('error', (e: Error) => this.log.warn(e.message));
52
61
  localSocket.pipe(remoteSocket);
53
62
  remoteSocket.pipe(localSocket);
54
63
  });
55
- const listeningPromise = new B((resolve, reject) => {
56
- /** @type {net.Server} */ (this.localServer).once('listening', resolve);
57
- /** @type {net.Server} */ (this.localServer).once('error', reject);
64
+ const listeningPromise = new B<void>((resolve, reject) => {
65
+ if (this.localServer) {
66
+ this.localServer.once('listening', resolve);
67
+ this.localServer.once('error', reject);
68
+ } else {
69
+ reject(new Error('Local server is not initialized'));
70
+ }
58
71
  });
59
72
  this.localServer.listen(this.localport);
60
73
  try {
@@ -63,8 +76,8 @@ class iProxy {
63
76
  this.localServer = null;
64
77
  throw e;
65
78
  }
66
- this.localServer.on('error', (e) => this.log.warn(e.message));
67
- this.localServer.once('close', (e) => {
79
+ this.localServer.on('error', (e: Error) => this.log.warn(e.message));
80
+ this.localServer.once('close', (e?: Error) => {
68
81
  if (e) {
69
82
  this.log.info(`The connection has been closed with error ${e.message}`);
70
83
  } else {
@@ -75,20 +88,12 @@ class iProxy {
75
88
 
76
89
  this.onBeforeProcessExit = this._closeLocalServer.bind(this);
77
90
  // Make sure we free up the socket on process exit
78
- process.on('beforeExit', this.onBeforeProcessExit);
79
- }
80
-
81
- _closeLocalServer() {
82
- if (!this.localServer) {
83
- return;
91
+ if (this.onBeforeProcessExit) {
92
+ process.on('beforeExit', this.onBeforeProcessExit);
84
93
  }
85
-
86
- this.log.debug(`Closing the connection`);
87
- this.localServer.close();
88
- this.localServer = null;
89
94
  }
90
95
 
91
- stop() {
96
+ stop(): void {
92
97
  if (this.onBeforeProcessExit) {
93
98
  process.off('beforeExit', this.onBeforeProcessExit);
94
99
  this.onBeforeProcessExit = null;
@@ -96,43 +101,34 @@ class iProxy {
96
101
 
97
102
  this._closeLocalServer();
98
103
  }
104
+
105
+ private _closeLocalServer(): void {
106
+ if (!this.localServer) {
107
+ return;
108
+ }
109
+
110
+ this.log.debug(`Closing the connection`);
111
+ this.localServer.close();
112
+ this.localServer = null;
113
+ }
99
114
  }
100
115
 
101
116
  const log = logger.getLogger('DevCon Factory');
102
117
  const PORT_CLOSE_TIMEOUT = 15 * 1000; // 15 seconds
103
118
  const SPLITTER = ':';
104
119
 
105
- class DeviceConnectionsFactory {
120
+ export class DeviceConnectionsFactory {
121
+ private _connectionsMapping: ConnectionMapping;
122
+
106
123
  constructor() {
107
124
  this._connectionsMapping = {};
108
125
  }
109
126
 
110
- _udidAsToken(udid) {
111
- return `${util.hasValue(udid) ? udid : ''}${SPLITTER}`;
112
- }
113
-
114
- _portAsToken(port) {
115
- return `${SPLITTER}${util.hasValue(port) ? port : ''}`;
116
- }
117
-
118
- _toKey(udid = null, port = null) {
119
- return `${util.hasValue(udid) ? udid : ''}${SPLITTER}${util.hasValue(port) ? port : ''}`;
120
- }
121
-
122
- _releaseProxiedConnections(connectionKeys) {
123
- const keys = connectionKeys.filter((k) => _.has(this._connectionsMapping[k], 'iproxy'));
124
- for (const key of keys) {
125
- log.info(`Releasing the listener for '${key}'`);
126
- try {
127
- this._connectionsMapping[key].iproxy.stop();
128
- } catch (e) {
129
- log.debug(e);
130
- }
131
- }
132
- return keys;
133
- }
134
-
135
- listConnections(udid = null, port = null, strict = false) {
127
+ listConnections(
128
+ udid: string | null = null,
129
+ port: string | number | null = null,
130
+ strict: boolean = false
131
+ ): string[] {
136
132
  if (!udid && !port) {
137
133
  return [];
138
134
  }
@@ -149,7 +145,11 @@ class DeviceConnectionsFactory {
149
145
  );
150
146
  }
151
147
 
152
- async requestConnection(udid, port, options = {}) {
148
+ async requestConnection(
149
+ udid?: string | null,
150
+ port?: string | number | null,
151
+ options: RequestConnectionOptions = {}
152
+ ): Promise<void> {
153
153
  if (!udid || !port) {
154
154
  log.warn('Did not know how to request the connection:');
155
155
  if (!udid) {
@@ -174,7 +174,7 @@ class DeviceConnectionsFactory {
174
174
  }
175
175
 
176
176
  if (usePortForwarding) {
177
- let isPortBusy = (await checkPortStatus(port, LOCALHOST)) === 'open';
177
+ let isPortBusy = (await checkPortStatus(Number(port), LOCALHOST)) === 'open';
178
178
  if (isPortBusy) {
179
179
  log.warn(`Port #${port} is busy. Did you quit the previous driver session(s) properly?`);
180
180
  if (!_.isEmpty(connectionsOnPort)) {
@@ -187,7 +187,7 @@ class DeviceConnectionsFactory {
187
187
  await waitForCondition(
188
188
  async () => {
189
189
  try {
190
- if ((await checkPortStatus(port, LOCALHOST)) !== 'open') {
190
+ if ((await checkPortStatus(Number(port), LOCALHOST)) !== 'open') {
191
191
  log.info(
192
192
  `Port #${port} has been successfully released after ` +
193
193
  `${timer.getDuration().asMilliSeconds.toFixed(0)}ms`,
@@ -221,7 +221,10 @@ class DeviceConnectionsFactory {
221
221
  }
222
222
  const currentKey = this._toKey(udid, port);
223
223
  if (usePortForwarding) {
224
- const iproxy = new iProxy(udid, port, devicePort);
224
+ if (!_.isInteger(devicePort)) {
225
+ throw new Error('devicePort is required when usePortForwarding is true');
226
+ }
227
+ const iproxy = new iProxy(udid, port, Number(devicePort));
225
228
  try {
226
229
  await iproxy.start();
227
230
  this._connectionsMapping[currentKey] = {iproxy};
@@ -239,7 +242,7 @@ class DeviceConnectionsFactory {
239
242
  log.info(`Successfully requested the connection for ${currentKey}`);
240
243
  }
241
244
 
242
- releaseConnection(udid = null, port = null) {
245
+ releaseConnection(udid: string | null = null, port: string | number | null = null): void {
243
246
  if (!udid && !port) {
244
247
  log.warn(
245
248
  'Neither device UDID nor local port is set. ' +
@@ -261,9 +264,42 @@ class DeviceConnectionsFactory {
261
264
  }
262
265
  log.debug(`Cached connections count: ${_.size(this._connectionsMapping)}`);
263
266
  }
267
+
268
+ private _udidAsToken(udid?: string | null): string {
269
+ return `${util.hasValue(udid) ? udid : ''}${SPLITTER}`;
270
+ }
271
+
272
+ private _portAsToken(port?: string | number | null): string {
273
+ return `${SPLITTER}${util.hasValue(port) ? port : ''}`;
274
+ }
275
+
276
+ private _toKey(udid: string | null = null, port: string | number | null = null): string {
277
+ return `${util.hasValue(udid) ? udid : ''}${SPLITTER}${util.hasValue(port) ? port : ''}`;
278
+ }
279
+
280
+ private _releaseProxiedConnections(connectionKeys: string[]): string[] {
281
+ const keys = connectionKeys.filter((k) => _.has(this._connectionsMapping[k], 'iproxy'));
282
+ for (const key of keys) {
283
+ log.info(`Releasing the listener for '${key}'`);
284
+ try {
285
+ this._connectionsMapping[key].iproxy?.stop();
286
+ } catch (e) {
287
+ log.debug(e);
288
+ }
289
+ }
290
+ return keys;
291
+ }
264
292
  }
265
293
 
266
- const DEVICE_CONNECTIONS_FACTORY = new DeviceConnectionsFactory();
294
+ export const DEVICE_CONNECTIONS_FACTORY = new DeviceConnectionsFactory();
295
+
296
+ interface ConnectionMapping {
297
+ [key: string]: {
298
+ iproxy?: iProxy;
299
+ };
300
+ }
267
301
 
268
- export {DEVICE_CONNECTIONS_FACTORY, DeviceConnectionsFactory};
269
- export default DEVICE_CONNECTIONS_FACTORY;
302
+ interface RequestConnectionOptions {
303
+ usePortForwarding?: boolean;
304
+ devicePort?: number | null;
305
+ }
@@ -1,4 +1,4 @@
1
- import type { LogEntry } from '../commands/types';
1
+ import type { LogEntry } from '../../commands/types';
2
2
  import { fs } from 'appium/support';
3
3
  import { createInterface } from 'node:readline';
4
4
  import _ from 'lodash';
@@ -2,13 +2,13 @@ import {fs, tempDir, util} from 'appium/support';
2
2
  import B from 'bluebird';
3
3
  import path from 'path';
4
4
  import _ from 'lodash';
5
- import {Pyidevice} from '../real-device-clients/py-ios-device-client';
5
+ import {Pyidevice} from '../clients/py-ios-device-client';
6
6
  import {IOSLog} from './ios-log';
7
7
  import { toLogEntry, grepFile } from './helpers';
8
8
  import type { AppiumLogger } from '@appium/types';
9
- import type { BaseDeviceClient } from '../real-device-clients/base-device-client';
9
+ import type { BaseDeviceClient } from '../clients/base-device-client';
10
10
  import type { Simulator } from 'appium-ios-simulator';
11
- import type { LogEntry } from '../commands/types';
11
+ import type { LogEntry } from '../../commands/types';
12
12
 
13
13
  // The file format has been changed from '.crash' to '.ips' since Monterey.
14
14
  const CRASH_REPORTS_GLOB_PATTERN = '**/*.@(crash|ips)';
@@ -1,6 +1,6 @@
1
1
  import {EventEmitter} from 'events';
2
2
  import { LRUCache } from 'lru-cache';
3
- import type { LogEntry } from '../commands/types';
3
+ import type { LogEntry } from '../../commands/types';
4
4
  import type { AppiumLogger } from '@appium/types';
5
5
  import {logger} from 'appium/support';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import {IOSLog} from './ios-log';
2
2
  import { toLogEntry } from './helpers';
3
- import type { LogEntry } from '../commands/types';
3
+ import type { LogEntry } from '../../commands/types';
4
4
 
5
5
  type TSerializedEntry = [string, number];
6
6
 
@@ -7,7 +7,7 @@ import {
7
7
  MAX_BUFFERED_EVENTS_COUNT
8
8
  } from './helpers';
9
9
  import { IOSLog } from './ios-log';
10
- import type { LogEntry } from '../commands/types';
10
+ import type { LogEntry } from '../../commands/types';
11
11
 
12
12
  const LOG_LEVELS_MAP = {
13
13
  error: 'SEVERE',