appium-mac2-driver 3.2.3 → 3.2.4

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 (53) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/build/lib/commands/app-management.d.ts +18 -21
  3. package/build/lib/commands/app-management.d.ts.map +1 -1
  4. package/build/lib/commands/app-management.js +14 -25
  5. package/build/lib/commands/app-management.js.map +1 -1
  6. package/build/lib/commands/applescript.d.ts +8 -9
  7. package/build/lib/commands/applescript.d.ts.map +1 -1
  8. package/build/lib/commands/applescript.js +14 -13
  9. package/build/lib/commands/applescript.js.map +1 -1
  10. package/build/lib/commands/execute.d.ts +5 -8
  11. package/build/lib/commands/execute.d.ts.map +1 -1
  12. package/build/lib/commands/execute.js +5 -13
  13. package/build/lib/commands/execute.js.map +1 -1
  14. package/build/lib/commands/find.d.ts +6 -8
  15. package/build/lib/commands/find.d.ts.map +1 -1
  16. package/build/lib/commands/find.js +8 -13
  17. package/build/lib/commands/find.js.map +1 -1
  18. package/build/lib/commands/gestures.d.ts +105 -118
  19. package/build/lib/commands/gestures.d.ts.map +1 -1
  20. package/build/lib/commands/gestures.js +141 -154
  21. package/build/lib/commands/gestures.js.map +1 -1
  22. package/build/lib/commands/navigation.d.ts +4 -6
  23. package/build/lib/commands/navigation.d.ts.map +1 -1
  24. package/build/lib/commands/navigation.js +2 -8
  25. package/build/lib/commands/navigation.js.map +1 -1
  26. package/build/lib/commands/record-screen.d.ts +57 -98
  27. package/build/lib/commands/record-screen.d.ts.map +1 -1
  28. package/build/lib/commands/record-screen.js +81 -84
  29. package/build/lib/commands/record-screen.js.map +1 -1
  30. package/build/lib/commands/screenshots.d.ts +5 -5
  31. package/build/lib/commands/screenshots.d.ts.map +1 -1
  32. package/build/lib/commands/screenshots.js +3 -8
  33. package/build/lib/commands/screenshots.js.map +1 -1
  34. package/build/lib/commands/source.d.ts +4 -5
  35. package/build/lib/commands/source.d.ts.map +1 -1
  36. package/build/lib/commands/source.js +3 -8
  37. package/build/lib/commands/source.js.map +1 -1
  38. package/lib/commands/app-management.ts +88 -0
  39. package/lib/commands/{applescript.js → applescript.ts} +28 -24
  40. package/lib/commands/execute.ts +32 -0
  41. package/lib/commands/find.ts +34 -0
  42. package/lib/commands/{gestures.js → gestures.ts} +333 -238
  43. package/lib/commands/navigation.ts +19 -0
  44. package/lib/commands/{record-screen.js → record-screen.ts} +165 -138
  45. package/lib/commands/screenshots.ts +18 -0
  46. package/lib/commands/{source.js → source.ts} +10 -11
  47. package/npm-shrinkwrap.json +5 -5
  48. package/package.json +1 -1
  49. package/lib/commands/app-management.js +0 -83
  50. package/lib/commands/execute.js +0 -33
  51. package/lib/commands/find.js +0 -31
  52. package/lib/commands/navigation.js +0 -18
  53. package/lib/commands/screenshots.js +0 -18
@@ -1,6 +1,8 @@
1
1
  import _ from 'lodash';
2
2
  import { util } from 'appium/support';
3
3
  import { errors } from 'appium/driver';
4
+ import type { Mac2Driver } from '../driver';
5
+ import type { KeyOptions } from '../types';
4
6
 
5
7
  /**
6
8
  * Set value to the given element.
@@ -8,483 +10,574 @@ import { errors } from 'appium/driver';
8
10
  * This is not exposed as 'macos: setValue' because this is the same as
9
11
  * element.send_keys in W3C WebDriver spec.
10
12
  *
11
- * @this {Mac2Driver}
12
- * @param {string} elementId Uuid of the element to set value for.
13
- * @param {any} [value] Value to set. Could also be an array.
14
- * @param {string} [text] Text to set. If both value and text are set then `value` is preferred
15
- * @param {number} [keyModifierFlags] If set then the given key modifiers will
13
+ * @param elementId - Uuid of the element to set value for.
14
+ * @param value - Value to set. Could also be an array.
15
+ * @param text - Text to set. If both value and text are set then `value` is preferred
16
+ * @param keyModifierFlags - If set then the given key modifiers will
16
17
  * be applied while the element value is being set. See
17
18
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
18
19
  * for more details.
19
20
  */
