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
@@ -4,24 +4,6 @@ import _ from 'lodash';
4
4
 
5
5
  const SUPPORTED_GESTURE_DIRECTIONS = ['up', 'down', 'left', 'right'];
6
6
 
7
- /**
8
- * Converts the given value to a float number.
9
- *
10
- * @throws If `value` is `NaN`
11
- * @param {any} value
12
- * @param {string} paramName
13
- * @returns {number}
14
- */
15
- function requireFloat(value, paramName) {
16
- const num = parseFloat(String(value));
17
- if (Number.isNaN(num)) {
18
- throw new errors.InvalidArgumentError(
19
- `"${paramName}" parameter should be a valid number. "${value}" is given instead`,
20
- );
21
- }
22
- return num;
23
- }
24
-
25
7
  /**
26
8
  *
27
9
  * @param {any[]} gestures
@@ -47,519 +29,529 @@ export function gesturesChainToString(gestures, keysToInclude = ['options']) {
47
29
  .join('-');
48
30
  }
49
31
 
50
- const commands = {
51
- /**
52
- * Shake the device
53
- * @this {XCUITestDriver}
54
- * @group Simulator Only
55
- */
56
- async mobileShake() {
57
- if (!this.isSimulator()) {
58
- throw new errors.UnknownError('Shake is not supported on real devices');
59
- }
60
- await /** @type {import('../driver').Simulator} */ (this.device).shake();
61
- },
62
- /**
63
- * @this {XCUITestDriver}
64
- */
65
- async click(el) {
66
- if (!this.isWebContext()) {
67
- // there are multiple commands that map here, so manually proxy
68
- return await this.nativeClick(el);
69
- }
70
- el = util.unwrapElement(el);
71
- const {nativeWebTap, nativeWebTapStrict} = this.settings.getSettings();
72
- if (nativeWebTap || nativeWebTapStrict) {
73
- // atoms-based clicks don't always work in safari 7
74
- this.log.debug('Using native web tap');
75
- await this.nativeWebTap(el);
76
- } else {
77
- const atomsElement = this.getAtomsElement(el);
78
- // clicking can cause an alert to pop up and freeze the event loop, meaning the click atom
79
- // itself never returns. we have alert handling in `waitForAtom` but with click, we create
80
- // a special case where if a click results in an unexpected alert error, we just return
81
- // control to the client. they will encounter the error on their next command, which mirrors
82
- // the behaviour of selenium.
83
- try {
84
- return await this.executeAtom('click', [atomsElement]);
85
- } catch (err) {
86
- if (err.error === errors.UnexpectedAlertOpenError.error()) {
87
- return;
88
- }
89
- throw err;
90
- }
91
- }
92
- },
93
- /**
94
- * @this {XCUITestDriver}
95
- */
96
- async releaseActions() {
97
- this.log.warn('On this platform, releaseActions is a no-op');
98
- },
99
- /**
100
- * @param {import('@appium/types').ActionSequence[]} actions
101
- * @returns {Promise<void>}
102
- * @this {XCUITestDriver}
103
- */
104
- async performActions(actions) {
105
- this.log.debug(`Received the following W3C actions: ${JSON.stringify(actions, null, ' ')}`);
106
- assertNoWebElements(actions);
107
- // This is mandatory, since WDA only supports TOUCH pointer type
108
- // and Selenium API uses MOUSE as the default one
109
- const preprocessedActions = actions
110
- .map((action) => ({
111
- ...action,
112
- ...(action.type === 'pointer'
113
- ? {
114
- parameters: {
115
- pointerType: 'touch',
116
- },
117
- }
118
- : {}),
119
- }))
120
- .map((action) => {
121
- const modifiedAction = _.clone(action) || {};
122
- // Selenium API unexpectedly inserts zero pauses, which are not supported by WDA
123
- modifiedAction.actions = (action.actions || []).filter(
124
- (innerAction) => !(innerAction.type === 'pause' && innerAction.duration === 0),
125
- );
126
- return modifiedAction;
127
- });
128
- this.log.debug(`Preprocessed actions: ${JSON.stringify(preprocessedActions, null, ' ')}`);
129
- await this.proxyCommand('/actions', 'POST', {actions: preprocessedActions});
130
- },
131
- /**
132
- * @param {import('@appium/types').Element|string} el
133
- * @this {XCUITestDriver}
134
- * @group Native Only
135
- */
136
- async nativeClick(el) {
137
- el = util.unwrapElement(el);
138
- let endpoint = `/element/${el}/click`;
139
- return await this.proxyCommand(endpoint, 'POST', {});
140
- },
32
+ /**
33
+ * Shake the device
34
+ * @this {XCUITestDriver}
35
+ * @group Simulator Only
36
+ */
37
+ export async function mobileShake() {
38
+ if (!this.isSimulator()) {
39
+ throw new errors.UnknownError('Shake is not supported on real devices');
40
+ }
41
+ await /** @type {import('../driver').Simulator} */ (this.device).shake();
42
+ }
141
43
 
142
- /**
143
- * Scrolls the current viewport to the given element.
144
- *
145
- * This command expects the destination element to be inside a scrollable container and is hittable. The scroll direction is detected automatically.
146
- *
147
- * This API uses native XCTest calls, so it is performant. The same native call is implicitly performed by a `click` command if the destination element is outside the current viewport.
148
- *
149
- * @since 4.7.0
150
- * @throws If the scrolling action cannot be performed
151
- * @privateRemarks See https://github.com/facebook/WebDriverAgent/blob/master/WebDriverAgentLib/Commands/FBElementCommands.m for details on WDA gestures API
152
- * @param {Element|string} elementId - The internal element identifier (as hexadecimal hash string) to scroll to. The destination element must be located in a scrollable container and must be hittable. If the element is already present in the current viewport then no action is performed.
153
- * @returns {Promise<void>}
154
- * @this {XCUITestDriver}
155
- */
156
- async mobileScrollToElement(elementId) {
157
- if (!elementId) {
158
- throw new errors.InvalidArgumentError('Element id must be provided');
44
+ /**
45
+ * @this {XCUITestDriver}
46
+ */
47
+ export async function click(el) {
48
+ if (!this.isWebContext()) {
49
+ // there are multiple commands that map here, so manually proxy
50
+ return await this.nativeClick(el);
51
+ }
52
+ el = util.unwrapElement(el);
53
+ const {nativeWebTap, nativeWebTapStrict} = this.settings.getSettings();
54
+ if (nativeWebTap || nativeWebTapStrict) {
55
+ // atoms-based clicks don't always work in safari 7
56
+ this.log.debug('Using native web tap');
57
+ await this.nativeWebTap(el);
58
+ } else {
59
+ const atomsElement = this.getAtomsElement(el);
60
+ // clicking can cause an alert to pop up and freeze the event loop, meaning the click atom
61
+ // itself never returns. we have alert handling in `waitForAtom` but with click, we create
62
+ // a special case where if a click results in an unexpected alert error, we just return
63
+ // control to the client. they will encounter the error on their next command, which mirrors
64
+ // the behaviour of selenium.
65
+ try {
66
+ return await this.executeAtom('click', [atomsElement]);
67
+ } catch (err) {
68
+ if (err.error === errors.UnexpectedAlertOpenError.error()) {
69
+ return;
70
+ }
71
+ throw err;
159
72
  }
160
- return await this.proxyCommand(`/wda/element/${elementId}/scrollTo`, 'POST', {});
161
- },
162
- };
73
+ }
74
+ }
163
75
 
