appium-uiautomator2-driver 2.29.11 → 2.30.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 (135) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/build/index.d.ts +4 -0
  3. package/build/index.d.ts.map +1 -0
  4. package/build/index.js +8 -15
  5. package/build/index.js.map +1 -0
  6. package/build/lib/commands/actions.d.ts +2 -0
  7. package/build/lib/commands/actions.d.ts.map +1 -0
  8. package/build/lib/commands/actions.js +67 -62
  9. package/build/lib/commands/actions.js.map +1 -1
  10. package/build/lib/commands/alert.d.ts +2 -0
  11. package/build/lib/commands/alert.d.ts.map +1 -0
  12. package/build/lib/commands/alert.js +28 -26
  13. package/build/lib/commands/alert.js.map +1 -1
  14. package/build/lib/commands/app-strings.d.ts +3 -0
  15. package/build/lib/commands/app-strings.d.ts.map +1 -0
  16. package/build/lib/commands/app-strings.js +86 -57
  17. package/build/lib/commands/app-strings.js.map +1 -1
  18. package/build/lib/commands/battery.d.ts +2 -0
  19. package/build/lib/commands/battery.d.ts.map +1 -0
  20. package/build/lib/commands/battery.js +26 -16
  21. package/build/lib/commands/battery.js.map +1 -1
  22. package/build/lib/commands/element.d.ts +2 -0
  23. package/build/lib/commands/element.d.ts.map +1 -0
  24. package/build/lib/commands/element.js +140 -159
  25. package/build/lib/commands/element.js.map +1 -1
  26. package/build/lib/commands/find.d.ts +2 -0
  27. package/build/lib/commands/find.d.ts.map +1 -0
  28. package/build/lib/commands/find.js +39 -25
  29. package/build/lib/commands/find.js.map +1 -1
  30. package/build/lib/commands/general.d.ts +4 -0
  31. package/build/lib/commands/general.d.ts.map +1 -0
  32. package/build/lib/commands/general.js +217 -215
  33. package/build/lib/commands/general.js.map +1 -1
  34. package/build/lib/commands/gestures.d.ts +2 -0
  35. package/build/lib/commands/gestures.d.ts.map +1 -0
  36. package/build/lib/commands/gestures.js +206 -193
  37. package/build/lib/commands/gestures.js.map +1 -1
  38. package/build/lib/commands/index.d.ts +2 -0
  39. package/build/lib/commands/index.d.ts.map +1 -0
  40. package/build/lib/commands/index.js +13 -22
  41. package/build/lib/commands/index.js.map +1 -1
  42. package/build/lib/commands/mixins.d.ts +84 -0
  43. package/build/lib/commands/mixins.d.ts.map +1 -0
  44. package/build/lib/commands/mixins.js +23 -0
  45. package/build/lib/commands/mixins.js.map +1 -0
  46. package/build/lib/commands/screenshot.d.ts +2 -0
  47. package/build/lib/commands/screenshot.d.ts.map +1 -0
  48. package/build/lib/commands/screenshot.js +77 -62
  49. package/build/lib/commands/screenshot.js.map +1 -1
  50. package/build/lib/commands/touch.d.ts +2 -0
  51. package/build/lib/commands/touch.d.ts.map +1 -0
  52. package/build/lib/commands/touch.js +48 -38
  53. package/build/lib/commands/touch.js.map +1 -1
  54. package/build/lib/commands/types.d.ts +452 -0
  55. package/build/lib/commands/types.d.ts.map +1 -0
  56. package/build/lib/commands/types.js +3 -0
  57. package/build/lib/commands/types.js.map +1 -0
  58. package/build/lib/commands/viewport.d.ts +2 -0
  59. package/build/lib/commands/viewport.d.ts.map +1 -0
  60. package/build/lib/commands/viewport.js +37 -35
  61. package/build/lib/commands/viewport.js.map +1 -1
  62. package/build/lib/constraints.d.ts +334 -0
  63. package/build/lib/constraints.d.ts.map +1 -0
  64. package/build/lib/constraints.js +51 -0
  65. package/build/lib/constraints.js.map +1 -0
  66. package/build/lib/css-converter.d.ts +45 -0
  67. package/build/lib/css-converter.d.ts.map +1 -0
  68. package/build/lib/css-converter.js +272 -175
  69. package/build/lib/css-converter.js.map +1 -1
  70. package/build/lib/driver.d.ts +912 -0
  71. package/build/lib/driver.d.ts.map +1 -0
  72. package/build/lib/driver.js +738 -482
  73. package/build/lib/driver.js.map +1 -1
  74. package/build/lib/execute-method-map.d.ts +477 -0
  75. package/build/lib/execute-method-map.d.ts.map +1 -0
  76. package/build/lib/execute-method-map.js +542 -0
  77. package/build/lib/execute-method-map.js.map +1 -0
  78. package/build/lib/extensions.d.ts +3 -0
  79. package/build/lib/extensions.d.ts.map +1 -0
  80. package/build/lib/extensions.js +7 -9
  81. package/build/lib/extensions.js.map +1 -1
  82. package/build/lib/helpers.d.ts +7 -0
  83. package/build/lib/helpers.d.ts.map +1 -0
  84. package/build/lib/helpers.js +36 -29
  85. package/build/lib/helpers.js.map +1 -1
  86. package/build/lib/logger.d.ts +3 -0
  87. package/build/lib/logger.d.ts.map +1 -0
  88. package/build/lib/logger.js +5 -10
  89. package/build/lib/logger.js.map +1 -1
  90. package/build/lib/method-map.d.ts +389 -0
  91. package/build/lib/method-map.d.ts.map +1 -0
  92. package/build/lib/method-map.js +11 -17
  93. package/build/lib/method-map.js.map +1 -1
  94. package/build/lib/types.d.ts +45 -0
  95. package/build/lib/types.d.ts.map +1 -0
  96. package/build/lib/types.js +3 -0
  97. package/build/lib/types.js.map +1 -0
  98. package/build/lib/uiautomator2.d.ts +45 -0
  99. package/build/lib/uiautomator2.d.ts.map +1 -0
  100. package/build/lib/uiautomator2.js +340 -299
  101. package/build/lib/uiautomator2.js.map +1 -1
  102. package/build/lib/utils.d.ts +10 -0
  103. package/build/lib/utils.d.ts.map +1 -0
  104. package/build/lib/utils.js +23 -16
  105. package/build/lib/utils.js.map +1 -1
  106. package/build/tsconfig.tsbuildinfo +1 -0
  107. package/index.js +5 -3
  108. package/lib/commands/actions.js +115 -101
  109. package/lib/commands/alert.js +36 -44
  110. package/lib/commands/app-strings.js +79 -58
  111. package/lib/commands/battery.js +27 -28
  112. package/lib/commands/element.js +231 -134
  113. package/lib/commands/find.js +40 -21
  114. package/lib/commands/general.js +271 -336
  115. package/lib/commands/gestures.js +252 -366
  116. package/lib/commands/index.js +11 -31
  117. package/lib/commands/mixins.ts +167 -0
  118. package/lib/commands/screenshot.js +80 -76
  119. package/lib/commands/touch.js +64 -31
  120. package/lib/commands/types.ts +473 -0
  121. package/lib/commands/viewport.js +43 -31
  122. package/lib/constraints.ts +53 -0
  123. package/lib/css-converter.js +9 -1
  124. package/lib/{driver.js → driver.ts} +383 -225
  125. package/lib/execute-method-map.ts +573 -0
  126. package/lib/method-map.ts +11 -0
  127. package/lib/types.ts +59 -0
  128. package/lib/uiautomator2.js +21 -2
  129. package/lib/utils.js +2 -2
  130. package/npm-shrinkwrap.json +363 -492
  131. package/package.json +95 -69
  132. package/build/lib/desired-caps.js +0 -71
  133. package/build/lib/desired-caps.js.map +0 -1
  134. package/lib/desired-caps.js +0 -70
  135. package/lib/method-map.js +0 -11