20
- export async function macosSetValue (elementId, value, text, keyModifierFlags) {
21
+ export async function macosSetValue(
22
+ this: Mac2Driver,
23
+ elementId: string,
24
+ value?: any,
25
+ text?: string,
26
+ keyModifierFlags?: number
27
+ ): Promise<unknown> {
21
28
  return await this.wda.proxy.command(`/element/${elementId}/value`, 'POST', {
22
- value, text,
29
+ value,
30
+ text,
23
31
  keyModifierFlags,
24
32
  });
25
- };
26
-
33
+ }
27
34
 
28
35
  /**
29
36
  * Perform click gesture on an element or by relative/absolute coordinates
30
37
  *
31
- * @this {Mac2Driver}
32
- * @param {string} [elementId] Uuid of the element to click. Either this property
38
+ * @param elementId - Uuid of the element to click. Either this property
33
39
  * or/and x and y must be set. If both are set then x and y are
34
40
  * considered as relative element coordinates. If only x and y
35
41
  * are set then these are parsed as absolute coordinates.
36
- * @param {number} [x] Click X coordinate
37
- * @param {number} [y] Click Y coordinate
38
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
42
+ * @param x - Click X coordinate
43
+ * @param y - Click Y coordinate
44
+ * @param keyModifierFlags - If set then the given key modifiers will be
39
45
  * applied while click is performed. See
40
46
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
41
47
  * for more details
42
48
  */
43
- export async function macosClick (elementId, x, y, keyModifierFlags) {
49
+ export async function macosClick(
50
+ this: Mac2Driver,
51
+ elementId?: string,
52
+ x?: number,
53
+ y?: number,
54
+ keyModifierFlags?: number
55
+ ): Promise<unknown> {
44
56
  requireElementIdOrXY(elementId, x, y);
45
57
  const url = elementId ? `/element/${elementId}/click` : '/wda/click';
46
58
  return await this.wda.proxy.command(url, 'POST', {
47
- x, y,
59
+ x,
60
+ y,
48
61
  keyModifierFlags,
49
62
  });
50
- };
63
+ }
51
64
 
52
65
  /**
53
66
  * Perform scroll gesture on an element or by relative/absolute coordinates
54
67
  *
55
- * @this {Mac2Driver}
56
- * @param {number} deltaX Horizontal delta as float number
57
- * @param {number} deltaY Vertical delta as float number
58
- * @param {string} [elementId] Uuid of the element to be scrolled. Either this property
68
+ * @param deltaX - Horizontal delta as float number
69
+ * @param deltaY - Vertical delta as float number
70
+ * @param elementId - Uuid of the element to be scrolled. Either this property
59
71
  * or/and x and y must be set. If both are set then x and y are
60
72
  * considered as relative element coordinates. If only x and y are
61
73
  * set then these are parsed as absolute coordinates.
62
- * @param {number} [x] Scroll X coordinate
63
- * @param {number} [y] Scroll Y coordinate
64
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
74
+ * @param x - Scroll X coordinate
75
+ * @param y - Scroll Y coordinate
76
+ * @param keyModifierFlags - If set then the given key modifiers will be
65
77
  * applied while scroll is performed. See
66
78
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
67
79
  * for more details
68
80
  */
69
- export async function macosScroll (
70
- deltaX, deltaY,
71
- elementId,
72
- x, y,
73
- keyModifierFlags
74
- ) {
81
+ export async function macosScroll(
82
+ this: Mac2Driver,
83
+ deltaX: number,
84
+ deltaY: number,
85
+ elementId?: string,
86
+ x?: number,
87
+ y?: number,
88
+ keyModifierFlags?: number
89
+ ): Promise<unknown> {
75
90
  requireElementIdOrXY(elementId, x, y);
76
91
  const url = elementId ? `/wda/element/${elementId}/scroll` : '/wda/scroll';
77
92
  return await this.wda.proxy.command(url, 'POST', {
78
- deltaX, deltaY,
79
- x, y,
93
+ deltaX,
94
+ deltaY,
95
+ x,
96
+ y,
80
97
  keyModifierFlags,
81
98
  });
82
- };
99
+ }
83
100
 
84
101
  /**
85
102
  * Perform swipe gesture on an element
86
103
  *
87
- * @this {Mac2Driver}
88
- * @param {'up'|'down'|'left'|'right'} direction Swipe direction
89
- * @param {string} [elementId] Uuid of the element to be swiped. Either this property
104
+ * @param direction - Swipe direction
105
+ * @param elementId - Uuid of the element to be swiped. Either this property
90
106
  * or/and x and y must be set. If both are set then x and y are
91
107
  * considered as relative element coordinates. If only x and y are
92
108
  * set then these are parsed as absolute coordinates.
93
- * @param {number} [x] Swipe X coordinate
94
- * @param {number} [y] Swipe Y coordinate
95
- * @param {number} [velocity] The value is measured in pixels per second and same
109
+ * @param x - Swipe X coordinate
110
+ * @param y - Swipe Y coordinate
111
+ * @param velocity - The value is measured in pixels per second and same
96
112
  * values could behave differently on different devices depending
97
113
  * on their display density. Higher values make swipe gesture faster
98
114
  * (which usually scrolls larger areas if we apply it to a list)
99
115
  * and lower values slow it down. Only values greater than zero have effect.
100
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
116
+ * @param keyModifierFlags - If set then the given key modifiers will be
101
117
  * applied while scroll is performed. See
102
118
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
103
119
  * for more details
104
120
  */
