appium-xcuitest-driver 10.3.0 → 10.4.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 (252) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/lib/commands/active-app-info.d.ts +9 -0
  3. package/build/lib/commands/active-app-info.d.ts.map +1 -0
  4. package/build/lib/commands/active-app-info.js +14 -0
  5. package/build/lib/commands/active-app-info.js.map +1 -0
  6. package/build/lib/commands/alert.d.ts +42 -45
  7. package/build/lib/commands/alert.d.ts.map +1 -1
  8. package/build/lib/commands/alert.js +66 -62
  9. package/build/lib/commands/alert.js.map +1 -1
  10. package/build/lib/commands/app-management.d.ts +150 -153
  11. package/build/lib/commands/app-management.d.ts.map +1 -1
  12. package/build/lib/commands/app-management.js +300 -286
  13. package/build/lib/commands/app-management.js.map +1 -1
  14. package/build/lib/commands/app-strings.d.ts +14 -17
  15. package/build/lib/commands/app-strings.d.ts.map +1 -1
  16. package/build/lib/commands/app-strings.js +23 -24
  17. package/build/lib/commands/app-strings.js.map +1 -1
  18. package/build/lib/commands/appearance.d.ts +19 -22
  19. package/build/lib/commands/appearance.d.ts.map +1 -1
  20. package/build/lib/commands/appearance.js +56 -56
  21. package/build/lib/commands/appearance.js.map +1 -1
  22. package/build/lib/commands/audit.d.ts +22 -17
  23. package/build/lib/commands/audit.d.ts.map +1 -1
  24. package/build/lib/commands/audit.js +17 -18
  25. package/build/lib/commands/audit.js.map +1 -1
  26. package/build/lib/commands/battery.d.ts +11 -14
  27. package/build/lib/commands/battery.d.ts.map +1 -1
  28. package/build/lib/commands/battery.js +36 -37
  29. package/build/lib/commands/battery.js.map +1 -1
  30. package/build/lib/commands/biometric.d.ts +30 -33
  31. package/build/lib/commands/biometric.d.ts.map +1 -1
  32. package/build/lib/commands/biometric.js +42 -41
  33. package/build/lib/commands/biometric.js.map +1 -1
  34. package/build/lib/commands/certificate.d.ts +48 -45
  35. package/build/lib/commands/certificate.d.ts.map +1 -1
  36. package/build/lib/commands/certificate.js +218 -205
  37. package/build/lib/commands/certificate.js.map +1 -1
  38. package/build/lib/commands/clipboard.d.ts +19 -22
  39. package/build/lib/commands/clipboard.d.ts.map +1 -1
  40. package/build/lib/commands/clipboard.js +30 -30
  41. package/build/lib/commands/clipboard.js.map +1 -1
  42. package/build/lib/commands/condition.d.ts +49 -26
  43. package/build/lib/commands/condition.d.ts.map +1 -1
  44. package/build/lib/commands/condition.js +87 -86
  45. package/build/lib/commands/condition.js.map +1 -1
  46. package/build/lib/commands/content-size.d.ts +26 -29
  47. package/build/lib/commands/content-size.d.ts.map +1 -1
  48. package/build/lib/commands/content-size.js +36 -36
  49. package/build/lib/commands/content-size.js.map +1 -1
  50. package/build/lib/commands/context.d.ts +161 -108
  51. package/build/lib/commands/context.d.ts.map +1 -1
  52. package/build/lib/commands/context.js +530 -517
  53. package/build/lib/commands/context.js.map +1 -1
  54. package/build/lib/commands/deviceInfo.d.ts +9 -12
  55. package/build/lib/commands/deviceInfo.d.ts.map +1 -1
  56. package/build/lib/commands/deviceInfo.js +17 -18
  57. package/build/lib/commands/deviceInfo.js.map +1 -1
  58. package/build/lib/commands/element.d.ts +102 -105
  59. package/build/lib/commands/element.d.ts.map +1 -1
  60. package/build/lib/commands/element.js +337 -323
  61. package/build/lib/commands/element.js.map +1 -1
  62. package/build/lib/commands/execute.d.ts +24 -19
  63. package/build/lib/commands/execute.d.ts.map +1 -1
  64. package/build/lib/commands/execute.js +63 -62
  65. package/build/lib/commands/execute.js.map +1 -1
  66. package/build/lib/commands/file-movement.d.ts +77 -80
  67. package/build/lib/commands/file-movement.d.ts.map +1 -1
  68. package/build/lib/commands/file-movement.js +130 -124
  69. package/build/lib/commands/file-movement.js.map +1 -1
  70. package/build/lib/commands/find.d.ts +18 -21
  71. package/build/lib/commands/find.d.ts.map +1 -1
  72. package/build/lib/commands/find.js +158 -156
  73. package/build/lib/commands/find.js.map +1 -1
  74. package/build/lib/commands/general.d.ts +124 -116
  75. package/build/lib/commands/general.d.ts.map +1 -1
  76. package/build/lib/commands/general.js +248 -232
  77. package/build/lib/commands/general.js.map +1 -1
  78. package/build/lib/commands/geolocation.d.ts +43 -46
  79. package/build/lib/commands/geolocation.d.ts.map +1 -1
  80. package/build/lib/commands/geolocation.js +10 -11
  81. package/build/lib/commands/geolocation.js.map +1 -1
  82. package/build/lib/commands/gesture.d.ts +273 -276
  83. package/build/lib/commands/gesture.d.ts.map +1 -1
  84. package/build/lib/commands/gesture.js +506 -492
  85. package/build/lib/commands/gesture.js.map +1 -1
  86. package/build/lib/commands/increase-contrast.d.ts +20 -23
  87. package/build/lib/commands/increase-contrast.d.ts.map +1 -1
  88. package/build/lib/commands/increase-contrast.js +30 -30
  89. package/build/lib/commands/increase-contrast.js.map +1 -1
  90. package/build/lib/commands/iohid.d.ts +1370 -1373
  91. package/build/lib/commands/iohid.d.ts.map +1 -1
  92. package/build/lib/commands/iohid.js +30 -31
  93. package/build/lib/commands/iohid.js.map +1 -1
  94. package/build/lib/commands/keyboard.d.ts +29 -32
  95. package/build/lib/commands/keyboard.d.ts.map +1 -1
  96. package/build/lib/commands/keyboard.js +53 -51
  97. package/build/lib/commands/keyboard.js.map +1 -1
  98. package/build/lib/commands/keychains.d.ts +9 -12
  99. package/build/lib/commands/keychains.d.ts.map +1 -1
  100. package/build/lib/commands/keychains.js +13 -14
  101. package/build/lib/commands/keychains.js.map +1 -1
  102. package/build/lib/commands/localization.d.ts +16 -19
  103. package/build/lib/commands/localization.d.ts.map +1 -1
  104. package/build/lib/commands/localization.js +25 -26
  105. package/build/lib/commands/localization.js.map +1 -1
  106. package/build/lib/commands/location.d.ts +36 -39
  107. package/build/lib/commands/location.d.ts.map +1 -1
  108. package/build/lib/commands/location.js +99 -98
  109. package/build/lib/commands/location.js.map +1 -1
  110. package/build/lib/commands/lock.d.ts +21 -24
  111. package/build/lib/commands/lock.d.ts.map +1 -1
  112. package/build/lib/commands/lock.js +39 -38
  113. package/build/lib/commands/lock.js.map +1 -1
  114. package/build/lib/commands/log.d.ts +43 -37
  115. package/build/lib/commands/log.d.ts.map +1 -1
  116. package/build/lib/commands/log.js +174 -171
  117. package/build/lib/commands/log.js.map +1 -1
  118. package/build/lib/commands/memory.d.ts +9 -12
  119. package/build/lib/commands/memory.d.ts.map +1 -1
  120. package/build/lib/commands/memory.js +37 -38
  121. package/build/lib/commands/memory.js.map +1 -1
  122. package/build/lib/commands/navigation.d.ts +30 -33
  123. package/build/lib/commands/navigation.d.ts.map +1 -1
  124. package/build/lib/commands/navigation.js +92 -92
  125. package/build/lib/commands/navigation.js.map +1 -1
  126. package/build/lib/commands/notifications.d.ts +26 -29
  127. package/build/lib/commands/notifications.d.ts.map +1 -1
  128. package/build/lib/commands/notifications.js +53 -53
  129. package/build/lib/commands/notifications.js.map +1 -1
  130. package/build/lib/commands/pasteboard.d.ts +21 -24
  131. package/build/lib/commands/pasteboard.d.ts.map +1 -1
  132. package/build/lib/commands/pasteboard.js +37 -37
  133. package/build/lib/commands/pasteboard.js.map +1 -1
  134. package/build/lib/commands/pcap.d.ts +39 -26
  135. package/build/lib/commands/pcap.d.ts.map +1 -1
  136. package/build/lib/commands/pcap.js +81 -81
  137. package/build/lib/commands/pcap.js.map +1 -1
  138. package/build/lib/commands/performance.d.ts +63 -44
  139. package/build/lib/commands/performance.d.ts.map +1 -1
  140. package/build/lib/commands/performance.js +105 -105
  141. package/build/lib/commands/performance.js.map +1 -1
  142. package/build/lib/commands/permissions.d.ts +33 -36
  143. package/build/lib/commands/permissions.d.ts.map +1 -1
  144. package/build/lib/commands/permissions.js +66 -65
  145. package/build/lib/commands/permissions.js.map +1 -1
  146. package/build/lib/commands/proxy-helper.d.ts +12 -15
  147. package/build/lib/commands/proxy-helper.d.ts.map +1 -1
  148. package/build/lib/commands/proxy-helper.js +53 -54
  149. package/build/lib/commands/proxy-helper.js.map +1 -1
  150. package/build/lib/commands/record-audio.d.ts +49 -29
  151. package/build/lib/commands/record-audio.d.ts.map +1 -1
  152. package/build/lib/commands/record-audio.js +100 -104
  153. package/build/lib/commands/record-audio.js.map +1 -1
  154. package/build/lib/commands/recordscreen.d.ts +54 -18
  155. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  156. package/build/lib/commands/recordscreen.js +127 -129
  157. package/build/lib/commands/recordscreen.js.map +1 -1
  158. package/build/lib/commands/screenshots.d.ts +14 -17
  159. package/build/lib/commands/screenshots.d.ts.map +1 -1
  160. package/build/lib/commands/screenshots.js +108 -107
  161. package/build/lib/commands/screenshots.js.map +1 -1
  162. package/build/lib/commands/simctl.d.ts +11 -14
  163. package/build/lib/commands/simctl.d.ts.map +1 -1
  164. package/build/lib/commands/simctl.js +23 -26
  165. package/build/lib/commands/simctl.js.map +1 -1
  166. package/build/lib/commands/source.d.ts +14 -17
  167. package/build/lib/commands/source.d.ts.map +1 -1
  168. package/build/lib/commands/source.js +40 -43
  169. package/build/lib/commands/source.js.map +1 -1
  170. package/build/lib/commands/timeouts.d.ts +44 -33
  171. package/build/lib/commands/timeouts.d.ts.map +1 -1
  172. package/build/lib/commands/timeouts.js +65 -63
  173. package/build/lib/commands/timeouts.js.map +1 -1
  174. package/build/lib/commands/web.d.ts +247 -197
  175. package/build/lib/commands/web.d.ts.map +1 -1
  176. package/build/lib/commands/web.js +815 -786
  177. package/build/lib/commands/web.js.map +1 -1
  178. package/build/lib/commands/xctest-record-screen.d.ts +63 -66
  179. package/build/lib/commands/xctest-record-screen.d.ts.map +1 -1
  180. package/build/lib/commands/xctest-record-screen.js +103 -102
  181. package/build/lib/commands/xctest-record-screen.js.map +1 -1
  182. package/build/lib/commands/xctest.d.ts +55 -51
  183. package/build/lib/commands/xctest.d.ts.map +1 -1
  184. package/build/lib/commands/xctest.js +116 -117
  185. package/build/lib/commands/xctest.js.map +1 -1
  186. package/build/lib/driver.d.ts +278 -1597
  187. package/build/lib/driver.d.ts.map +1 -1
  188. package/build/lib/driver.js +319 -235
  189. package/build/lib/driver.js.map +1 -1
  190. package/build/lib/execute-method-map.d.ts.map +1 -1
  191. package/build/lib/execute-method-map.js +9 -0
  192. package/build/lib/execute-method-map.js.map +1 -1
  193. package/lib/commands/active-app-info.js +12 -0
  194. package/lib/commands/alert.js +68 -65
  195. package/lib/commands/app-management.js +308 -301
  196. package/lib/commands/app-strings.js +24 -26
  197. package/lib/commands/appearance.js +54 -56
  198. package/lib/commands/audit.js +18 -20
  199. package/lib/commands/battery.js +35 -37
  200. package/lib/commands/biometric.js +44 -46
  201. package/lib/commands/certificate.js +226 -215
  202. package/lib/commands/clipboard.js +30 -32
  203. package/lib/commands/condition.js +98 -100
  204. package/lib/commands/content-size.js +36 -38
  205. package/lib/commands/context.js +495 -490
  206. package/lib/commands/deviceInfo.js +19 -20
  207. package/lib/commands/element.js +367 -357
  208. package/lib/commands/execute.js +72 -72
  209. package/lib/commands/file-movement.js +132 -134
  210. package/lib/commands/find.js +160 -159
  211. package/lib/commands/general.js +238 -231
  212. package/lib/commands/geolocation.js +6 -14
  213. package/lib/commands/gesture.js +525 -515
  214. package/lib/commands/increase-contrast.js +30 -32
  215. package/lib/commands/iohid.js +32 -34
  216. package/lib/commands/keyboard.js +49 -51
  217. package/lib/commands/keychains.js +12 -14
  218. package/lib/commands/localization.js +24 -26
  219. package/lib/commands/location.js +102 -104
  220. package/lib/commands/lock.js +38 -38
  221. package/lib/commands/log.js +197 -198
  222. package/lib/commands/memory.js +40 -42
  223. package/lib/commands/navigation.js +96 -100
  224. package/lib/commands/notifications.js +57 -59
  225. package/lib/commands/pasteboard.js +37 -39
  226. package/lib/commands/pcap.js +84 -86
  227. package/lib/commands/performance.js +132 -133
  228. package/lib/commands/permissions.js +67 -69
  229. package/lib/commands/proxy-helper.js +60 -61
  230. package/lib/commands/record-audio.js +115 -120
  231. package/lib/commands/recordscreen.js +145 -149
  232. package/lib/commands/screenshots.js +116 -116
  233. package/lib/commands/simctl.js +25 -29
  234. package/lib/commands/source.js +42 -46
  235. package/lib/commands/timeouts.js +59 -63
  236. package/lib/commands/web.js +878 -858
  237. package/lib/commands/xctest-record-screen.js +103 -105
  238. package/lib/commands/xctest.js +134 -139
  239. package/lib/driver.js +287 -235
  240. package/lib/execute-method-map.ts +9 -0
  241. package/npm-shrinkwrap.json +2 -2
  242. package/package.json +1 -1
  243. package/build/lib/commands/activeAppInfo.d.ts +0 -12
  244. package/build/lib/commands/activeAppInfo.d.ts.map +0 -1
  245. package/build/lib/commands/activeAppInfo.js +0 -15
  246. package/build/lib/commands/activeAppInfo.js.map +0 -1
  247. package/build/lib/commands/index.d.ts +0 -96
  248. package/build/lib/commands/index.d.ts.map +0 -1
  249. package/build/lib/commands/index.js +0 -100
  250. package/build/lib/commands/index.js.map +0 -1
  251. package/lib/commands/activeAppInfo.js +0 -14
  252. package/lib/commands/index.js +0 -95