@@ -1,397 +1,283 @@
1
- import { util } from 'appium/support';
1
+ // @ts-check
2
+ import {mixin} from './mixins';
3
+ import {util} from 'appium/support';
2
4
  import _ from 'lodash';
3
- import { errors } from 'appium/driver';
4
-
5
- const commands = {};
6
-
7
-
8
- function toOrigin (element) {
9
- return element ? util.wrapElement(util.unwrapElement(element)) : undefined;
10
- }
11
-
12
- function toPoint (x, y) {
13
- return _.isFinite(x) && _.isFinite(y) ? {x, y} : undefined;
14
- }
15
-
16
- function toRect (left, top, width, height) {
17
- return [left, top, width, height].some((v) => !_.isFinite(v))
18
- ? undefined
19
- : {left, top, width, height};
20
- }
21
-
22
- /**
23
- * @typedef {Object} ClickOptions
24
- * @property {?string} elementId - The id of the element to be clicked.
25
- * If the element is missing then both click offset coordinates must be provided.
26
- * If both the element id and offset are provided then the coordinates
27
- * are parsed as relative offsets from the top left corner of the element.
28
- * @property {?number} x - The x coordinate to click on
29
- * @property {?number} y - The y coordinate to click on
30
- */
5
+ import {errors} from 'appium/driver';
31
6
 