105
- export async function macosSwipe (
106
- direction,
107
- elementId,
108
- x, y,
109
- velocity,
110
- keyModifierFlags
111
- ) {
121
+ export async function macosSwipe(
122
+ this: Mac2Driver,
123
+ direction: 'up' | 'down' | 'left' | 'right',
124
+ elementId?: string,
125
+ x?: number,
126
+ y?: number,
127
+ velocity?: number,
128
+ keyModifierFlags?: number
129
+ ): Promise<unknown> {
112
130
  requireElementIdOrXY(elementId, x, y);
113
131
  const url = elementId ? `/wda/element/${elementId}/swipe` : `/wda/swipe`;
114
132
  return await this.wda.proxy.command(url, 'POST', {
115
- x, y,
133
+ x,
134
+ y,
116
135
  direction,
117
136
  velocity,
118
137
  keyModifierFlags,
119
138
  });
120
- };
139
+ }
121
140
 
122
141
  /**
123
142
  * Perform right click gesture on an element or by relative/absolute coordinates
124
143
  *
125
- * @this {Mac2Driver}
126
- * @param {string} [elementId] Uuid of the element to click. Either this property
144
+ * @param elementId - Uuid of the element to click. Either this property
127
145
  * or/and x and y must be set. If both are set then x and y are
128
146
  * considered as relative element coordinates. If only x and y
129
147
  * are set then these are parsed as absolute coordinates.
130
- * @param {number} [x] Click X coordinate
131
- * @param {number} [y] Click Y coordinate
132
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
148
+ * @param x - Click X coordinate
149
+ * @param y - Click Y coordinate
150
+ * @param keyModifierFlags - If set then the given key modifiers will be
133
151
  * applied while click is performed. See
134
152
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
135
153
  * for more details
136
154
  */
137
- export async function macosRightClick (elementId, x, y, keyModifierFlags) {
155
+ export async function macosRightClick(
156
+ this: Mac2Driver,
157
+ elementId?: string,
158
+ x?: number,
159
+ y?: number,
160
+ keyModifierFlags?: number
161
+ ): Promise<unknown> {
138
162
  requireElementIdOrXY(elementId, x, y);
139
163
  const url = elementId ? `/wda/element/${elementId}/rightClick` : '/wda/rightClick';
140
164
  return await this.wda.proxy.command(url, 'POST', {
141
- x, y,
165
+ x,
166
+ y,
142
167
  keyModifierFlags,
143
168
  });
144
- };
169
+ }
145
170
 
146
171
  /**
147
172
  * Perform hover gesture on an element or by relative/absolute coordinates
148
173
  *
149
- * @this {Mac2Driver}
150
- * @param {string} [elementId] Uuid of the element to hover. Either this property
174
+ * @param elementId - Uuid of the element to hover. Either this property
151
175
  * or/and x and y must be set. If both are set then x and y are
152
176
  * considered as relative element coordinates. If only x and y
153
177
  * are set then these are parsed as absolute coordinates.
154
- * @param {number} [x] Click X coordinate
155
- * @param {number} [y] Click Y coordinate
156
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
178
+ * @param x - Click X coordinate
179
+ * @param y - Click Y coordinate
180
+ * @param keyModifierFlags - If set then the given key modifiers will be
157
181
  * applied while click is performed. See
158
182
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
159
183
  * for more details
160
184
  */
161
- export async function macosHover (elementId, x, y, keyModifierFlags) {
185
+ export async function macosHover(
186
+ this: Mac2Driver,
187
+ elementId?: string,
188
+ x?: number,
189
+ y?: number,
190
+ keyModifierFlags?: number
191
+ ): Promise<unknown> {
162
192
  requireElementIdOrXY(elementId, x, y);
163
193
  const url = elementId ? `/wda/element/${elementId}/hover` : '/wda/hover';
164
194
  return await this.wda.proxy.command(url, 'POST', {
165
- x, y,
195
+ x,
196
+ y,
166
197
  keyModifierFlags,
167
198
  });
168
- };
199
+ }
169
200
 
170
201
  /**
171
202
  * Perform double click gesture on an element or by relative/absolute coordinates
172
203
  *
173
- * @this {Mac2Driver}
174
- * @param {string} [elementId] Uuid of the element to hover. Either this property
204
+ * @param elementId - Uuid of the element to hover. Either this property
175
205
  * or/and x and y must be set. If both are set then x and y are
176
206
  * considered as relative element coordinates. If only x and y
177
207
  * are set then these are parsed as absolute coordinates.
178
- * @param {number} [x] Click X coordinate
179
- * @param {number} [y] Click Y coordinate
180
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
208
+ * @param x - Click X coordinate
209
+ * @param y - Click Y coordinate
210
+ * @param keyModifierFlags - If set then the given key modifiers will be
181
211
  * applied while click is performed. See
182
212
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
183
213
  * for more details
184
214
  */