@@ -6,26 +6,25 @@ import {exec} from 'teen_process';
6
6
 
7
7
  const MOMENT_FORMAT_ISO8601 = 'YYYY-MM-DDTHH:mm:ssZ';
8
8
 
9
- const commands = {
10
- /**
11
- * @this {XCUITestDriver}
12
- */
13
- async active() {
14
- if (this.isWebContext()) {
15
- return this.cacheWebElements(await this.executeAtom('active_element', []));
16
- }
17
- return await this.proxyCommand(`/element/active`, 'GET');
18
- },
9
+ /**
10
+ * @this {XCUITestDriver}
11
+ */
12
+ export async function active() {
13
+ if (this.isWebContext()) {
14
+ return this.cacheWebElements(await this.executeAtom('active_element', []));
15
+ }
16
+ return await this.proxyCommand(`/element/active`, 'GET');
17
+ }
19
18
 
20
- /**
21
- * Trigger a touch/fingerprint match or match failure
22
- *
23
- * @param {boolean} match - whether the match should be a success or failure
24
- * @this {XCUITestDriver}
25
- */
26
- async touchId(match = true) {
27
- await this.mobileSendBiometricMatch('touchId', match);
28
- },
19
+ /**
20
+ * Trigger a touch/fingerprint match or match failure
21
+ *
22
+ * @param {boolean} match - whether the match should be a success or failure
23
+ * @this {XCUITestDriver}
24
+ */
25
+ export async function touchId(match = true) {
26
+ await this.mobileSendBiometricMatch('touchId', match);
27
+ }
29
28
  /**
30
29
  * Toggle whether the device is enrolled in the touch ID program
31
30
  *
@@ -33,231 +32,239 @@ const commands = {
33
32
  *
34
33
  * @this {XCUITestDriver}
35
34
  */
36
- async toggleEnrollTouchId(isEnabled = true) {
37
- await this.mobileEnrollBiometric(isEnabled);
38
- },
39
- /**
40
- * Get the window size
41
- * @this {XCUITestDriver}
42
- * @returns {Promise<import('@appium/types').Size>}
43
- */
44
- async getWindowSize() {
45
- const {width, height} = await this.getWindowRect();
46
- return {width, height};
47
- },
48
- /**
49
- * Retrieves the actual device time.
50
- *
51
- * @param {string} format - The format specifier string. Read the [MomentJS documentation](https://momentjs.com/docs/) to get the full list of supported datetime format specifiers. The default format is `YYYY-MM-DDTHH:mm:ssZ`, which complies to ISO-8601.
52
- * @returns {Promise<string>} Formatted datetime string or the raw command output (if formatting fails)
53
- * @this {XCUITestDriver}
54
- */
55
- async getDeviceTime(format = MOMENT_FORMAT_ISO8601) {
56
- this.log.info('Attempting to capture iOS device date and time');
57
- if (!this.isRealDevice()) {
58
- this.log.info('On simulator. Assuming device time is the same as host time');
59
- const cmd = 'date';
60
- const args = ['+%Y-%m-%dT%H:%M:%S%z'];
61
- const inputFormat = 'YYYY-MM-DDTHH:mm:ssZZ';
62
- const stdout = (await exec(cmd, args)).stdout.trim();
63
- this.log.debug(`Got the following output out of '${cmd} ${args.join(' ')}': ${stdout}`);
64
- const parsedTimestamp = moment.utc(stdout, inputFormat);
65
- if (!parsedTimestamp.isValid()) {
66
- this.log.warn(
67
- `Cannot parse the timestamp '${stdout}' returned by '${cmd}' command. Returning it as is`,
68
- );
69
- return stdout;
70
- }
71
- // @ts-expect-error This internal prop of moment is evidently a private API
72
- return parsedTimestamp.utcOffset(parsedTimestamp._tzm || 0).format(format);
73
- }
35
+ export async function toggleEnrollTouchId(isEnabled = true) {
36
+ await this.mobileEnrollBiometric(isEnabled);
37
+ }
74
38
 
75
- const {timestamp, utcOffset, timeZone} = await utilities.getDeviceTime(this.opts.udid);
76
- this.log.debug(`timestamp: ${timestamp}, utcOffset: ${utcOffset}, timeZone: ${timeZone}`);
77
- const utc = moment.unix(timestamp).utc();
78
- // at some point of time Apple started to return timestamps
79
- // in utcOffset instead of actual UTC offsets
80
- if (Math.abs(utcOffset) <= 12 * 60) {
81
- return utc.utcOffset(utcOffset).format(format);
82
- }
83
- // timeZone could either be a time zone name or
84
- // an UTC offset in seconds
85
- if (_.includes(timeZone, '/')) {
86
- return utc.tz(timeZone).format(format);
87
- }
88
- if (Math.abs(timeZone) <= 12 * 60 * 60) {
89
- return utc.utcOffset(timeZone / 60).format(format);
39
+ /**
40
+ * Get the window size
41
+ * @this {XCUITestDriver}
42
+ * @returns {Promise<import('@appium/types').Size>}
43
+ */
44
+ export async function getWindowSize() {
45
+ const {width, height} = await this.getWindowRect();
46
+ return {width, height};
47
+ }
48
+
49
+ /**
50
+ * Retrieves the actual device time.
51
+ *
52
+ * @param {string} format - The format specifier string. Read the [MomentJS documentation](https://momentjs.com/docs/) to get the full list of supported datetime format specifiers. The default format is `YYYY-MM-DDTHH:mm:ssZ`, which complies to ISO-8601.
53
+ * @returns {Promise<string>} Formatted datetime string or the raw command output (if formatting fails)
54
+ * @this {XCUITestDriver}
55
+ */
56
+ export async function getDeviceTime(format = MOMENT_FORMAT_ISO8601) {
57
+ this.log.info('Attempting to capture iOS device date and time');
58
+ if (!this.isRealDevice()) {
59
+ this.log.info('On simulator. Assuming device time is the same as host time');
60
+ const cmd = 'date';
61
+ const args = ['+%Y-%m-%dT%H:%M:%S%z'];
62
+ const inputFormat = 'YYYY-MM-DDTHH:mm:ssZZ';
63
+ const stdout = (await exec(cmd, args)).stdout.trim();
64
+ this.log.debug(`Got the following output out of '${cmd} ${args.join(' ')}': ${stdout}`);
65
+ const parsedTimestamp = moment.utc(stdout, inputFormat);
66
+ if (!parsedTimestamp.isValid()) {
67
+ this.log.warn(
68
+ `Cannot parse the timestamp '${stdout}' returned by '${cmd}' command. Returning it as is`,
69
+ );
70
+ return stdout;
90
71
  }
91
- this.log.warn('Did not know how to apply the UTC offset. Returning the timestamp without it');
92
- return utc.format(format);
93
- },
72
+ // @ts-expect-error This internal prop of moment is evidently a private API
73
+ return parsedTimestamp.utcOffset(parsedTimestamp._tzm || 0).format(format);
74
+ }
94
75
 
95
- /**
96
- * Retrieves the current device time
97
- *
98
- * @param {string} format - See {@linkcode getDeviceTime.format}
99
- * @returns {Promise<string>} Formatted datetime string or the raw command output if formatting fails
100
- * @this {XCUITestDriver}
101
- */
102
- async mobileGetDeviceTime(format = MOMENT_FORMAT_ISO8601) {
103
- return await this.getDeviceTime(format);
104
- },
76
+ const {timestamp, utcOffset, timeZone} = await utilities.getDeviceTime(this.opts.udid);
77
+ this.log.debug(`timestamp: ${timestamp}, utcOffset: ${utcOffset}, timeZone: ${timeZone}`);
78
+ const utc = moment.unix(timestamp).utc();
79
+ // at some point of time Apple started to return timestamps
80
+ // in utcOffset instead of actual UTC offsets
81
+ if (Math.abs(utcOffset) <= 12 * 60) {
82
+ return utc.utcOffset(utcOffset).format(format);
83
+ }
84
+ // timeZone could either be a time zone name or
85
+ // an UTC offset in seconds
86
+ if (_.includes(timeZone, '/')) {
87
+ return utc.tz(timeZone).format(format);
88
+ }
89
+ if (Math.abs(timeZone) <= 12 * 60 * 60) {
90
+ return utc.utcOffset(timeZone / 60).format(format);
91
+ }
92
+ this.log.warn('Did not know how to apply the UTC offset. Returning the timestamp without it');
93
+ return utc.format(format);
94
+ }
105
95
 
106
- /**
107
- * For W3C
108
- * @this {XCUITestDriver}
109
- * @return {Promise<import('@appium/types').Rect>}
110
- */
111
- async getWindowRect() {
112
- if (this.isWebContext()) {
113
- const script = 'return {' +
114
- 'x: window.screenX || 0,' +
115
- 'y: window.screenY || 0,' +
116
- 'width: window.innerWidth,' +
117
- 'height: window.innerHeight' +
118
- '}';
119
- return await this.executeAtom('execute_script', [script]);
120
- }
96
+ /**
97
+ * Retrieves the current device time
98
+ *
99
+ * @param {string} format - See {@linkcode getDeviceTime.format}
100
+ * @returns {Promise<string>} Formatted datetime string or the raw command output if formatting fails
101
+ * @this {XCUITestDriver}
102
+ */
103
+ export async function mobileGetDeviceTime(format = MOMENT_FORMAT_ISO8601) {
104
+ return await this.getDeviceTime(format);
105
+ }
121
106
 
122
- return /** @type {import('@appium/types').Rect} */ (
123
- await this.proxyCommand('/window/rect', 'GET')
124
- );
125
- },
126
- /**
127
- * @this {XCUITestDriver}
128
- */
129
- async removeApp(bundleId) {
130
- return await this.mobileRemoveApp(bundleId);
131
- },
132
- /**
133
- * @this {XCUITestDriver}
134
- */
135
- async launchApp() {
136
- throw new Error(
137
- `The launchApp API has been deprecated and is not supported anymore. ` +
138
- `Consider using corresponding 'mobile:' extensions to manage the state of the app under test.`,
139
- );
140
- },
141
- /**
142
- * @this {XCUITestDriver}
143
- */
144
- async closeApp() {
145
- throw new Error(
146
- `The closeApp API has been deprecated and is not supported anymore. ` +
147
- `Consider using corresponding 'mobile:' extensions to manage the state of the app under test.`,
148
- );
149
- },
150
- /**
151
- * @this {XCUITestDriver}
152
- */
153
- async setUrl(url) {
154
- this.log.debug(`Attempting to set url '${url}'`);
107
+ /**
108
+ * For W3C
109
+ * @this {XCUITestDriver}
110
+ * @return {Promise<import('@appium/types').Rect>}
111
+ */
112
+ export async function getWindowRect() {
113
+ if (this.isWebContext()) {
114
+ const script = 'return {' +
115
+ 'x: window.screenX || 0,' +
116
+ 'y: window.screenY || 0,' +
117
+ 'width: window.innerWidth,' +
118
+ 'height: window.innerHeight' +
119
+ '}';
120
+ return await this.executeAtom('execute_script', [script]);
121
+ }
155
122
 
156
- if (this.isWebContext()) {
157
- this.setCurrentUrl(url);
158
- // make sure to clear out any leftover web frames
159
- this.curWebFrames = [];
160
- await (/** @type {import('appium-remote-debugger').RemoteDebugger} */ (this.remote)).navToUrl(url);
161
- return;
162
- }
123
+ return /** @type {import('@appium/types').Rect} */ (
124
+ await this.proxyCommand('/window/rect', 'GET')
125
+ );
126
+ }
163
127
 
164
- if (this.isRealDevice()) {
165
- await this.proxyCommand('/url', 'POST', {url});
166
- } else {
167
- await /** @type {import('../driver').Simulator} */ (this.device).simctl.openUrl(url);
168
- }
169
- },
170
- /**
171
- * Retrieves the viewport dimensions.
172
- *
173
- * The viewport is the device's screen size with status bar size subtracted if the latter is present/visible.
174
- * @returns {Promise<import('./types').Viewport>}
175
- * @this {XCUITestDriver}
176
- */
177
- async getViewportRect() {
178
- const scale = await this.getDevicePixelRatio();
179
- // status bar height comes in unscaled, so scale it
180
- const statusBarHeight = Math.trunc((await this.getStatusBarHeight()) * scale);
181
- const windowSize = await this.getWindowRect();
128
+ /**
129
+ * @this {XCUITestDriver}
130
+ */
131
+ export async function removeApp(bundleId) {
132
+ return await this.mobileRemoveApp(bundleId);
133
+ }
182
134
 
183
- // ios returns coordinates/dimensions in logical pixels, not device pixels,
184
- // so scale up to device pixels. status bar height is already scaled.
185
- return {
186
- left: 0,
187
- top: statusBarHeight,
188
- width: Math.trunc(windowSize.width * scale),
189
- height: Math.trunc(windowSize.height * scale) - statusBarHeight,
190
- };
191
- },
135
+ /**
136
+ * @this {XCUITestDriver}
137
+ */
138
+ export async function launchApp() {
139
+ throw new Error(
140
+ `The launchApp API has been deprecated and is not supported anymore. ` +
141
+ `Consider using corresponding 'mobile:' extensions to manage the state of the app under test.`,
142
+ );
143
+ }
192
144
 
193
- /**
194
- * Get information about the screen.
195
- *
196
- * @privateRemarks memoized in constructor
197
- * @this {XCUITestDriver}
198
- * @returns {Promise<ScreenInfo>}
199
- */
200
- async getScreenInfo() {
201
- return /** @type {ScreenInfo} */ (await this.proxyCommand('/wda/screen', 'GET'));
202
- },
203
- /**
204
- * @this {XCUITestDriver}
205
- */
206
- async getStatusBarHeight() {
207
- const {statusBarSize} = await this.getScreenInfo();
208
- return statusBarSize.height;
209
- },
145
+ /**
146
+ * @this {XCUITestDriver}
147
+ */
148
+ export async function closeApp() {
149
+ throw new Error(
150
+ `The closeApp API has been deprecated and is not supported anymore. ` +
151
+ `Consider using corresponding 'mobile:' extensions to manage the state of the app under test.`,
152
+ );
153
+ }
210
154
 
211
- /**
212
- * memoized in constructor
213
- * @this {XCUITestDriver}
214
- */
215
- async getDevicePixelRatio() {
216
- const {scale} = await this.getScreenInfo();
217
- return scale;
218
- },
155
+ /**
156
+ * @this {XCUITestDriver}
157
+ * @param {string} url
158
+ * @returns {Promise<void>}
159
+ */
160
+ export async function setUrl(url) {
161
+ this.log.debug(`Attempting to set url '${url}'`);
219
162
 
220
- /**
221
- * Emulates press action on the given physical device button.
222
- *
223
- * This executes different methods based on the platform:
224
- *
225
- * - iOS: [`pressButton:`](https://developer.apple.com/documentation/xctest/xcuidevice/1619052-pressbutton)
226
- * - tvOS: [`pressButton:`](https://developer.apple.com/documentation/xctest/xcuiremote/1627475-pressbutton) or [`pressButton:forDuration:`](https://developer.apple.com/documentation/xctest/xcuiremote/1627476-pressbutton)
227
- *
228
- * Use {@linkcode mobilePerformIoHidEvent} to call a more universal API to perform a button press with duration on any supported device.
229
- *
230
- * @param {import('./types').ButtonName} name - The name of the button to be pressed.
231
- * @param {number} [durationSeconds] - The duration of the button press in seconds (float).
232
- * @this {XCUITestDriver}
233
- */
234
- async mobilePressButton(name, durationSeconds) {
235
- if (!name) {
236
- throw new errors.InvalidArgumentError('Button name is mandatory');
237
- }
238
- if (!_.isNil(durationSeconds) && !_.isNumber(durationSeconds)) {
239
- throw new errors.InvalidArgumentError('durationSeconds should be a number');
240
- }
241
- return await this.proxyCommand('/wda/pressButton', 'POST', {name, duration: durationSeconds});
242
- },
243
- /**
244
- * Process a string as speech and send it to Siri.
245
- *
246
- * Presents the Siri UI, if it is not currently active, and accepts a string which is then processed as if it were recognized speech. See [the documentation of `activateWithVoiceRecognitionText`](https://developer.apple.com/documentation/xctest/xcuisiriservice/2852140-activatewithvoicerecognitiontext?language=objc) for more details.
163
+ if (this.isWebContext()) {
164
+ this.setCurrentUrl(url);
165
+ // make sure to clear out any leftover web frames
166
+ this.curWebFrames = [];
167
+ await (/** @type {import('appium-remote-debugger').RemoteDebugger} */ (this.remote)).navToUrl(url);
168
+ return;
169
+ }
247
170
 
248
- * @param {string} text - Text to be sent to Siri
249
- * @returns {Promise<void>}
250
- * @this {XCUITestDriver}
251
- */
252
- async mobileSiriCommand(text) {
253
- if (!text) {
254
- throw new errors.InvalidArgumentError('"text" argument is mandatory');
255
- }
256
- await this.proxyCommand('/wda/siri/activate', 'POST', {text});
257
- },
258
- };
171
+ if (this.isRealDevice()) {
172
+ await this.proxyCommand('/url', 'POST', {url});
173
+ } else {
174
+ await /** @type {import('../driver').Simulator} */ (this.device).simctl.openUrl(url);
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Retrieves the viewport dimensions.
180
+ *
181
+ * The viewport is the device's screen size with status bar size subtracted if the latter is present/visible.
182
+ * @returns {Promise<import('./types').Viewport>}
183
+ * @this {XCUITestDriver}
184
+ */
185
+ export async function getViewportRect() {
186
+ const scale = await this.getDevicePixelRatio();
187
+ // status bar height comes in unscaled, so scale it
188
+ const statusBarHeight = Math.trunc((await this.getStatusBarHeight()) * scale);
189
+ const windowSize = await this.getWindowRect();
259
190
 
260
- export default commands;
191
+ // ios returns coordinates/dimensions in logical pixels, not device pixels,
192
+ // so scale up to device pixels. status bar height is already scaled.
193
+ return {
194
+ left: 0,
195
+ top: statusBarHeight,
196
+ width: Math.trunc(windowSize.width * scale),
197
+ height: Math.trunc(windowSize.height * scale) - statusBarHeight,
198
+ };
199
+ }
200
+
201
+ /**
202
+ * Get information about the screen.
203
+ *
204
+ * @privateRemarks memoized in constructor
205
+ * @this {XCUITestDriver}
206
+ * @returns {Promise<ScreenInfo>}
207
+ */
208
+ export async function getScreenInfo() {
209
+ return /** @type {ScreenInfo} */ (await this.proxyCommand('/wda/screen', 'GET'));
210
+ }
211
+
212
+ /**
213
+ * @this {XCUITestDriver}
214
+ */
215
+ export async function getStatusBarHeight() {
216
+ const {statusBarSize} = await this.getScreenInfo();
217
+ return statusBarSize.height;
218
+ }
219
+
220
+ /**
221
+ * memoized in constructor
222
+ * @this {XCUITestDriver}
223
+ */
224
+ export async function getDevicePixelRatio() {
225
+ const {scale} = await this.getScreenInfo();
226
+ return scale;
227
+ }
228
+
229
+ /**
230
+ * Emulates press action on the given physical device button.
231
+ *
232
+ * This executes different methods based on the platform:
233
+ *
234
+ * - iOS: [`pressButton:`](https://developer.apple.com/documentation/xctest/xcuidevice/1619052-pressbutton)
235
+ * - tvOS: [`pressButton:`](https://developer.apple.com/documentation/xctest/xcuiremote/1627475-pressbutton) or [`pressButton:forDuration:`](https://developer.apple.com/documentation/xctest/xcuiremote/1627476-pressbutton)
236
+ *
237
+ * Use {@linkcode mobilePerformIoHidEvent} to call a more universal API to perform a button press with duration on any supported device.
238
+ *
239
+ * @param {import('./types').ButtonName} name - The name of the button to be pressed.
240
+ * @param {number} [durationSeconds] - The duration of the button press in seconds (float).
241
+ * @this {XCUITestDriver}
242
+ */
243
+ export async function mobilePressButton(name, durationSeconds) {
244
+ if (!name) {
245
+ throw new errors.InvalidArgumentError('Button name is mandatory');
246
+ }
247
+ if (!_.isNil(durationSeconds) && !_.isNumber(durationSeconds)) {
248
+ throw new errors.InvalidArgumentError('durationSeconds should be a number');
249
+ }
250
+ return await this.proxyCommand('/wda/pressButton', 'POST', {name, duration: durationSeconds});
251
+ }
252
+
253
+ /**
254
+ * Process a string as speech and send it to Siri.
255
+ *
256
+ * Presents the Siri UI, if it is not currently active, and accepts a string which is then processed as if it were recognized speech. See [the documentation of `activateWithVoiceRecognitionText`](https://developer.apple.com/documentation/xctest/xcuisiriservice/2852140-activatewithvoicerecognitiontext?language=objc) for more details.
257
+
258
+ * @param {string} text - Text to be sent to Siri
259
+ * @returns {Promise<void>}
260
+ * @this {XCUITestDriver}
261
+ */
262
+ export async function mobileSiriCommand(text) {
263
+ if (!text) {
264
+ throw new errors.InvalidArgumentError('"text" argument is mandatory');
265
+ }
266
+ await this.proxyCommand('/wda/siri/activate', 'POST', {text});
267
+ }
261
268
 
262
269
  /**
263
270
  * @typedef {Object} PressButtonOptions
@@ -1,5 +1,3 @@
1
- const commands = {};
2
-
3
1
  /**
4
2
  * @typedef {Object} GeolocationInfo
5
3
  * @property {number|null} latitude Measurement of distance north or south of the Equator, or
@@ -19,9 +17,9 @@ const commands = {};
19
17
  * @since 4.18
20
18
  * @this {XCUITestDriver}
21
19
  */
22
- commands.mobileGetSimulatedLocation = async function mobileGetSimulatedLocation() {
20
+ export async function mobileGetSimulatedLocation() {
23
21
  return await this.proxyCommand('/wda/simulatedLocation', 'GET');
24
- };
22
+ }
25
23
 
26
24
  /**
27
25
  * Sets simulated geolocation value.
@@ -34,12 +32,9 @@ commands.mobileGetSimulatedLocation = async function mobileGetSimulatedLocation(
34
32
  * @since 4.18
35
33
  * @this {XCUITestDriver}
36
34
  */
37
- commands.mobileSetSimulatedLocation = async function mobileSetSimulatedLocation(
38
- latitude,
39
- longitude,
40
- ) {
35
+ export async function mobileSetSimulatedLocation(latitude, longitude) {
41
36
  return await this.proxyCommand('/wda/simulatedLocation', 'POST', {latitude, longitude});
42
- };
37
+ }
43
38
 
44
39
  /**
45
40
  * Resets simulated geolocation value.
@@ -52,12 +47,9 @@ commands.mobileSetSimulatedLocation = async function mobileSetSimulatedLocation(
52
47
  * @since 4.18
53
48
  * @this {XCUITestDriver}
54
49
  */
55
- commands.mobileResetSimulatedLocation = async function mobileResetSimulatedLocation() {
50
+ export async function mobileResetSimulatedLocation() {
56
51
  return await this.proxyCommand('/wda/simulatedLocation', 'DELETE');
57
- };
58
-
59
- export {commands};
60
- export default commands;
52
+ }
61
53
 
62
54
  /**
63
55
  * @typedef {import('../driver').XCUITestDriver} XCUITestDriver