32
7
  /**
33
- * Performs a simple click/tap gesture
34
8
  *
35
- * @param {?ClickOptions} opts
36
- * @throws {Error} if provided options are not valid
37
- */
38
- commands.mobileClickGesture = async function mobileClickGesture (opts = {}) {
39
- const {
40
- elementId,
41
- x, y,
42
- } = opts;
43
- return await this.uiautomator2.jwproxy.command('/appium/gestures/click', 'POST', {
44
- origin: toOrigin(elementId),
45
- offset: toPoint(x, y),
46
- });
47
- };
48
-
49
- /**
50
- * @typedef {Object} LongClickOptions
51
- * @property {?string} elementId - The id of the element to be clicked.
52
- * If the element is missing then both click offset coordinates must be provided.
53
- * If both the element id and offset are provided then the coordinates
54
- * are parsed as relative offsets from the top left corner of the element.
55
- * @property {?number} x - The x coordinate to click on
56
- * @property {?number} y - The y coordinate to click on
57
- * @property {?number} duration [500] - Click duration in milliseconds.
58
- * The value must not be negative
59
- */
60
-
61
- /**
62
- * Performs a click that lasts for the given duration
63
- *
64
- * @param {?LongClickOptions} opts
65
- * @throws {Error} if provided options are not valid
66
- */
67
- commands.mobileLongClickGesture = async function mobileLongClickGesture (opts = {}) {
68
- const {
69
- elementId,
70
- x, y,
71
- duration,
72
- } = opts;
73
- return await this.uiautomator2.jwproxy.command('/appium/gestures/long_click', 'POST', {
74
- origin: toOrigin(elementId),
75
- offset: toPoint(x, y),
76
- duration,
77
- });
78
- };
79
-
80
- /**
81
- * @typedef {Object} DoubleClickOptions
82
- * @property {?string} elementId - The id of the element to be double clicked.
83
- * If the element is missing then both click offset coordinates must be provided.
84
- * If both the element id and offset are provided then the coordinates
85
- * are parsed as relative offsets from the top left corner of the element.
86
- * @property {?number} x - The x coordinate to double click on
87
- * @property {?number} y - The y coordinate to double click on
9
+ * @param {import('@appium/types').Element|string} [element]
10
+ * @returns {import('@appium/types').Element|undefined}
88
11
  */
12
+ function toOrigin(element) {
13
+ return element ? util.wrapElement(util.unwrapElement(element)) : undefined;
14
+ }
89
15
 