185
- export async function macosDoubleClick (elementId, x, y, keyModifierFlags) {
215
+ export async function macosDoubleClick(
216
+ this: Mac2Driver,
217
+ elementId?: string,
218
+ x?: number,
219
+ y?: number,
220
+ keyModifierFlags?: number
221
+ ): Promise<unknown> {
186
222
  requireElementIdOrXY(elementId, x, y);
187
223
  const url = elementId ? `/wda/element/${elementId}/doubleClick` : '/wda/doubleClick';
188
224
  return await this.wda.proxy.command(url, 'POST', {
189
- x, y,
225
+ x,
226
+ y,
190
227
  keyModifierFlags,
191
228
  });
192
- };
229
+ }
193
230
 
194
231
  /**
195
232
  * Perform long click and drag gesture on an element or by absolute coordinates
196
233
  *
197
- * @this {Mac2Driver}
198
- * @param {number} duration Long click duration in float seconds
199
- * @param {string} [sourceElementId] Uuid of the element to start the drag from.
234
+ * @param duration - Long click duration in float seconds
235
+ * @param sourceElementId - Uuid of the element to start the drag from.
200
236
  * Either this property and `destinationElement` must be provided
201
237
  * or `startX`, `startY`, `endX`, `endY` coordinates must be set.
202
- * @param {string} [destinationElementId] Uuid of the element to end the drag on.
238
+ * @param destinationElementId - Uuid of the element to end the drag on.
203
239
  * Either this property and `sourceElement` must be provided or
204
240
  * `startX`, `startY`, `endX`, `endY` coordinatesmust be set.
205
- * @param {number} [startX] Starting X coordinate
206
- * @param {number} [startY] Starting Y coordinate
207
- * @param {number} [endX] Ending X coordinate
208
- * @param {number} [endY] Ending Y coordinate
209
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
241
+ * @param startX - Starting X coordinate
242
+ * @param startY - Starting Y coordinate
243
+ * @param endX - Ending X coordinate
244
+ * @param endY - Ending Y coordinate
245
+ * @param keyModifierFlags - If set then the given key modifiers will be
210
246
  * applied while drag is performed. See
211
247
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
212
248
  * for more details
213
249
  */
214
- export async function macosClickAndDrag (
215
- duration,
216
- sourceElementId,
217
- destinationElementId,
218
- startX, startY,
219
- endX, endY,
220
- keyModifierFlags
221
- ) {
250
+ export async function macosClickAndDrag(
251
+ this: Mac2Driver,
252
+ duration: number,
253
+ sourceElementId?: string,
254
+ destinationElementId?: string,
255
+ startX?: number,
256
+ startY?: number,
257
+ endX?: number,
258
+ endY?: number,
259
+ keyModifierFlags?: number
260
+ ): Promise<unknown> {
222
261
  requireSourceDestWithElementsOrCoordinates(
223
- sourceElementId, destinationElementId,
224
- startX, startY, endX, endY,
262
+ sourceElementId,
263
+ destinationElementId,
264
+ startX,
265
+ startY,
266
+ endX,
267
+ endY
225
268
  );
226
- const url = sourceElementId && destinationElementId
227
- ? `/wda/element/${sourceElementId}/clickAndDrag`
228
- : '/wda/clickAndDrag';
269
+ const url =
270
+ sourceElementId && destinationElementId
271
+ ? `/wda/element/${sourceElementId}/clickAndDrag`
272
+ : '/wda/clickAndDrag';
229
273
  const dest = destinationElementId && util.wrapElement(destinationElementId);
230
274
  return await this.wda.proxy.command(url, 'POST', {
231
- startX, startY,
232
- endX, endY,
275
+ startX,
276
+ startY,
277
+ endX,
278
+ endY,
233
279
  duration,
234
280
  dest,
235
281
  keyModifierFlags,
236
282
  });
237
- };
283
+ }
238
284
 