164
- const helpers = {
165
- /**
166
- * Scrolls an element or the entire screen.
167
- *
168
- * Use this command to emulate precise scrolling in tables or collection views where it is already known to which element the scrolling should be performed.
169
- *
170
- * The arguments define the chosen strategy: one of `name`, `direction`, `predicateString` or `toVisible`.
171
- *
172
- * **All strategies are exclusive**; only one strategy can be used at one time.
173
- *
174
- * **Known Limitations:**
175
- *
176
- * - If it is necessary to perform many scroll gestures on parent container to reach the necessary child element (tens of them), then the method call may fail. *
177
- * - The implementation of this extension relies on several undocumented XCTest features, which might not always be reliable.
178
- *
179
- * @param {string} [name] - The internal element identifier (as hexadecimal hash string) to scroll on (e.g. the container). The Application element will be used if this argument is not provided.
180
- * @param {import('./types').Direction} [direction] - The main difference between this command and a `mobile: swipe` command using the same direction is that `mobile: scroll` will attempt to move the current viewport exactly to the next or previous page (the term "page" means the content, which fits into a single device screen).
181
- * @param {string} [predicateString] - The `NSPredicate` locator of the child element, to which the scrolling should be performed. Has no effect if `elementId` is not a container.
182
- * @param {boolean} [toVisible] - If `true`, scrolls to the first visible `elementId` in the parent container. Has no effect if `elementId` is unset.
183
- * @param {number} [distance] - A ratio of the screen height; `1.0` means a full-screen-worth of scrolling.
184
- * @param {Element|string} [elementId] - Element ID or Element used in various strategies.
185
- * @returns {Promise<void>}
186
- * @this {XCUITestDriver}
187
- * @example
188
- * ```python
189
- * driver.execute_script('mobile: scroll', {'direction': 'down'})
190
- * ```
191
- */
192
- async mobileScroll(name, direction, predicateString, toVisible, distance, elementId) {
193
- /**
194
- * @todo This should be defined in WDA instead.
195
- * @typedef WdaScrollParams
196
- * @property {string} [name]
197
- * @property {import('./types').Direction} [direction]
198
- * @property {string} [predicateString]
199
- * @property {boolean} [toVisible]
200
- * @property {number} [distance]
201
- */
76
+ /**
77
+ * @this {XCUITestDriver}
78
+ */
79
+ export async function releaseActions() {
80
+ this.log.warn('On this platform, releaseActions is a no-op');
81
+ }
202
82
 
203
- /** @type {WdaScrollParams} */
204
- const params = {};
205
- if (name) {
206
- params.name = name;
207
- } else if (direction) {
208
- if (!SUPPORTED_GESTURE_DIRECTIONS.includes(_.toLower(direction))) {
209
- throw new errors.InvalidArgumentError(
210
- `'direction' must be one of: ${SUPPORTED_GESTURE_DIRECTIONS}`,
211
- );
212
- }
213
- params.direction = direction;
214
- } else if (predicateString) {
215
- params.predicateString = predicateString;
216
- } else if (toVisible) {
217
- params.toVisible = toVisible;
218
- } else {
219
- throw new errors.InvalidArgumentError(
220
- 'Mobile scroll supports the following strategies: name, direction, predicateString, and toVisible. ' +
221
- 'Specify one of these',
83
+ /**
84
+ * @param {import('@appium/types').ActionSequence[]} actions
85
+ * @returns {Promise<void>}
86
+ * @this {XCUITestDriver}
87
+ */
88
+ export async function performActions(actions) {
89
+ this.log.debug(`Received the following W3C actions: ${JSON.stringify(actions, null, ' ')}`);
90
+ assertNoWebElements(actions);
91
+ // This is mandatory, since WDA only supports TOUCH pointer type
92
+ // and Selenium API uses MOUSE as the default one
93
+ const preprocessedActions = actions
94
+ .map((action) => ({
95
+ ...action,
96
+ ...(action.type === 'pointer'
97
+ ? {
98
+ parameters: {
99
+ pointerType: 'touch',
100
+ },
101
+ }
102
+ : {}),
103
+ }))
104
+ .map((action) => {
105
+ const modifiedAction = _.clone(action) || {};
106
+ // Selenium API unexpectedly inserts zero pauses, which are not supported by WDA
107
+ modifiedAction.actions = (action.actions || []).filter(
108
+ (innerAction) => !(innerAction.type === 'pause' && innerAction.duration === 0),
222
109
  );
223
- }
224
- // we can also optionally pass a distance which appears to be a ratio of
225
- // screen height, so 1.0 means a full screen's worth of scrolling
226
- if (!_.isNil(distance)) {
227
- params.distance = distance;
228
- }
229
- const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/scroll` : '/wda/scroll';
230
- return await this.proxyCommand(endpoint, 'POST', params);
231
- },
110
+ return modifiedAction;
111
+ });
112
+ this.log.debug(`Preprocessed actions: ${JSON.stringify(preprocessedActions, null, ' ')}`);
113
+ await this.proxyCommand('/actions', 'POST', {actions: preprocessedActions});
114
+ }
115
+
116
+ /**
117
+ * @param {import('@appium/types').Element|string} el
118
+ * @this {XCUITestDriver}
119
+ * @group Native Only
120
+ */
121
+ export async function nativeClick(el) {
122
+ el = util.unwrapElement(el);
123
+ let endpoint = `/element/${el}/click`;
124
+ return await this.proxyCommand(endpoint, 'POST', {});
125
+ }
126
+
127
+ /**
128
+ * Scrolls the current viewport to the given element.
129
+ *
130
+ * This command expects the destination element to be inside a scrollable container and is hittable. The scroll direction is detected automatically.
131
+ *
132
+ * This API uses native XCTest calls, so it is performant. The same native call is implicitly performed by a `click` command if the destination element is outside the current viewport.
133
+ *
134
+ * @since 4.7.0
135
+ * @throws If the scrolling action cannot be performed
136
+ * @privateRemarks See https://github.com/facebook/WebDriverAgent/blob/master/WebDriverAgentLib/Commands/FBElementCommands.m for details on WDA gestures API
137
+ * @param {Element|string} elementId - The internal element identifier (as hexadecimal hash string) to scroll to. The destination element must be located in a scrollable container and must be hittable. If the element is already present in the current viewport then no action is performed.
138
+ * @returns {Promise<void>}
139
+ * @this {XCUITestDriver}
140
+ */
141
+ export async function mobileScrollToElement(elementId) {
142
+ if (!elementId) {
143
+ throw new errors.InvalidArgumentError('Element id must be provided');
144
+ }
145
+ return await this.proxyCommand(`/wda/element/${elementId}/scrollTo`, 'POST', {});
146
+ }
147
+
148
+ /**
149
+ * Scrolls an element or the entire screen.
150
+ *
151
+ * Use this command to emulate precise scrolling in tables or collection views where it is already known to which element the scrolling should be performed.
152
+ *
153
+ * The arguments define the chosen strategy: one of `name`, `direction`, `predicateString` or `toVisible`.
154
+ *
155
+ * **All strategies are exclusive**; only one strategy can be used at one time.
156
+ *
157
+ * **Known Limitations:**
158
+ *
159
+ * - If it is necessary to perform many scroll gestures on parent container to reach the necessary child element (tens of them), then the method call may fail. *
160
+ * - The implementation of this extension relies on several undocumented XCTest features, which might not always be reliable.
161
+ *
162
+ * @param {string} [name] - The internal element identifier (as hexadecimal hash string) to scroll on (e.g. the container). The Application element will be used if this argument is not provided.
163
+ * @param {import('./types').Direction} [direction] - The main difference between this command and a `mobile: swipe` command using the same direction is that `mobile: scroll` will attempt to move the current viewport exactly to the next or previous page (the term "page" means the content, which fits into a single device screen).
164
+ * @param {string} [predicateString] - The `NSPredicate` locator of the child element, to which the scrolling should be performed. Has no effect if `elementId` is not a container.
165
+ * @param {boolean} [toVisible] - If `true`, scrolls to the first visible `elementId` in the parent container. Has no effect if `elementId` is unset.
166
+ * @param {number} [distance] - A ratio of the screen height; `1.0` means a full-screen-worth of scrolling.
167
+ * @param {Element|string} [elementId] - Element ID or Element used in various strategies.
168
+ * @returns {Promise<void>}
169
+ * @this {XCUITestDriver}
170
+ * @example
171
+ * ```python
172
+ * driver.execute_script('mobile: scroll', {'direction': 'down'})
173
+ * ```
174
+ */
175
+ export async function mobileScroll(name, direction, predicateString, toVisible, distance, elementId) {
232
176
  /**
233
- * @param {import('./types').Direction} direction
234
- * @param {number} [velocity]
235
- * @param {Element|string} [elementId]
236
- * @this {XCUITestDriver}
177
+ * @todo This should be defined in WDA instead.
178
+ * @typedef WdaScrollParams
179
+ * @property {string} [name]
180
+ * @property {import('./types').Direction} [direction]
181
+ * @property {string} [predicateString]
182
+ * @property {boolean} [toVisible]
183
+ * @property {number} [distance]
237
184
  */
238
- async mobileSwipe(direction, velocity, elementId) {
185
+
186
+ /** @type {WdaScrollParams} */
187
+ const params = {};
188
+ if (name) {
189
+ params.name = name;
190
+ } else if (direction) {
239
191
  if (!SUPPORTED_GESTURE_DIRECTIONS.includes(_.toLower(direction))) {
240
192
  throw new errors.InvalidArgumentError(
241
193
  `'direction' must be one of: ${SUPPORTED_GESTURE_DIRECTIONS}`,
242
194
  );
243
195
  }
244
- const params = {direction};
245
- if (!_.isNil(velocity)) {
246
- params.velocity = velocity;
247
- }
248
- const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/swipe` : '/wda/swipe';
249
- await this.proxyCommand(endpoint, 'POST', params);
250
- },
251
- /**
252
- * Performs a pinch gesture on the given element or on the Application element.
253
- *
254
- * @param {number} scale - Pinch scale (float value). A value between `0` and `1` performs a "pinch close" (or "zoom out"); a value greater than `1` performs a "pinch open" ("zoom in").
255
- * @param {number} velocity - The velocity of the pinch in scale factor per second (float value).
256
- * @param {Element|string} [elementId] The internal element identifier (as hexadecimal hash string) to pinch on. The Application element will be used if this parameter is not provided.
257
- * @returns {Promise<void>}
258
- * @this {XCUITestDriver}
259
- * @see https://developer.apple.com/documentation/xctest/xcuielement/1618669-pinchwithscale?language=objc
260
- * @example
261
- *
262
- * ```ruby
263
- * execute_script 'mobile: pinch', scale: 0.5, velocity: 1.1, element: element.ref
264
- * ```
265
- */
266
- async mobilePinch(scale, velocity, elementId) {
267
- const params = {
268
- scale: requireFloat(scale, 'scale'),
269
- velocity: requireFloat(velocity, 'velocity'),
270
- };
271
- const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/pinch` : '/wda/pinch';
272
- await this.proxyCommand(endpoint, 'POST', params);
273
- },
274
- /**
275
- * Performs double tap gesture on the given element or on the screen.
276
- *
277
- * @param {Element|string} [elementId] - The internal element identifier (as hexadecimal hash string) to double tap on. The Application element will be used if this parameter is not provided.
278
- * @param {number} [x] - The _x_ coordinate (float value) to double tap on.
279
- * @param {number} [y] - The _y_ coordinate (float value) to double tap on.
280
- * @returns {Promise<void>}
281
- * @this {XCUITestDriver}
282
- * @example
283
- * ```javascript
284
- * // using WebdriverIO
285
- * await driver.execute('mobile: doubleTap', {element: element.value.ELEMENT});
286
- * ```
287
- */
288
- async mobileDoubleTap(elementId, x, y) {
289
- const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/doubleTap` : '/wda/doubleTap';
290
- await this.proxyCommand(endpoint, 'POST', {x, y});
291
- },
292
- /**
293
- * Performs two finger tap gesture on the given element or on the application element.
294
- *
295
- * @param {Element|string} [elementId] - The internal element identifier (as hexadecimal hash string) to double tap on. The Application element will be used if this parameter is not provided.
296
- * @returns {Promise<void>}
297
- * @this {XCUITestDriver}
298
- * @see https://developer.apple.com/documentation/xctest/xcuielement/1618675-twofingertap?language=objc
299
- * @example
300
- * ```csharp
301
- * Dictionary<string, object> tfTap = new Dictionary<string, object>();
302
- * tfTap.Add("element", element.Id);
303
- * ((IJavaScriptExecutor)driver).ExecuteScript("mobile: twoFingerTap", tfTap);
304
- * ```
305
- */
306
- async mobileTwoFingerTap(elementId) {
307
- const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/twoFingerTap` : '/wda/twoFingerTap';
308
- await this.proxyCommand(endpoint, 'POST');
309
- },
310
- /**
311
- * Performs a "long press" gesture on the given element or on the screen.
312
- *
313
- * @param {number} duration - The duration (in seconds) of the gesture.
314
- * @param {number} [y] - The _y_ coordinate (float value) to hold on.
315
- * @param {number} [x] - The _x_ coordinate (float value) to hold on.
316
- * @param {Element|string} [elementId] - The internal element identifier (as hexadecimal hash string) to double tap on. The Application element will be used if this parameter is not provided.
317
- * @this {XCUITestDriver}
318
- * @see https://developer.apple.com/documentation/xctest/xcuielement/1618663-pressforduration?language=objc
319
- * @example
320
- * ```csharp
321
- * Dictionary<string, object> tfLongTap = new Dictionary<string, object>();
322
- * tfLongTap.Add("element", element.Id);
323
- * tfLongTap.Add("duration", 2.0);
324
- * ((IJavaScriptExecutor)driver).ExecuteScript("mobile: touchAndHold", tfLongTap);
325
- * ```
326
- */
327
- async mobileTouchAndHold(duration, x, y, elementId) {
328
- const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/touchAndHold` : '/wda/touchAndHold';
329
- await this.proxyCommand(endpoint, 'POST', {
330
- duration: requireFloat(duration, 'duration'),
331
- x, y,
332
- });
333
- },
334
- /**
335
- * Performs tap gesture by coordinates on the given element or on the screen.
336
- *
337
- * @param {number} x - The _x_ coordinate (float value) to tap on. If `elementId` is provided, this is computed relative to the element; otherwise it is computed relative to the active Application element.
338
- * @param {number} y - The _y_ coordinate (float value) to tap on. If `elementId` is provided, this is computed relative to the element; otherwise it is computed relative to the active Application element.
339
- * @param {string|Element} [elementId] - The internal element identifier (as hexadecimal hash string) to tap on. The Application element will be used if this parameter is not provided.
340
- * @this {XCUITestDriver}
341
- * @returns {Promise<void>}
342
- */
343
- async mobileTap(x, y, elementId) {
344
- const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/tap` : '/wda/tap';
345
- await this.proxyCommand(endpoint, 'POST', {x, y});
346
- },
347
- /**
348
- * Performs drag and drop gesture by coordinates on the given element or on the screen.
349
- *
350
- * @param {number} duration - The duration (in seconds) of the gesture. Must be between `0.5` and `60.0`, inclusive.
351
- * @param {number} fromX - The _x_ coordinate (float value) of the starting drag point.
352
- * @param {number} fromY - The _y_ coordinate (float value) of the starting drag point.
353
- * @param {number} toX - The _x_ coordinate (float value) of the ending drag point.
354
- * @param {number} toY - The _y_ coordinate (float value) of the ending drag point.
355
- * @param {string|Element} [elementId] - The internal element identifier (as hexadecimal hash string) to drag. If provided, all coordinates will be calculated relative to this element; otherwise they will be calculated relative to the active Application element.
356
- * @returns {Promise<void>}
357
- * @see https://developer.apple.com/documentation/xctest/xcuielement/1500989-clickforduration?language=objc
358
- * @this {XCUITestDriver}
359
- * @example
360
- * ```java
361
- * JavascriptExecutor js = (JavascriptExecutor) driver;
362
- * Map<String, Object> params = new HashMap<>();
363
- * params.put("duration", 1.0);
364
- * params.put("fromX", 100);
365
- * params.put("fromY", 100);
366
- * params.put("toX", 200);
367
- * params.put("toY", 200);
368
- * params.put("element", ((RemoteWebElement) element).getId());
369
- * js.executeScript("mobile: dragFromToForDuration", params);
370
- * ```
371
- */
372
- async mobileDragFromToForDuration(duration, fromX, fromY, toX, toY, elementId) {
373
- const params = {
374
- duration: requireFloat(duration, 'duration'),
375
- fromX: requireFloat(fromX, 'fromX'),
376
- fromY: requireFloat(fromY, 'fromY'),
377
- toX: requireFloat(toX, 'toX'),
378
- toY: requireFloat(toY, 'toY'),
379
- };
380
- return elementId
381
- ? // Drag element
382
- await this.proxyCommand(`/wda/element/${util.unwrapElement(elementId)}/dragfromtoforduration`, 'POST', params)
383
- : // Drag coordinates
384
- await this.proxyCommand('/wda/dragfromtoforduration', 'POST', params);
385
- },
386
- /**
387
- * Initiates a press-and-hold gesture, drags to another coordinate or an element with a given velocity, and holds for a given duration.
388
- *
389
- * @param {number} pressDuration - The duration (in seconds) of the press-and-hold gesture at the starting point. Must be between `0.5` and `60.0`, inclusive.
390
- * @param {number} holdDuration - The duration (in seconds) of the hold gesture at the ending point (after dragging). Must be between `0.5` and `60.0`, inclusive.
391
- * @param {number} velocity - The speed (in pixels-per-second) which to move from the initial position to the end position.
392
- * @param {string|Element} [fromElementId] - The internal element identifier (as hexadecimal hash string) to drag from. Absolute screen coordinates are expected if this argument is not provided.
393
- * @param {string|Element} [toElementId] - The internal element identifier (as hexadecimal hash string) to drag to. Absolute screen coordinates are expected if this argument is not provided.
394
- * @param {number} [fromX] - The _x_ coordinate (float value) of the starting drag point.
395
- * @param {number} [fromY] - The _y_ coordinate (float value) of the starting drag point.
396
- * @param {number} [toX] - The _x_ coordinate (float value) of the ending drag point.
397
- * @param {number} [toY] - The _y_ coordinate (float value) of the ending drag point.
398
- * @returns {Promise<void>}
399
- * @see https://developer.apple.com/documentation/xctest/xcuielement/3551693-pressforduration?language=objc
400
- * @see https://developer.apple.com/documentation/xctest/xcuicoordinate/3551692-pressforduration?language=objc
401
- * @this {XCUITestDriver}
402
- */
403
- async mobileDragFromToWithVelocity(
404
- pressDuration,
405
- holdDuration,
406
- velocity,
407
- fromElementId,
408
- toElementId,
409
- fromX,
410
- fromY,
411
- toX,
412
- toY,
413
- ) {
414
- const params = {
415
- pressDuration: requireFloat(pressDuration, 'pressDuration'),
416
- holdDuration: requireFloat(holdDuration, 'holdDuration'),
417
- velocity: requireFloat(velocity, 'velocity'),
418
- };
419
- fromElementId = fromElementId ? util.unwrapElement(fromElementId) : undefined;
420
- if (fromElementId) {
421
- toElementId = toElementId ? util.unwrapElement(toElementId) : undefined;
422
- if (!toElementId) {
423
- throw new errors.InvalidArgumentError(
424
- `"toElementId" parameter is mandatory for "dragFromToWithVelocity" call`,
425
- );
426
- }
427
- params.toElement = toElementId;
428
- return await this.proxyCommand(
429
- `/wda/element/${fromElementId}/pressAndDragWithVelocity`,
430
- 'POST',
431
- params,
432
- );
433
- }
434
- params.fromX = requireFloat(fromX, 'fromX');
435
- params.fromY = requireFloat(fromY, 'fromY');
436
- params.toX = requireFloat(toX, 'toX');
437
- params.toY = requireFloat(toY, 'toY');
438
- return await this.proxyCommand('/wda/pressAndDragWithVelocity', 'POST', params);
439
- },
440
- /**
441
- * Sends one or more taps with one or more touch points.
442
- *
443
- * @since 1.17.1
444
- * @param {number} [numberOfTaps=1] - Number of taps to perform.
445
- * @param {number} [numberOfTouches=1] - Number of touch points to use.
446
- * @param {string|Element} [elementId] - The internal element identifier (as hexadecimal hash string) to perform one or more taps.
447
- * The Application element will be used if this parameter is not provided.
448
- * @returns {Promise<void>}
449
- * @this {XCUITestDriver}
450
- * @see https://developer.apple.com/documentation/xctest/xcuielement/1618671-tapwithnumberoftaps?language=objc
451
- * @example
452
- * ```ruby
453
- * e = @driver.find_element :id, 'target element'
454
- * # Taps the element with a single touch point twice
455
- * @driver.execute_script 'mobile: tapWithNumberOfTaps', {element: e.ref, numberOfTaps: 2, numberOfTouches: 1}
456
- * ```
457
- */
458
- async mobileTapWithNumberOfTaps(numberOfTouches = 1, numberOfTaps = 1, elementId = undefined) {
459
- const endpoint = elementId
460
- ? `/wda/element/${util.unwrapElement(elementId)}/tapWithNumberOfTaps`
461
- : '/wda/tapWithNumberOfTaps';
462
- return await this.proxyCommand(endpoint, 'POST', {
463
- numberOfTaps,
464
- numberOfTouches,
465
- });
466
- },
467
- /**
468
- * Performs a "force press" on the given element or coordinates.
469
- *
470
- * @throws If the target device does not support the "force press" gesture.
471
- * @param {number} [x] - The _x_ coordinate of the gesture. If `elementId` is set, this is calculated relative to its position; otherwise it's calculated relative to the active Application.
472
- * @param {number} [y] - The _y_ coordinate of the gesture. If `elementId` is set, this is calculated relative to its position; otherwise it's calculated relative to the active Application.
473
- * @param {number} [duration] - The duration (in seconds) of the force press. If this is provided, `pressure` must also be provided.
474
- * @param {number} [pressure] - A float value defining the pressure of the force press. If this is provided, `duration` must also be provided.
475
- * @param {string|Element} [elementId] - The internal element identifier (as hexadecimal hash string) to perform one or more taps.
476
- * The Application element will be used if this parameter is not provided.
477
- * @returns {Promise<void>}
478
- * @this {XCUITestDriver}
479
- */
480
- async mobileForcePress(x, y, duration, pressure, elementId) {
481
- const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/forceTouch` : `/wda/forceTouch`;
482
- return await this.proxyCommand(endpoint, 'POST', {x, y, duration, pressure});
483
- },
484
- /**
485
- * Performs selection of the next or previous picker wheel value.
486
- *
487
- * This might be useful if these values are populated dynamically; you don't know which one to select, or the value selection using the `sendKeys` API does not work (for whatever reason).
488
- *
489
- * @throws Upon failure to change the current picker value.
490
- * @param {string|Element} elementId - `PickerWheel`'s internal element ID as hexadecimal hash string. Value selection will be performed on this element. This element must be of type `XCUIElementTypePickerWheel`.
491
- * @param {'next'|'previous'} order - Either `next` to select the value _next_ to the current from the target picker wheel, or `previous` to select the _previous_ value.
492
- * @param {number} [offset=0.2] - The value in range `[0.01, 0.5]`. It defines how far from picker wheel's center the click should happen. The actual distance is calculated by multiplying this value to the actual picker wheel height. Too small an offset value may not change the picker wheel value at all, and too high a value may cause the wheel to switch two or more values at once. Usually the optimal value is located in range `[0.15, 0.3]`.
493
- * @param {string?} [value=undefined] - If provided WDA will try to automatically scroll in the given direction until the actual picker value reaches the expected one or the amount of scrolling attempts is exceeded.
494
- * @param {number} [maxAttempts=25] - The maximum number of scrolling attempts to reach `value` before an error will be thrown. Only makes sense in combination with `value`.
495
- * @this {XCUITestDriver}
496
- * @example
497
- * ```java
498
- * JavascriptExecutor js = (JavascriptExecutor) driver;
499
- * Map<String, Object> params = new HashMap<>();
500
- * params.put("order", "next");
501
- * params.put("offset", 0.15);
502
- * params.put("element", ((RemoteWebElement) element).getId());
503
- * js.executeScript("mobile: selectPickerWheelValue", params);
504
- * ```
505
- */
506
- async mobileSelectPickerWheelValue(elementId, order, offset, value, maxAttempts) {
507
- if (!elementId) {
508
- throw new errors.InvalidArgumentError(
509
- 'elementId is expected to be set for selectPickerWheelValue method',
510
- );
511
- }
512
- if (!_.isString(order) || !['next', 'previous'].includes(order.toLowerCase())) {
196
+ params.direction = direction;
197
+ } else if (predicateString) {
198
+ params.predicateString = predicateString;
199
+ } else if (toVisible) {
200
+ params.toVisible = toVisible;
201
+ } else {
202
+ throw new errors.InvalidArgumentError(
203
+ 'Mobile scroll supports the following strategies: name, direction, predicateString, and toVisible. ' +
204
+ 'Specify one of these',
205
+ );
206
+ }
207
+ // we can also optionally pass a distance which appears to be a ratio of
208
+ // screen height, so 1.0 means a full screen's worth of scrolling
209
+ if (!_.isNil(distance)) {
210
+ params.distance = distance;
211
+ }
212
+ const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/scroll` : '/wda/scroll';
213
+ return await this.proxyCommand(endpoint, 'POST', params);
214
+ }
215
+
216
+ /**
217
+ * @param {import('./types').Direction} direction
218
+ * @param {number} [velocity]
219
+ * @param {Element|string} [elementId]
220
+ * @this {XCUITestDriver}
221
+ */
222
+ export async function mobileSwipe(direction, velocity, elementId) {
223
+ if (!SUPPORTED_GESTURE_DIRECTIONS.includes(_.toLower(direction))) {
224
+ throw new errors.InvalidArgumentError(
225
+ `'direction' must be one of: ${SUPPORTED_GESTURE_DIRECTIONS}`,
226
+ );
227
+ }
228
+ const params = {direction};
229
+ if (!_.isNil(velocity)) {
230
+ params.velocity = velocity;
231
+ }
232
+ const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/swipe` : '/wda/swipe';
233
+ await this.proxyCommand(endpoint, 'POST', params);
234
+ }
235
+
236
+ /**
237
+ * Performs a pinch gesture on the given element or on the Application element.
238
+ *
239
+ * @param {number} scale - Pinch scale (float value). A value between `0` and `1` performs a "pinch close" (or "zoom out"); a value greater than `1` performs a "pinch open" ("zoom in").
240
+ * @param {number} velocity - The velocity of the pinch in scale factor per second (float value).
241
+ * @param {Element|string} [elementId] The internal element identifier (as hexadecimal hash string) to pinch on. The Application element will be used if this parameter is not provided.
242
+ * @returns {Promise<void>}
243
+ * @this {XCUITestDriver}
244
+ * @see https://developer.apple.com/documentation/xctest/xcuielement/1618669-pinchwithscale?language=objc
245
+ * @example
246
+ *
247
+ * ```ruby
248
+ * execute_script 'mobile: pinch', scale: 0.5, velocity: 1.1, element: element.ref
249
+ * ```
250
+ */
251
+ export async function mobilePinch(scale, velocity, elementId) {
252
+ const params = {
253
+ scale: requireFloat(scale, 'scale'),
254
+ velocity: requireFloat(velocity, 'velocity'),
255
+ };
256
+ const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/pinch` : '/wda/pinch';
257
+ await this.proxyCommand(endpoint, 'POST', params);
258
+ }
259
+
260
+ /**
261
+ * Performs double tap gesture on the given element or on the screen.
262
+ *
263
+ * @param {Element|string} [elementId] - The internal element identifier (as hexadecimal hash string) to double tap on. The Application element will be used if this parameter is not provided.
264
+ * @param {number} [x] - The _x_ coordinate (float value) to double tap on.
265
+ * @param {number} [y] - The _y_ coordinate (float value) to double tap on.
266
+ * @returns {Promise<void>}
267
+ * @this {XCUITestDriver}
268
+ * @example
269
+ * ```javascript
270
+ * // using WebdriverIO
271
+ * await driver.execute('mobile: doubleTap', {element: element.value.ELEMENT});
272
+ * ```
273
+ */
274
+ export async function mobileDoubleTap(elementId, x, y) {
275
+ const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/doubleTap` : '/wda/doubleTap';
276
+ await this.proxyCommand(endpoint, 'POST', {x, y});
277
+ }
278
+
279
+ /**
280
+ * Performs two finger tap gesture on the given element or on the application element.
281
+ *
282
+ * @param {Element|string} [elementId] - The internal element identifier (as hexadecimal hash string) to double tap on. The Application element will be used if this parameter is not provided.
283
+ * @returns {Promise<void>}
284
+ * @this {XCUITestDriver}
285
+ * @see https://developer.apple.com/documentation/xctest/xcuielement/1618675-twofingertap?language=objc
286
+ * @example
287
+ * ```csharp
288
+ * Dictionary<string, object> tfTap = new Dictionary<string, object>();
289
+ * tfTap.Add("element", element.Id);
290
+ * ((IJavaScriptExecutor)driver).ExecuteScript("mobile: twoFingerTap", tfTap);
291
+ * ```
292
+ */
293
+ export async function mobileTwoFingerTap(elementId) {
294
+ const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/twoFingerTap` : '/wda/twoFingerTap';
295
+ await this.proxyCommand(endpoint, 'POST');
296
+ }
297
+
298
+ /**
299
+ * Performs a "long press" gesture on the given element or on the screen.
300
+ *
301
+ * @param {number} duration - The duration (in seconds) of the gesture.
302
+ * @param {number} [y] - The _y_ coordinate (float value) to hold on.
303
+ * @param {number} [x] - The _x_ coordinate (float value) to hold on.
304
+ * @param {Element|string} [elementId] - The internal element identifier (as hexadecimal hash string) to double tap on. The Application element will be used if this parameter is not provided.
305
+ * @this {XCUITestDriver}
306
+ * @see https://developer.apple.com/documentation/xctest/xcuielement/1618663-pressforduration?language=objc
307
+ * @example
308
+ * ```csharp
309
+ * Dictionary<string, object> tfLongTap = new Dictionary<string, object>();
310
+ * tfLongTap.Add("element", element.Id);
311
+ * tfLongTap.Add("duration", 2.0);
312
+ * ((IJavaScriptExecutor)driver).ExecuteScript("mobile: touchAndHold", tfLongTap);
313
+ * ```
314
+ */
315
+ export async function mobileTouchAndHold(duration, x, y, elementId) {
316
+ const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/touchAndHold` : '/wda/touchAndHold';
317
+ await this.proxyCommand(endpoint, 'POST', {
318
+ duration: requireFloat(duration, 'duration'),
319
+ x, y,
320
+ });
321
+ }
322
+
323
+ /**
324
+ * Performs tap gesture by coordinates on the given element or on the screen.
325
+ *
326
+ * @param {number} x - The _x_ coordinate (float value) to tap on. If `elementId` is provided, this is computed relative to the element; otherwise it is computed relative to the active Application element.
327
+ * @param {number} y - The _y_ coordinate (float value) to tap on. If `elementId` is provided, this is computed relative to the element; otherwise it is computed relative to the active Application element.
328
+ * @param {string|Element} [elementId] - The internal element identifier (as hexadecimal hash string) to tap on. The Application element will be used if this parameter is not provided.
329
+ * @this {XCUITestDriver}
330
+ * @returns {Promise<void>}
331
+ */
332
+ export async function mobileTap(x, y, elementId) {
333
+ const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/tap` : '/wda/tap';
334
+ await this.proxyCommand(endpoint, 'POST', {x, y});
335
+ }
336
+
337
+ /**
338
+ * Performs drag and drop gesture by coordinates on the given element or on the screen.
339
+ *
340
+ * @param {number} duration - The duration (in seconds) of the gesture. Must be between `0.5` and `60.0`, inclusive.
341
+ * @param {number} fromX - The _x_ coordinate (float value) of the starting drag point.
342
+ * @param {number} fromY - The _y_ coordinate (float value) of the starting drag point.
343
+ * @param {number} toX - The _x_ coordinate (float value) of the ending drag point.
344
+ * @param {number} toY - The _y_ coordinate (float value) of the ending drag point.
345
+ * @param {string|Element} [elementId] - The internal element identifier (as hexadecimal hash string) to drag. If provided, all coordinates will be calculated relative to this element; otherwise they will be calculated relative to the active Application element.
346
+ * @returns {Promise<void>}
347
+ * @see https://developer.apple.com/documentation/xctest/xcuielement/1500989-clickforduration?language=objc
348
+ * @this {XCUITestDriver}
349
+ * @example
350
+ * ```java
351
+ * JavascriptExecutor js = (JavascriptExecutor) driver;
352
+ * Map<String, Object> params = new HashMap<>();
353
+ * params.put("duration", 1.0);
354
+ * params.put("fromX", 100);
355
+ * params.put("fromY", 100);
356
+ * params.put("toX", 200);
357
+ * params.put("toY", 200);
358
+ * params.put("element", ((RemoteWebElement) element).getId());
359
+ * js.executeScript("mobile: dragFromToForDuration", params);
360
+ * ```
361
+ */
362
+ export async function mobileDragFromToForDuration(duration, fromX, fromY, toX, toY, elementId) {
363
+ const params = {
364
+ duration: requireFloat(duration, 'duration'),
365
+ fromX: requireFloat(fromX, 'fromX'),
366
+ fromY: requireFloat(fromY, 'fromY'),
367
+ toX: requireFloat(toX, 'toX'),
368
+ toY: requireFloat(toY, 'toY'),
369
+ };
370
+ return elementId
371
+ ? // Drag element
372
+ await this.proxyCommand(`/wda/element/${util.unwrapElement(elementId)}/dragfromtoforduration`, 'POST', params)
373
+ : // Drag coordinates
374
+ await this.proxyCommand('/wda/dragfromtoforduration', 'POST', params);
375
+ }
376
+
377
+ /**
378
+ * Initiates a press-and-hold gesture, drags to another coordinate or an element with a given velocity, and holds for a given duration.
379
+ *
380
+ * @param {number} pressDuration - The duration (in seconds) of the press-and-hold gesture at the starting point. Must be between `0.5` and `60.0`, inclusive.
381
+ * @param {number} holdDuration - The duration (in seconds) of the hold gesture at the ending point (after dragging). Must be between `0.5` and `60.0`, inclusive.
382
+ * @param {number} velocity - The speed (in pixels-per-second) which to move from the initial position to the end position.
383
+ * @param {string|Element} [fromElementId] - The internal element identifier (as hexadecimal hash string) to drag from. Absolute screen coordinates are expected if this argument is not provided.
384
+ * @param {string|Element} [toElementId] - The internal element identifier (as hexadecimal hash string) to drag to. Absolute screen coordinates are expected if this argument is not provided.
385
+ * @param {number} [fromX] - The _x_ coordinate (float value) of the starting drag point.
386
+ * @param {number} [fromY] - The _y_ coordinate (float value) of the starting drag point.
387
+ * @param {number} [toX] - The _x_ coordinate (float value) of the ending drag point.
388
+ * @param {number} [toY] - The _y_ coordinate (float value) of the ending drag point.
389
+ * @returns {Promise<void>}
390
+ * @see https://developer.apple.com/documentation/xctest/xcuielement/3551693-pressforduration?language=objc
391
+ * @see https://developer.apple.com/documentation/xctest/xcuicoordinate/3551692-pressforduration?language=objc
392
+ * @this {XCUITestDriver}
393
+ */
394
+ export async function mobileDragFromToWithVelocity(
395
+ pressDuration,
396
+ holdDuration,
397
+ velocity,
398
+ fromElementId,
399
+ toElementId,
400
+ fromX,
401
+ fromY,
402
+ toX,
403
+ toY,
404
+ ) {
405
+ const params = {
406
+ pressDuration: requireFloat(pressDuration, 'pressDuration'),
407
+ holdDuration: requireFloat(holdDuration, 'holdDuration'),
408
+ velocity: requireFloat(velocity, 'velocity'),
409
+ };
410
+ fromElementId = fromElementId ? util.unwrapElement(fromElementId) : undefined;
411
+ if (fromElementId) {
412
+ toElementId = toElementId ? util.unwrapElement(toElementId) : undefined;
413
+ if (!toElementId) {
513
414
  throw new errors.InvalidArgumentError(
514
- `The mandatory 'order' parameter is expected to be equal either to 'next' or 'previous'. ` +
515
- `'${order}' is given instead`,
415
+ `"toElementId" parameter is mandatory for "dragFromToWithVelocity" call`,
516
416
  );
517
417
  }
518
- const params = {order};
519
- if (offset) {
520
- params.offset = requireFloat(offset, 'offset');
521
- }
522
- if (!_.isNil(value)) {
523
- params.value = value;
524
- }
525
- if (!_.isNil(maxAttempts)) {
526
- params.maxAttempts = maxAttempts;
527
- }
528
- return await this.proxyCommand(`/wda/pickerwheel/${util.unwrapElement(elementId)}/select`, 'POST', params);
529
- },
530
- /**
531
- * Performs a rotate gesture on the given element.
532
- *
533
- * @see https://developer.apple.com/documentation/xctest/xcuielement/1618665-rotate?language=objc
534
- * @param {number} rotation - The rotation gesture (in radians)
535
- * @param {number} velocity - The velocity (in radians-per-second) of the gesture.
536
- * @param {string|Element} [elementId] - The internal element identifier (as hexadecimal hash string) to perform the gesture on.
537
- * The Application element will be used if this parameter is not provided.
538
- * @returns {Promise<void>}
539
- * @this {XCUITestDriver}
540
- * @example
541
- * ```java
542
- * JavascriptExecutor js = (JavascriptExecutor) driver;
543
- * js.executeScript("mobile: rotateElement", ImmutableMap.of(
544
- * // rotate clockwise, 90 degrees
545
- * "rotation", -Math.PI / 2,
546
- * // in approximately two seconds
547
- * "velocity", Math.PI / 4,
548
- * "element", ((RemoteWebElement) element).getId()
549
- * ));
550
- * ```
551
- */
552
- async mobileRotateElement(rotation, velocity, elementId) {
553
- const params = {
554
- rotation: requireFloat(rotation, 'rotation'),
555
- velocity: requireFloat(velocity, 'velocity'),
556
- };
557
- const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/rotate` : '/wda/rotate';
558
- return await this.proxyCommand(endpoint, 'POST', params);
559
- },
560
- };
418
+ params.toElement = toElementId;
419
+ return await this.proxyCommand(
420
+ `/wda/element/${fromElementId}/pressAndDragWithVelocity`,
421
+ 'POST',
422
+ params,
423
+ );
424
+ }
425
+ params.fromX = requireFloat(fromX, 'fromX');
426
+ params.fromY = requireFloat(fromY, 'fromY');
427
+ params.toX = requireFloat(toX, 'toX');
428
+ params.toY = requireFloat(toY, 'toY');
429
+ return await this.proxyCommand('/wda/pressAndDragWithVelocity', 'POST', params);
430
+ }
561
431
 
562
- export default {...helpers, ...commands};
432
+ /**
433
+ * Sends one or more taps with one or more touch points.
434
+ *
435
+ * @since 1.17.1
436
+ * @param {number} [numberOfTaps=1] - Number of taps to perform.
437
+ * @param {number} [numberOfTouches=1] - Number of touch points to use.
438
+ * @param {string|Element} [elementId] - The internal element identifier (as hexadecimal hash string) to perform one or more taps.
439
+ * The Application element will be used if this parameter is not provided.
440
+ * @returns {Promise<void>}
441
+ * @this {XCUITestDriver}
442
+ * @see https://developer.apple.com/documentation/xctest/xcuielement/1618671-tapwithnumberoftaps?language=objc
443
+ * @example
444
+ * ```ruby
445
+ * e = @driver.find_element :id, 'target element'
446
+ * # Taps the element with a single touch point twice
447
+ * @driver.execute_script 'mobile: tapWithNumberOfTaps', {element: e.ref, numberOfTaps: 2, numberOfTouches: 1}
448
+ * ```
449
+ */
450
+ export async function mobileTapWithNumberOfTaps(numberOfTouches = 1, numberOfTaps = 1, elementId = undefined) {
451
+ const endpoint = elementId
452
+ ? `/wda/element/${util.unwrapElement(elementId)}/tapWithNumberOfTaps`
453
+ : '/wda/tapWithNumberOfTaps';
454
+ return await this.proxyCommand(endpoint, 'POST', {
455
+ numberOfTaps,
456
+ numberOfTouches,
457
+ });
458
+ }
459
+
460
+ /**
461
+ * Performs a "force press" on the given element or coordinates.
462
+ *
463
+ * @throws If the target device does not support the "force press" gesture.
464
+ * @param {number} [x] - The _x_ coordinate of the gesture. If `elementId` is set, this is calculated relative to its position; otherwise it's calculated relative to the active Application.
465
+ * @param {number} [y] - The _y_ coordinate of the gesture. If `elementId` is set, this is calculated relative to its position; otherwise it's calculated relative to the active Application.
466
+ * @param {number} [duration] - The duration (in seconds) of the force press. If this is provided, `pressure` must also be provided.
467
+ * @param {number} [pressure] - A float value defining the pressure of the force press. If this is provided, `duration` must also be provided.
468
+ * @param {string|Element} [elementId] - The internal element identifier (as hexadecimal hash string) to perform one or more taps.
469
+ * The Application element will be used if this parameter is not provided.
470
+ * @returns {Promise<void>}
471
+ * @this {XCUITestDriver}
472
+ */
473
+ export async function mobileForcePress(x, y, duration, pressure, elementId) {
474
+ const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/forceTouch` : `/wda/forceTouch`;
475
+ return await this.proxyCommand(endpoint, 'POST', {x, y, duration, pressure});
476
+ }
477
+
478
+ /**
479
+ * Performs selection of the next or previous picker wheel value.
480
+ *
481
+ * This might be useful if these values are populated dynamically; you don't know which one to select, or the value selection using the `sendKeys` API does not work (for whatever reason).
482
+ *
483
+ * @throws Upon failure to change the current picker value.
484
+ * @param {string|Element} elementId - `PickerWheel`'s internal element ID as hexadecimal hash string. Value selection will be performed on this element. This element must be of type `XCUIElementTypePickerWheel`.
485
+ * @param {'next'|'previous'} order - Either `next` to select the value _next_ to the current from the target picker wheel, or `previous` to select the _previous_ value.
486
+ * @param {number} [offset=0.2] - The value in range `[0.01, 0.5]`. It defines how far from picker wheel's center the click should happen. The actual distance is calculated by multiplying this value to the actual picker wheel height. Too small an offset value may not change the picker wheel value at all, and too high a value may cause the wheel to switch two or more values at once. Usually the optimal value is located in range `[0.15, 0.3]`.
487
+ * @param {string?} [value=undefined] - If provided WDA will try to automatically scroll in the given direction until the actual picker value reaches the expected one or the amount of scrolling attempts is exceeded.
488
+ * @param {number} [maxAttempts=25] - The maximum number of scrolling attempts to reach `value` before an error will be thrown. Only makes sense in combination with `value`.
489
+ * @this {XCUITestDriver}
490
+ * @example
491
+ * ```java
492
+ * JavascriptExecutor js = (JavascriptExecutor) driver;
493
+ * Map<String, Object> params = new HashMap<>();
494
+ * params.put("order", "next");
495
+ * params.put("offset", 0.15);
496
+ * params.put("element", ((RemoteWebElement) element).getId());
497
+ * js.executeScript("mobile: selectPickerWheelValue", params);
498
+ * ```
499
+ */
500
+ export async function mobileSelectPickerWheelValue(elementId, order, offset, value, maxAttempts) {
501
+ if (!elementId) {
502
+ throw new errors.InvalidArgumentError(
503
+ 'elementId is expected to be set for selectPickerWheelValue method',
504
+ );
505
+ }
506
+ if (!_.isString(order) || !['next', 'previous'].includes(order.toLowerCase())) {
507
+ throw new errors.InvalidArgumentError(
508
+ `The mandatory 'order' parameter is expected to be equal either to 'next' or 'previous'. ` +
509
+ `'${order}' is given instead`,
510
+ );
511
+ }
512
+ const params = {order};
513
+ if (offset) {
514
+ params.offset = requireFloat(offset, 'offset');
515
+ }
516
+ if (!_.isNil(value)) {
517
+ params.value = value;
518
+ }
519
+ if (!_.isNil(maxAttempts)) {
520
+ params.maxAttempts = maxAttempts;
521
+ }
522
+ return await this.proxyCommand(`/wda/pickerwheel/${util.unwrapElement(elementId)}/select`, 'POST', params);
523
+ }
524
+
525
+ /**
526
+ * Performs a rotate gesture on the given element.
527
+ *
528
+ * @see https://developer.apple.com/documentation/xctest/xcuielement/1618665-rotate?language=objc
529
+ * @param {number} rotation - The rotation gesture (in radians)
530
+ * @param {number} velocity - The velocity (in radians-per-second) of the gesture.
531
+ * @param {string|Element} [elementId] - The internal element identifier (as hexadecimal hash string) to perform the gesture on.
532
+ * The Application element will be used if this parameter is not provided.
533
+ * @returns {Promise<void>}
534
+ * @this {XCUITestDriver}
535
+ * @example
536
+ * ```java
537
+ * JavascriptExecutor js = (JavascriptExecutor) driver;
538
+ * js.executeScript("mobile: rotateElement", ImmutableMap.of(
539
+ * // rotate clockwise, 90 degrees
540
+ * "rotation", -Math.PI / 2,
541
+ * // in approximately two seconds
542
+ * "velocity", Math.PI / 4,
543
+ * "element", ((RemoteWebElement) element).getId()
544
+ * ));
545
+ * ```
546
+ */
547
+ export async function mobileRotateElement(rotation, velocity, elementId) {
548
+ const params = {
549
+ rotation: requireFloat(rotation, 'rotation'),
550
+ velocity: requireFloat(velocity, 'velocity'),
551
+ };
552
+ const endpoint = elementId ? `/wda/element/${util.unwrapElement(elementId)}/rotate` : '/wda/rotate';
553
+ return await this.proxyCommand(endpoint, 'POST', params);
554
+ }
563
555
 
564
556
  /**
565
557
  * @param {import('@appium/types').ActionSequence[]} actionSeq
@@ -580,6 +572,24 @@ function assertNoWebElements(actionSeq) {
580
572
  }
581
573
  }
582
574
 
575
+ /**
576
+ * Converts the given value to a float number.
577
+ *
578
+ * @throws If `value` is `NaN`
579
+ * @param {any} value
580
+ * @param {string} paramName
581
+ * @returns {number}
582
+ */
583
+ function requireFloat(value, paramName) {
584
+ const num = parseFloat(String(value));
585
+ if (Number.isNaN(num)) {
586
+ throw new errors.InvalidArgumentError(
587
+ `"${paramName}" parameter should be a valid number. "${value}" is given instead`,
588
+ );
589
+ }
590
+ return num;
591
+ }
592
+
583
593
  /**
584
594
  * @typedef {import('../driver').XCUITestDriver} XCUITestDriver
585
595
  * @typedef {import('@appium/types').Element} Element