90
16
  /**
91
- * Performs a click that lasts for the given duration
92
17
  *
93
- * @param {?DoubleClickOptions} opts
94
- * @throws {Error} if provided options are not valid
95
- */
96
- commands.mobileDoubleClickGesture = async function mobileDoubleClickGesture (opts = {}) {
97
- const {
98
- elementId,
99
- x, y,
100
- } = opts;
101
- return await this.uiautomator2.jwproxy.command('/appium/gestures/double_click', 'POST', {
102
- origin: toOrigin(elementId),
103
- offset: toPoint(x, y),
104
- });
105
- };
106
-
107
- /**
108
- * @typedef {Object} DragOptions
109
- * @property {?string} elementId - The id of the element to be dragged.
110
- * If the element id is missing then the start coordinates must be provided.
111
- * If both the element id and the start coordinates are provided then these
112
- * coordinates are considered as offsets from the top left element corner.
113
- * @property {?number} startX - The x coordinate where the dragging starts
114
- * @property {?number} startY - The y coordinate where the dragging starts
115
- * @property {!number} endX - The x coordinate where the dragging ends
116
- * @property {!number} endY - The y coordinate where the dragging ends
117
- * @property {?number} speed [2500 * displayDensity] - The speed at which to perform
118
- * this gesture in pixels per second. The value must not be negative
18
+ * @param {number} [x]
19
+ * @param {number} [y]
20
+ * @returns {Partial<import('@appium/types').Position>|undefined}
119
21
  */
22
+ function toPoint(x, y) {
23
+ return _.isFinite(x) && _.isFinite(y) ? {x, y} : undefined;
24
+ }
120
25
 
121
26
  /**
122
- * Drags this object to the specified location.
123
27
  *
124
- * @param {?DragOptions} opts
125
- * @throws {Error} if provided options are not valid
28
+ * @param {number} [left]
29
+ * @param {number} [top]
30
+ * @param {number} [width]
31
+ * @param {number} [height]
32
+ * @returns {Partial<import('./types').RelativeRect>|undefined}
126
33
  */
127
- commands.mobileDragGesture = async function mobileDragGesture (opts = {}) {
128
- const {
129
- elementId,
130
- startX, startY,
131
- endX, endY,
132
- speed,
133
- } = opts;
134
- return await this.uiautomator2.jwproxy.command('/appium/gestures/drag', 'POST', {
135
- origin: toOrigin(elementId),
136
- start: toPoint(startX, startY),
137
- end: toPoint(endX, endY),
138
- speed,
139
- });
140
- };
34
+ function toRect(left, top, width, height) {
35
+ return [left, top, width, height].some((v) => !_.isFinite(v))
36
+ ? undefined
37
+ : {left, top, width, height};
38
+ }
141
39
 
142
40
  /**
143
- * @typedef {Object} FlingOptions
144
- * @property {?string} elementId - The id of the element to be flinged.
145
- * If the element id is missing then fling bounding area must be provided.
146
- * If both the element id and the fling bounding area are provided then this
147
- * area is effectively ignored.
148
- * @property {?number} left - The left coordinate of the fling bounding area
149
- * @property {?number} top - The top coordinate of the fling bounding area
150
- * @property {?number} width - The width of the fling bounding area
151
- * @property {?number} height - The height of the fling bounding area
152
- * @property {!string} direction - Direction of the fling.
153
- * Acceptable values are: `up`, `down`, `left` and `right` (case insensitive)
154
- * @property {?number} speed [7500 * displayDensity] - The speed at which to perform this
155
- * gesture in pixels per second. The value must be greater than the minimum fling
156
- * velocity for the given view (50 by default)
41
+ * @type {import('./mixins').UIA2GesturesMixin}
42
+ * @satisfies {import('@appium/types').ExternalDriver}
157
43
  */
44
+ const GesturesMixin = {
45
+ /**
46
+ * Performs a simple click/tap gesture
47
+ *
48
+ * @throws {Error} if provided options are not valid
49
+ */
50
+ async mobileClickGesture(opts = {}) {
51
+ const {elementId, x, y} = opts;
52
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
53
+ '/appium/gestures/click',
54
+ 'POST',
55
+ {
56
+ origin: toOrigin(elementId),
57
+ offset: toPoint(x, y),
58
+ }
59
+ );
60
+ },
158
61
 