239
285
  /**
240
286
  * Perform long click, drag and hold gesture on an element or by absolute coordinates
241
287
  *
242
- * @this {Mac2Driver}
243
- * @param {number} duration Long click duration in float seconds
244
- * @param {number} holdDuration Touch hold duration in float seconds
245
- * @param {string} [sourceElementId] Uuid of the element to start the drag from.
288
+ * @param duration - Long click duration in float seconds
289
+ * @param holdDuration - Touch hold duration in float seconds
290
+ * @param sourceElementId - Uuid of the element to start the drag from.
246
291
  * Either this property and `destinationElement` must be provided
247
292
  * or `startX`, `startY`, `endX`, `endY` coordinates must be set.
248
- * @param {string} [destinationElementId] Uuid of the element to end the drag on.
293
+ * @param destinationElementId - Uuid of the element to end the drag on.
249
294
  * Either this property and `sourceElement` must be provided
250
295
  * or `startX`, `startY`, `endX`, `endY` coordinates must be set.
251
- * @param {number} [startX] Starting X coordinate
252
- * @param {number} [startY] Starting Y coordinate
253
- * @param {number} [endX] Ending X coordinate
254
- * @param {number} [endY] Ending Y coordinate
255
- * @param {number} [velocity] Dragging velocity in pixels per second.
296
+ * @param startX - Starting X coordinate
297
+ * @param startY - Starting Y coordinate
298
+ * @param endX - Ending X coordinate
299
+ * @param endY - Ending Y coordinate
300
+ * @param velocity - Dragging velocity in pixels per second.
256
301
  * If not provided then the default velocity is used. See
257
302
  * https://developer.apple.com/documentation/xctest/xcuigesturevelocity
258
303
  * for more details
259
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
304
+ * @param keyModifierFlags - If set then the given key modifiers will be
260
305
  * applied while drag is performed. See
261
306
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
262
- * for more details */
263
- export async function macosClickAndDragAndHold (
264
- duration,
265
- holdDuration,
266
- sourceElementId,
267
- destinationElementId,
268
- startX, startY,
269
- endX, endY,
270
- velocity,
271
- keyModifierFlags
272
- ) {
307
+ * for more details
308
+ */
309
+ export async function macosClickAndDragAndHold(
310
+ this: Mac2Driver,
311
+ duration: number,
312
+ holdDuration: number,
313
+ sourceElementId?: string,
314
+ destinationElementId?: string,
315
+ startX?: number,
316
+ startY?: number,
317
+ endX?: number,
318
+ endY?: number,
319
+ velocity?: number,
320
+ keyModifierFlags?: number
321
+ ): Promise<unknown> {
273
322
  requireSourceDestWithElementsOrCoordinates(
274
- sourceElementId, destinationElementId,
275
- startX, startY, endX, endY,
323
+ sourceElementId,
324
+ destinationElementId,
325
+ startX,
326
+ startY,
327
+ endX,
328
+ endY
276
329
  );
277
- const url = sourceElementId && destinationElementId
278
- ? `/wda/element/${sourceElementId}/clickAndDragAndHold`
279
- : '/wda/clickAndDragAndHold';
330
+ const url =
331
+ sourceElementId && destinationElementId
332
+ ? `/wda/element/${sourceElementId}/clickAndDragAndHold`
333
+ : '/wda/clickAndDragAndHold';
280
334
  const dest = destinationElementId && util.wrapElement(destinationElementId);
281
335
  return await this.wda.proxy.command(url, 'POST', {
282
- startX, startY,
283
- endX, endY,
284
- duration, holdDuration,
336
+ startX,
337
+ startY,
338
+ endX,
339
+ endY,
340
+ duration,
341
+ holdDuration,
285
342
  velocity,
286
343
  dest,
287
344
  keyModifierFlags,
288
345
  });
289
- };
346
+ }
290
347
 
291
348
  /**
292
349
  * Send keys to the given element or to the application under test
293
350
  *
294
- * @this {Mac2Driver}
295
- * @param {(import('../types').KeyOptions | string)[]} keys Array of keys to type.
351
+ * @param keys - Array of keys to type.
296
352
  * Each item could either be a string, that represents a key itself (see
297
353
  * https://developer.apple.com/documentation/xctest/xcuielement/1500604-typekey
298
354
  * and https://developer.apple.com/documentation/xctest/xcuikeyboardkey)
299
355
  * or a dictionary, if the key should also be entered with modifiers.
300
- * @param {string} [elementId] Uuid of the element to send the keys to.
356
+ * @param elementId - Uuid of the element to send the keys to.
301
357
  * If unset then keys are sent to the current application
302
358
  * under test.
303
359
  */
304
- export async function macosKeys (keys, elementId) {
360
+ export async function macosKeys(
361
+ this: Mac2Driver,
362
+ keys: (KeyOptions | string)[],
363
+ elementId?: string
364
+ ): Promise<unknown> {
305
365
  const url = elementId ? `/wda/element/${elementId}/keys` : '/wda/keys';
306
366
  return await this.wda.proxy.command(url, 'POST', { keys });
307
- };
367
+ }
308
368
 
309
369
  /**
310
370
  * Perform tap gesture on a Touch Bar element or by relative/absolute coordinates
311
371
  *
312
- * @this {Mac2Driver}
313
- * @param {string} [elementId] Uuid of the Touch Bar element to tap. Either this property
372
+ * @param elementId - Uuid of the Touch Bar element to tap. Either this property
314
373
  * or/and x and y must be set. If both are set then x and y are considered
315
374
  * as relative element coordinates. If only x and y are set then
316
375
  * these are parsed as absolute Touch Bar coordinates.
317
- * @param {number} [x] Tap X coordinate
318
- * @param {number} [y] Tap Y coordinate
319
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
376
+ * @param x - Tap X coordinate
377
+ * @param y - Tap Y coordinate
378
+ * @param keyModifierFlags - If set then the given key modifiers will be
320
379
  * applied while click is performed. See
321
380
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
322
381
  * for more details
323
382
  */