159
- /**
160
- * Drags to the specified location.
161
- *
162
- * @param {?FlingOptions} opts
163
- * @throws {Error} if provided options are not valid
164
- * @returns {boolean} True if the object can still scroll in the given direction.
165
- */
166
- commands.mobileFlingGesture = async function mobileFlingGesture (opts = {}) {
167
- const {
168
- elementId,
169
- left, top, width, height,
170
- direction,
171
- speed,
172
- } = opts;
173
- return await this.uiautomator2.jwproxy.command('/appium/gestures/fling', 'POST', {
174
- origin: toOrigin(elementId),
175
- area: toRect(left, top, width, height),
176
- direction,
177
- speed,
178
- });
179
- };
62
+ /**
63
+ * Performs a click that lasts for the given duration
64
+ *
65
+ * @throws {Error} if provided options are not valid
66
+ */
67
+ async mobileLongClickGesture(opts = {}) {
68
+ const {elementId, x, y, duration} = opts;
69
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
70
+ '/appium/gestures/long_click',
71
+ 'POST',
72
+ {
73
+ origin: toOrigin(elementId),
74
+ offset: toPoint(x, y),
75
+ duration,
76
+ }
77
+ );
78
+ },
180
79
 
181
- /**
182
- * @typedef {Object} PinchOptions
183
- * @property {?string} elementId - The id of the element to be pinched.
184
- * If the element id is missing then pinch bounding area must be provided.
185
- * If both the element id and the pinch bounding area are provided then the
186
- * area is effectively ignored.
187
- * @property {?number} left - The left coordinate of the pinch bounding area
188
- * @property {?number} top - The top coordinate of the pinch bounding area
189
- * @property {?number} width - The width of the pinch bounding area
190
- * @property {?number} height - The height of the pinch bounding area
191
- * @property {!number} percent - The size of the pinch as a percentage of the pinch area size.
192
- * Valid values must be float numbers in range 0..1, where 1.0 is 100%
193
- * @property {?number} speed [2500 * displayDensity] - The speed at which to perform
194
- * this gesture in pixels per second. The value must not be negative
195
- */
80
+ /**
81
+ * Performs a click that lasts for the given duration
82
+ *
83
+ * @throws {Error} if provided options are not valid
84
+ */
85
+ async mobileDoubleClickGesture(opts = {}) {
86
+ const {elementId, x, y} = opts;
87
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
88
+ '/appium/gestures/double_click',
89
+ 'POST',
90
+ {
91
+ origin: toOrigin(elementId),
92
+ offset: toPoint(x, y),
93
+ }
94
+ );
95
+ },
196
96
 
197
- /**
198
- * Performs a pinch close gesture.
199
- *
200
- * @param {?PinchOptions} opts
201
- * @throws {Error} if provided options are not valid
202
- */
203
- commands.mobilePinchCloseGesture = async function mobilePinchCloseGesture (opts = {}) {
204
- const {
205
- elementId,
206
- left, top, width, height,
207
- percent,
208
- speed,
209
- } = opts;
210
- return await this.uiautomator2.jwproxy.command('/appium/gestures/pinch_close', 'POST', {
211
- origin: toOrigin(elementId),
212
- area: toRect(left, top, width, height),
213
- percent,
214
- speed,
215
- });
216
- };
97
+ /**
98
+ * Drags this object to the specified location.
99
+ *
100
+ * @throws {Error} if provided options are not valid
101
+ */
102
+ async mobileDragGesture(opts) {
103
+ const {elementId, startX, startY, endX, endY, speed} = opts;
104
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
105
+ '/appium/gestures/drag',
106
+ 'POST',
107
+ {
108
+ origin: toOrigin(elementId),
109
+ start: toPoint(startX, startY),
110
+ end: toPoint(endX, endY),
111
+ speed,
112
+ }
113
+ );
114
+ },
217
115
 
218
- /**
219
- * Performs a pinch open gesture.
220
- *
221
- * @param {?PinchOptions} opts
222
- * @throws {Error} if provided options are not valid
223
- */
224
- commands.mobilePinchOpenGesture = async function mobilePinchOpenGesture (opts = {}) {
225
- const {
226
- elementId,
227
- left, top, width, height,
228
- percent,
229
- speed,
230
- } = opts;
231
- return await this.uiautomator2.jwproxy.command('/appium/gestures/pinch_open', 'POST', {
232
- origin: toOrigin(elementId),
233
- area: toRect(left, top, width, height),
234
- percent,
235
- speed,
236
- });
237
- };
116
+ /**
117
+ * Drags to the specified location.
118
+ *
119
+ * @throws {Error} if provided options are not valid
120
+ * @returns True if the object can still scroll in the given direction.
121
+ */
122
+ async mobileFlingGesture(opts) {
123
+ const {elementId, left, top, width, height, direction, speed} = opts;
124
+ return /** @type {boolean} */ (
125
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
126
+ '/appium/gestures/fling',
127
+ 'POST',
128
+ {
129
+ origin: toOrigin(elementId),
130
+ area: toRect(left, top, width, height),
131
+ direction,
132
+ speed,
133
+ }
134
+ )
135
+ );
136
+ },
238
137
 
239
- /**
240
- * @typedef {Object} SwipeOptions
241
- * @property {?string} elementId - The id of the element to be swiped.
242
- * If the element id is missing then swipe bounding area must be provided.
243
- * If both the element id and the swipe bounding area are provided then the
244
- * area is effectively ignored.
245
- * @property {?number} left - The left coordinate of the swipe bounding area
246
- * @property {?number} top - The top coordinate of the swipe bounding area
247
- * @property {?number} width - The width of the swipe bounding area
248
- * @property {?number} height - The height of the swipe bounding area
249
- * @property {!string} direction - Direction of the swipe.
250
- * Acceptable values are: `up`, `down`, `left` and `right` (case insensitive)
251
- * @property {!number} percent - The size of the swipe as a percentage of the swipe area size.
252
- * Valid values must be float numbers in range 0..1, where 1.0 is 100%
253
- * @property {?number} speed [5000 * displayDensity] - The speed at which to perform this
254
- * gesture in pixels per second. The value must not be negative
255
- */
138
+ /**
139
+ * Performs a pinch close gesture.
140
+ *
141
+ * @throws {Error} if provided options are not valid
142
+ */
143
+ async mobilePinchCloseGesture(opts) {
144
+ const {elementId, left, top, width, height, percent, speed} = opts;
145
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
146
+ '/appium/gestures/pinch_close',
147
+ 'POST',
148
+ {
149
+ origin: toOrigin(elementId),
150
+ area: toRect(left, top, width, height),
151
+ percent,
152
+ speed,
153
+ }
154
+ );
155
+ },
256
156
 
257
- /**
258
- * Performs a swipe gesture.
259
- *
260
- * @param {?SwipeOptions} opts
261
- * @throws {Error} if provided options are not valid
262
- */
263
- commands.mobileSwipeGesture = async function mobileSwipeGesture (opts = {}) {
264
- const {
265
- elementId,
266
- left, top, width, height,
267
- direction,
268
- percent,
269
- speed,
270
- } = opts;
271
- return await this.uiautomator2.jwproxy.command('/appium/gestures/swipe', 'POST', {
272
- origin: toOrigin(elementId),
273
- area: toRect(left, top, width, height),
274
- direction,
275
- percent,
276
- speed,
277
- });
278
- };
157
+ /**
158
+ * Performs a pinch open gesture.
159
+ *
160
+ * @throws {Error} if provided options are not valid
161
+ */
162
+ async mobilePinchOpenGesture(opts) {
163
+ const {elementId, left, top, width, height, percent, speed} = opts;
164
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
165
+ '/appium/gestures/pinch_open',
166
+ 'POST',
167
+ {
168
+ origin: toOrigin(elementId),
169
+ area: toRect(left, top, width, height),
170
+ percent,
171
+ speed,
172
+ }
173
+ );
174
+ },
279
175
 