324
- export async function macosTap (elementId, x, y, keyModifierFlags) {
383
+ export async function macosTap(
384
+ this: Mac2Driver,
385
+ elementId?: string,
386
+ x?: number,
387
+ y?: number,
388
+ keyModifierFlags?: number
389
+ ): Promise<unknown> {
325
390
  requireElementIdOrXY(elementId, x, y);
326
391
  const url = elementId ? `/wda/element/${elementId}/tap` : '/wda/tap';
327
392
  return await this.wda.proxy.command(url, 'POST', {
328
- x, y,
393
+ x,
394
+ y,
329
395
  keyModifierFlags,
330
396
  });
331
- };
397
+ }
332
398
 
333
399
  /**
334
400
  * Perform tap gesture on a Touch Bar element or by relative/absolute coordinates
335
401
  *
336
- * @this {Mac2Driver}
337
- * @param {string} [elementId] Uuid of the Touch Bar element to tap. Either this property
338
- * or/and x and y must be set. If both are set then x and y are considered
339
- * as relative element coordinates. If only x and y are set then
340
- * these are parsed as absolute Touch Bar coordinates.
341
- * @param {number} [x] Tap X coordinate
342
- * @param {number} [y] Tap Y coordinate
343
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
402
+ * @param elementId - Uuid of the Touch Bar element to tap. Either this property
403
+ * or/and x and y must be set. If both are set then x and y are considered
404
+ * as relative element coordinates. If only x and y are set then
405
+ * these are parsed as absolute Touch Bar coordinates.
406
+ * @param x - Tap X coordinate
407
+ * @param y - Tap Y coordinate
408
+ * @param keyModifierFlags - If set then the given key modifiers will be
344
409
  * applied while click is performed. See
345
410
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
346
411
  * for more details
347
412
  */
348
- export async function macosDoubleTap (elementId, x, y, keyModifierFlags) {
413
+ export async function macosDoubleTap(
414
+ this: Mac2Driver,
415
+ elementId?: string,
416
+ x?: number,
417
+ y?: number,
418
+ keyModifierFlags?: number
419
+ ): Promise<unknown> {
349
420
  requireElementIdOrXY(elementId, x, y);
350
421
  const url = elementId ? `/wda/element/${elementId}/doubleTap` : '/wda/doubleTap';
351
422
  return await this.wda.proxy.command(url, 'POST', {
352
- x, y,
423
+ x,
424
+ y,
353
425
  keyModifierFlags,
354
426
  });
355
- };
427
+ }
356
428
 
357
429
  /**
358
430
  * Perform press gesture on a Touch Bar element or by relative/absolute coordinates
359
431
  *
360
- * @this {Mac2Driver}
361
- * @param {number} duration The number of float seconds to hold the mouse button
362
- * @param {string} [elementId] Uuid of the Touch Bar element to be pressed. Either this property
432
+ * @param duration - The number of float seconds to hold the mouse button
433
+ * @param elementId - Uuid of the Touch Bar element to be pressed. Either this property
363
434
  * or/and x and y must be set. If both are set then x and y are considered
364
435
  * as relative element coordinates. If only x and y are set then these are
365
436
  * parsed as absolute Touch Bar coordinates.
366
- * @param {number} [x] Press X coordinate
367
- * @param {number} [y] Press Y coordinate
368
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
437
+ * @param x - Press X coordinate
438
+ * @param y - Press Y coordinate
439
+ * @param keyModifierFlags - If set then the given key modifiers will be
369
440
  * applied while click is performed. See
370
441
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
371
442
  * for more details
372
443
  */
373
- export async function macosPressAndHold (duration, elementId, x, y, keyModifierFlags) {
444
+ export async function macosPressAndHold(
445
+ this: Mac2Driver,
446
+ duration: number,
447
+ elementId?: string,
448
+ x?: number,
449
+ y?: number,
450
+ keyModifierFlags?: number
451
+ ): Promise<unknown> {
374
452
  const url = elementId ? `/wda/element/${elementId}/press` : '/wda/press';
375
453
  return await this.wda.proxy.command(url, 'POST', {
376
- x, y,
454
+ x,
455
+ y,
377
456
  duration,
378
457
  keyModifierFlags,
379
458
  });
380
- };
459
+ }
381
460
 