280
- /**
281
- * @typedef {Object} ScrollOptions
282
- * @property {?string} elementId - The id of the element to be scrolled.
283
- * If the element id is missing then scroll bounding area must be provided.
284
- * If both the element id and the scroll bounding area are provided then this
285
- * area is effectively ignored.
286
- * @property {?number} left - The left coordinate of the scroll bounding area
287
- * @property {?number} top - The top coordinate of the scroll bounding area
288
- * @property {?number} width - The width of the scroll bounding area
289
- * @property {?number} height - The height of the scroll bounding area
290
- * @property {!string} direction - Direction of the scroll.
291
- * Acceptable values are: `up`, `down`, `left` and `right` (case insensitive)
292
- * @property {!number} percent - The size of the scroll as a percentage of the scrolling area size.
293
- * Valid values must be float numbers greater than zero, where 1.0 is 100%
294
- * @property {?number} speed [5000 * displayDensity] - The speed at which to perform this gesture
295
- * in pixels per second. The value must not be negative
296
- */
176
+ /**
177
+ * Performs a swipe gesture.
178
+ *
179
+ * @throws {Error} if provided options are not valid
180
+ */
181
+ async mobileSwipeGesture(opts) {
182
+ const {elementId, left, top, width, height, direction, percent, speed} = opts;
183
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
184
+ '/appium/gestures/swipe',
185
+ 'POST',
186
+ {
187
+ origin: toOrigin(elementId),
188
+ area: toRect(left, top, width, height),
189
+ direction,
190
+ percent,
191
+ speed,
192
+ }
193
+ );
194
+ },
297
195
 
298
- /**
299
- * Performs a scroll gesture.
300
- *
301
- * @param {?ScrollOptions} opts
302
- * @throws {Error} if provided options are not valid
303
- * @returns {boolean} True if the object can still scroll in the given direction.
304
- */
305
- commands.mobileScrollGesture = async function mobileScrollGesture (opts = {}) {
306
- const {
307
- elementId,
308
- left, top, width, height,
309
- direction,
310
- percent,
311
- speed,
312
- } = opts;
313
- return await this.uiautomator2.jwproxy.command('/appium/gestures/scroll', 'POST', {
314
- origin: toOrigin(elementId),
315
- area: toRect(left, top, width, height),
316
- direction,
317
- percent,
318
- speed,
319
- });
320
- };
196
+ /**
197
+ * Performs a scroll gesture.
198
+ *
199
+ * @throws {Error} if provided options are not valid
200
+ * @returns True if the object can still scroll in the given direction.
201
+ */
202
+ async mobileScrollGesture(opts) {
203
+ const {elementId, left, top, width, height, direction, percent, speed} = opts;
204
+ return /** @type {boolean} */ (
205
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
206
+ '/appium/gestures/scroll',
207
+ 'POST',
208
+ {
209
+ origin: toOrigin(elementId),
210
+ area: toRect(left, top, width, height),
211
+ direction,
212
+ percent,
213
+ speed,
214
+ }
215
+ )
216
+ );
217
+ },
321
218
 
322
- /**
323
- * @typedef {Object} ScrollElementToElementOpts
324
- * @property {string} elementId The identifier of the scrollable element,
325
- * which is going to be scrolled. It is required this element
326
- * is a valid scrollable container and it was located by `-android uiautomator`
327
- * strategy.
328
- * @property {string} elementToId The identifier of the item, which belongs
329
- * to the scrollable element above, and which should become visible after
330
- * the scrolling operation is finished. It is required this element
331
- * was located by `-android uiautomator` strategy.
332
- */
219
+ /**
220
+ * Scrolls the given scrollable element `elementId` until `elementToId`
221
+ * becomes visible. This function returns immediately if the `elementToId`
222
+ * is already visible in the view port. Otherwise it would scroll
223
+ * to the very beginning of the scrollable control and tries to reach the destination element
224
+ * by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
225
+ * is detected automatically.
226
+ *
227
+ * @throws {Error} if the scrolling operation cannot be performed
228
+ */
229
+ async mobileScrollBackTo(opts) {
230
+ const {elementId, elementToId} = opts;
231
+ if (!elementId || !elementToId) {
232
+ throw new errors.InvalidArgumentError(
233
+ `Both elementId and elementToId arguments must be provided`
234
+ );
235
+ }
236
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
237
+ `/appium/element/${util.unwrapElement(elementId)}/scroll_to/${util.unwrapElement(
238
+ elementToId
239
+ )}`,
240
+ 'POST',
241
+ {}
242
+ );
243
+ },
333
244
 