382
461
  /**
383
462
  * Perform long press and drag gesture on a Touch Bar element or by absolute coordinates
384
463
  *
385
- * @this {Mac2Driver}
386
- * @param {number} duration Long press duration in float seconds
387
- * @param {string} [sourceElementId] Uuid of a Touch Bar element to start the drag from.
464
+ * @param duration - Long press duration in float seconds
465
+ * @param sourceElementId - Uuid of a Touch Bar element to start the drag from.
388
466
  * Either this property and `destinationElement` must be provided or
389
467
  * `startX`, `startY`, `endX`, `endY` coordinates must be set.
390
- * @param {string} [destinationElementId] Uuid of a Touch Bar element to end the drag on.
468
+ * @param destinationElementId - Uuid of a Touch Bar element to end the drag on.
391
469
  * Either this property and `sourceElement` must be provided or
392
470
  * `startX`, `startY`, `endX`, `endY` coordinates must be set.
393
- * @param {number} [startX] Starting X coordinate
394
- * @param {number} [startY] Starting Y coordinate
395
- * @param {number} [endX] Ending X coordinate
396
- * @param {number} [endY] Ending Y coordinate
397
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
471
+ * @param startX - Starting X coordinate
472
+ * @param startY - Starting Y coordinate
473
+ * @param endX - Ending X coordinate
474
+ * @param endY - Ending Y coordinate
475
+ * @param keyModifierFlags - If set then the given key modifiers will be
398
476
  * applied while drag is performed. See
399
477
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
400
478
  * for more details
401
479
  */
402
- export async function macosPressAndDrag (
403
- duration,
404
- sourceElementId,
405
- destinationElementId,
406
- startX, startY,
407
- endX, endY,
408
- keyModifierFlags
409
- ) {
480
+ export async function macosPressAndDrag(
481
+ this: Mac2Driver,
482
+ duration: number,
483
+ sourceElementId?: string,
484
+ destinationElementId?: string,
485
+ startX?: number,
486
+ startY?: number,
487
+ endX?: number,
488
+ endY?: number,
489
+ keyModifierFlags?: number
490
+ ): Promise<unknown> {
410
491
  // requireSourceDestWithElementsOrCoordinates(
411
492
  // sourceElementId, destinationElementId,
412
493
  // startX, startY, endX, endY,
413
494
  // );
414
- const url = sourceElementId && destinationElementId
415
- ? `/wda/element/${sourceElementId}/pressAndDrag`
416
- : '/wda/pressAndDrag';
495
+ const url =
496
+ sourceElementId && destinationElementId
497
+ ? `/wda/element/${sourceElementId}/pressAndDrag`
498
+ : '/wda/pressAndDrag';
417
499
  const dest = destinationElementId && util.wrapElement(destinationElementId);
418
500
  return await this.wda.proxy.command(url, 'POST', {
419
- startX, startY,
420
- endX, endY,
501
+ startX,
502
+ startY,
503
+ endX,
504
+ endY,
421
505
  duration,
422
506
  dest,
423
507
  keyModifierFlags,
424
508
  });
425
- };
509
+ }
426
510
 
427
511
  /**
428
512
  * Perform press, drag and hold gesture on a Touch Bar element or by absolute Touch Bar coordinates
429
513
  *
430
- * @this {Mac2Driver}
431
- * @param {number} duration Long press duration in float seconds
432
- * @param {number} holdDuration Touch hold duration in float seconds
433
- * @param {string} [sourceElementId] Uuid of a Touch Bar element to start the drag from.
514
+ * @param duration - Long press duration in float seconds
515
+ * @param holdDuration - Touch hold duration in float seconds
516
+ * @param sourceElementId - Uuid of a Touch Bar element to start the drag from.
434
517
  * Either this property and `destinationElement` must be provided or
435
518
  * `startX`, `startY`, `endX`, `endY` coordinates must be set.
436
- * @param {string} [destinationElementId] Uuid of a Touch Bar element to end the drag on.
519
+ * @param destinationElementId - Uuid of a Touch Bar element to end the drag on.
437
520
  * Either this property and `sourceElement` must be provided or
438
521
  * `startX`, `startY`, `endX`, `endY` coordinates must be set.
439
- * @param {number} [startX] Starting X coordinate
440
- * @param {number} [startY] Starting Y coordinate
441
- * @param {number} [endX] Ending X coordinate
442
- * @param {number} [endY] Ending Y coordinate
443
- * @param {number} [velocity] Dragging velocity in pixels per second.
522
+ * @param startX - Starting X coordinate
523
+ * @param startY - Starting Y coordinate
524
+ * @param endX - Ending X coordinate
525
+ * @param endY - Ending Y coordinate
526
+ * @param velocity - Dragging velocity in pixels per second.
444
527
  * If not provided then the default velocity is used. See
445
528
  * https://developer.apple.com/documentation/xctest/xcuigesturevelocity
446
529
  * for more details
447
- * @param {number} [keyModifierFlags] If set then the given key modifiers will be
530
+ * @param keyModifierFlags - If set then the given key modifiers will be
448
531
  * applied while drag is performed. See
449
532
  * https://developer.apple.com/documentation/xctest/xcuikeymodifierflags
450
533
  * for more details
451
534
  */