334
- /**
335
- * Scrolls the given scrollable element `elementId` until `elementToId`
336
- * becomes visible. This function returns immediately if the `elementToId`
337
- * is already visible in the view port. Otherwise it would scroll
338
- * to the very beginning of the scrollable control and tries to reach the destination element
339
- * by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
340
- * is detected automatically.
341
- *
342
- * @param {ScrollElementToElementOpts} opts
343
- * @throws {Error} if the scrolling operation cannot be performed
344
- */
345
- commands.mobileScrollBackTo = async function (opts = {}) {
346
- const {elementId, elementToId} = opts;
347
- if (!elementId || !elementToId) {
348
- throw new errors.InvalidArgumentError(`Both elementId and elementToId arguments must be provided`);
349
- }
350
- return await this.uiautomator2.jwproxy.command(
351
- `/appium/element/${util.unwrapElement(elementId)}/scroll_to/${util.unwrapElement(elementToId)}`, 'POST', {});
245
+ /**
246
+ * Scrolls the given scrollable element until the element identified
247
+ * by `strategy` and `selector` becomes visible. This function returns immediately if the
248
+ * destination element is already visible in the view port. Otherwise it would scroll
249
+ * to the very beginning of the scrollable control and tries to reach the destination element
250
+ * by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
251
+ * is detected automatically.
252
+ *
253
+ * @throws {Error} if the scrolling operation cannot be performed
254
+ */
255
+ async mobileScroll(opts) {
256
+ const {
257
+ element,
258
+ elementId, // `element` is deprecated, use `elementId` instead
259
+ strategy,
260
+ selector,
261
+ maxSwipes,
262
+ } = opts;
263
+ if (!strategy || !selector) {
264
+ throw new errors.InvalidArgumentError(
265
+ `Both strategy and selector arguments must be provided`
266
+ );
267
+ }
268
+ await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
269
+ '/touch/scroll',
270
+ 'POST',
271
+ {
272
+ origin: toOrigin(elementId || element),
273
+ params: {strategy, selector, maxSwipes},
274
+ }
275
+ );
276
+ },
352
277
  };
353
278
 
354
- /**
355
- * @typedef {Object} ScrollOpts
356
- * @property {?string} elementId The identifier of an element. It is required this element
357
- * is a valid scrollable container and it was located by `-android uiautomator`
358
- * strategy. If this property is not provided then the first currently available scrollable view
359
- * is selected for the interaction.
360
- * @property {!string} strategy The following strategies are supported:
361
- * - `accessibility id` (UiSelector().description)
362
- * - `class name` (UiSelector().className)
363
- * - `-android uiautomator` (UiSelector)
364
- * @property {!string} selector The corresponding lookup value for the given
365
- * strategy.
366
- * @property {?number} maxSwipes The maximum number of swipes to perform
367
- * on the target scrollable view in order to reach the destination element.
368
- * In case this value is unset then it would be retrieved from the scrollable
369
- * element itself (vua `getMaxSearchSwipes()` property).
370
- */
279
+ mixin(GesturesMixin);
371
280
 
372
281
  /**
373
- * Scrolls the given scrollable element until the element identified
374
- * by `strategy` and `selector` becomes visible. This function returns immediately if the
375
- * destination element is already visible in the view port. Otherwise it would scroll
376
- * to the very beginning of the scrollable control and tries to reach the destination element
377
- * by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
378
- * is detected automatically.
379
- *
380
- * @param {ScrollOpts} opts
381
- * @throws {Error} if the scrolling operation cannot be performed
282
+ * @typedef {import('../uiautomator2').UiAutomator2Server} UiAutomator2Server
382
283
  */
383
- commands.mobileScroll = async function (opts = {}) {
384
- const {
385
- element, elementId, // `element` is deprecated, use `elementId` instead
386
- strategy, selector, maxSwipes
387
- } = opts;
388
- if (!strategy || !selector) {
389
- throw new errors.InvalidArgumentError(`Both strategy and selector arguments must be provided`);
390
- }
391
- return await this.uiautomator2.jwproxy.command('/touch/scroll', 'POST', {
392
- origin: toOrigin(elementId || element),
393
- params: {strategy, selector, maxSwipes},
394
- });
395
- };
396
-
397
- export default commands;