452
- export async function macosPressAndDragAndHold (
453
- duration,
454
- holdDuration,
455
- sourceElementId,
456
- destinationElementId,
457
- startX, startY,
458
- endX, endY,
459
- velocity,
460
- keyModifierFlags
461
- ) {
535
+ export async function macosPressAndDragAndHold(
536
+ this: Mac2Driver,
537
+ duration: number,
538
+ holdDuration: number,
539
+ sourceElementId?: string,
540
+ destinationElementId?: string,
541
+ startX?: number,
542
+ startY?: number,
543
+ endX?: number,
544
+ endY?: number,
545
+ velocity?: number,
546
+ keyModifierFlags?: number
547
+ ): Promise<unknown> {
462
548
  requireSourceDestWithElementsOrCoordinates(
463
- sourceElementId, destinationElementId,
464
- startX, startY, endX, endY,
549
+ sourceElementId,
550
+ destinationElementId,
551
+ startX,
552
+ startY,
553
+ endX,
554
+ endY
465
555
  );
466
- const url = sourceElementId && destinationElementId
467
- ? `/wda/element/${sourceElementId}/pressAndDragAndHold`
468
- : '/wda/pressAndDragAndHold';
556
+ const url =
557
+ sourceElementId && destinationElementId
558
+ ? `/wda/element/${sourceElementId}/pressAndDragAndHold`
559
+ : '/wda/pressAndDragAndHold';
469
560
  const dest = destinationElementId && util.wrapElement(destinationElementId);
470
561
  return await this.wda.proxy.command(url, 'POST', {
471
- startX, startY,
472
- endX, endY,
473
- duration, holdDuration,
562
+ startX,
563
+ startY,
564
+ endX,
565
+ endY,
566
+ duration,
567
+ holdDuration,
474
568
  velocity,
475
569
  dest,
476
570
  keyModifierFlags,
477
571
  });
478
- };
572
+ }
479
573
 
480
574
  /**
481
575
  * Raise invalid argument error if element id was unset or x and y were unset.
482
- * @param {string} [elementId]
483
- * @param {number} [x]
484
- * @param {number} [y]
485
- * @returns {void}
576
+ * @param elementId - Optional element ID
577
+ * @param x - Optional X coordinate
578
+ * @param y - Optional Y coordinate
486
579
  */
487
- function requireElementIdOrXY (elementId, x, y) {
580
+ function requireElementIdOrXY(elementId?: string, x?: number, y?: number): void {
488
581
  if (!_.isString(elementId) && !(_.isNumber(x) && _.isNumber(y))) {
489
582
  throw new errors.InvalidArgumentError(`'elementId' or 'x' and 'y' is required.`);
490
583
  }
@@ -493,27 +586,29 @@ function requireElementIdOrXY (elementId, x, y) {
493
586
  /**
494
587
  * Raise invalid argument error if sourceElementId and destinationElementId were unset
495
588
  * or startX, startY, endX and endY were unset.
496
- * @param {string} [sourceElementId]
497
- * @param {string} [destinationElementId]
498
- * @param {number} [startX]
499
- * @param {number} [startY]
500
- * @param {number} [endX]
501
- * @param {number} [endY]
502
- * @returns {void}
589
+ * @param sourceElementId - Optional source element ID
590
+ * @param destinationElementId - Optional destination element ID
591
+ * @param startX - Optional starting X coordinate
592
+ * @param startY - Optional starting Y coordinate
593
+ * @param endX - Optional ending X coordinate
594
+ * @param endY - Optional ending Y coordinate
503
595
  */
504
- function requireSourceDestWithElementsOrCoordinates (
505
- sourceElementId, destinationElementId,
506
- startX, startY, endX, endY
507
- ) {
596
+ function requireSourceDestWithElementsOrCoordinates(
597
+ sourceElementId?: string,
598
+ destinationElementId?: string,
599
+ startX?: number,
600
+ startY?: number,
601
+ endX?: number,
602
+ endY?: number
603
+ ): void {
508
604
  if (
509
- !(_.isString(sourceElementId) && _.isString(destinationElementId))
510
- && !(_.isNumber(startX) && _.isNumber(startY) && _.isNumber(endX) && _.isNumber(endY))
605
+ !(_.isString(sourceElementId) && _.isString(destinationElementId)) &&
606
+ !(_.isNumber(startX) && _.isNumber(startY) && _.isNumber(endX) && _.isNumber(endY))
511
607
  ) {
512
- throw new errors.InvalidArgumentError(`'sourceElementId' and 'destinationElementId' ` +
513
- `or 'startX', 'startY', 'endX' and 'endY' are required.`);
608
+ throw new errors.InvalidArgumentError(
609
+ `'sourceElementId' and 'destinationElementId' ` +
610
+ `or 'startX', 'startY', 'endX' and 'endY' are required.`
611
+ );
514
612
  }
515
613
  }
516
614
 
517
- /**
518
- * @typedef {import('../driver').Mac2Driver} Mac2Driver
519
- */