appium-uiautomator2-driver 3.10.0 → 4.0.1

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 (73) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +19 -1
  3. package/build/lib/commands/actions.d.ts +13 -7
  4. package/build/lib/commands/actions.d.ts.map +1 -1
  5. package/build/lib/commands/actions.js +24 -10
  6. package/build/lib/commands/actions.js.map +1 -1
  7. package/build/lib/commands/alert.d.ts +8 -4
  8. package/build/lib/commands/alert.d.ts.map +1 -1
  9. package/build/lib/commands/alert.js +10 -6
  10. package/build/lib/commands/alert.js.map +1 -1
  11. package/build/lib/commands/app-management.d.ts +10 -6
  12. package/build/lib/commands/app-management.d.ts.map +1 -1
  13. package/build/lib/commands/app-management.js +13 -10
  14. package/build/lib/commands/app-management.js.map +1 -1
  15. package/build/lib/commands/clipboard.d.ts +0 -12
  16. package/build/lib/commands/clipboard.d.ts.map +1 -1
  17. package/build/lib/commands/clipboard.js +0 -18
  18. package/build/lib/commands/clipboard.js.map +1 -1
  19. package/build/lib/commands/element.d.ts +3 -2
  20. package/build/lib/commands/element.d.ts.map +1 -1
  21. package/build/lib/commands/element.js +3 -4
  22. package/build/lib/commands/element.js.map +1 -1
  23. package/build/lib/commands/gestures.d.ts +130 -22
  24. package/build/lib/commands/gestures.d.ts.map +1 -1
  25. package/build/lib/commands/gestures.js +130 -33
  26. package/build/lib/commands/gestures.js.map +1 -1
  27. package/build/lib/commands/keyboard.d.ts +11 -4
  28. package/build/lib/commands/keyboard.d.ts.map +1 -1
  29. package/build/lib/commands/keyboard.js +13 -7
  30. package/build/lib/commands/keyboard.js.map +1 -1
  31. package/build/lib/commands/navigation.d.ts +5 -2
  32. package/build/lib/commands/navigation.d.ts.map +1 -1
  33. package/build/lib/commands/navigation.js +5 -3
  34. package/build/lib/commands/navigation.js.map +1 -1
  35. package/build/lib/commands/screenshot.d.ts +4 -2
  36. package/build/lib/commands/screenshot.d.ts.map +1 -1
  37. package/build/lib/commands/screenshot.js +4 -3
  38. package/build/lib/commands/screenshot.js.map +1 -1
  39. package/build/lib/commands/types.d.ts +0 -387
  40. package/build/lib/commands/types.d.ts.map +1 -1
  41. package/build/lib/driver.d.ts +540 -8
  42. package/build/lib/driver.d.ts.map +1 -1
  43. package/build/lib/driver.js +2 -7
  44. package/build/lib/driver.js.map +1 -1
  45. package/build/lib/execute-method-map.d.ts +540 -0
  46. package/build/lib/execute-method-map.d.ts.map +1 -0
  47. package/build/lib/execute-method-map.js +257 -0
  48. package/build/lib/execute-method-map.js.map +1 -0
  49. package/build/tsconfig.tsbuildinfo +1 -1
  50. package/lib/commands/actions.js +32 -10
  51. package/lib/commands/alert.js +10 -6
  52. package/lib/commands/app-management.js +14 -11
  53. package/lib/commands/clipboard.js +0 -18
  54. package/lib/commands/element.js +3 -4
  55. package/lib/commands/gestures.js +184 -38
  56. package/lib/commands/keyboard.js +13 -8
  57. package/lib/commands/navigation.js +5 -3
  58. package/lib/commands/screenshot.js +4 -3
  59. package/lib/commands/types.ts +0 -406
  60. package/lib/driver.ts +2 -16
  61. package/lib/execute-method-map.ts +269 -0
  62. package/npm-shrinkwrap.json +41 -48
  63. package/package.json +3 -3
  64. package/build/lib/commands/app-strings.d.ts +0 -12
  65. package/build/lib/commands/app-strings.d.ts.map +0 -1
  66. package/build/lib/commands/app-strings.js +0 -19
  67. package/build/lib/commands/app-strings.js.map +0 -1
  68. package/build/lib/commands/execute.d.ts +0 -15
  69. package/build/lib/commands/execute.d.ts.map +0 -1
  70. package/build/lib/commands/execute.js +0 -83
  71. package/build/lib/commands/execute.js.map +0 -1
  72. package/lib/commands/app-strings.js +0 -16
  73. package/lib/commands/execute.js +0 -93
@@ -1,29 +1,51 @@
1
1
  /**
2
- * See https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-scheduleaction
2
+ * @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-scheduleaction
3
3
  * @this {AndroidUiautomator2Driver}
4
- * @param {Record<string, any>} [opts={}]
4
+ * @param {string} name
5
+ * @param {import('@appium/types').StringRecord[]} steps
6
+ * @param {number} [maxPass]
7
+ * @param {number} [maxFail]
8
+ * @param {number} [times]
9
+ * @param {number} [intervalMs]
10
+ * @param {number} [maxHistoryItems]
5
11
  * @returns {Promise<any>}
6
12
  */
7
- export async function mobileScheduleAction(opts = {}) {
13
+ export async function mobileScheduleAction(
14
+ name,
15
+ steps,
16
+ maxPass,
17
+ maxFail,
18
+ times,
19
+ intervalMs,
20
+ maxHistoryItems,
21
+ ) {
8
22
  return await this.uiautomator2.jwproxy.command(
9
23
  '/appium/schedule_action',
10
24
  'POST',
11
- opts
25
+ {
26
+ name,
27
+ steps,
28
+ maxFail,
29
+ maxPass,
30
+ times,
31
+ intervalMs,
32
+ maxHistoryItems,
33
+ }
12
34
  );
13
35
  }
14
36
 
15
37
  /**
16
38
  * @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-getactionhistory
17
39
  * @this {AndroidUiautomator2Driver}
18
- * @param {import('./types').ActionArgs} [opts={}]
40
+ * @param {string} name
19
41
  * @returns {Promise<import('./types').ActionResult>}
20
42
  */
21
- export async function mobileGetActionHistory(opts) {
43
+ export async function mobileGetActionHistory(name) {
22
44
  return /** @type {import('./types').ActionResult} */ (
23
45
  await this.uiautomator2.jwproxy.command(
24
46
  '/appium/action_history',
25
47
  'POST',
26
- opts ?? {}
48
+ {name}
27
49
  )
28
50
  );
29
51
  }
@@ -31,14 +53,14 @@ export async function mobileGetActionHistory(opts) {
31
53
  /**
32
54
  * @this {AndroidUiautomator2Driver}
33
55
  * @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-unscheduleaction
34
- * @param {import('./types').ActionArgs} [opts={}]
56
+ * @param {string} name
35
57
  * @returns {Promise<any>}
36
58
  */
37
- export async function mobileUnscheduleAction(opts) {
59
+ export async function mobileUnscheduleAction(name) {
38
60
  return await this.uiautomator2.jwproxy.command(
39
61
  '/appium/unschedule_action',
40
62
  'POST',
41
- opts ?? {}
63
+ {name}
42
64
  );
43
65
  }
44
66
 
@@ -14,14 +14,16 @@ export async function getAlertText() {
14
14
 
15
15
  /**
16
16
  * @this {AndroidUiautomator2Driver}
17
- * @param {import('./types').AcceptAlertOptions} [opts={}]
17
+ * @param {string} [buttonLabel] The name of the button to click in order to accept the alert.
18
+ * If the name is not provided
19
+ * then the script will try to detect the button automatically.
18
20
  * @returns {Promise<void>}
19
21
  */
20
- export async function mobileAcceptAlert(opts = {}) {
22
+ export async function mobileAcceptAlert(buttonLabel) {
21
23
  await this.uiautomator2.jwproxy.command(
22
24
  '/alert/accept',
23
25
  'POST',
24
- opts
26
+ {buttonLabel}
25
27
  );
26
28
  }
27
29
 
@@ -35,14 +37,16 @@ export async function postAcceptAlert() {
35
37
 
36
38
  /**
37
39
  * @this {AndroidUiautomator2Driver}
38
- * @param {import('./types').DismissAlertOptions} [opts={}]
40
+ * @param {string} [buttonLabel] The name of the button to click in order to dismiss the alert.
41
+ * If the name is not provided
42
+ * then the script will try to detect the button automatically.
39
43
  * @returns {Promise<void>}
40
44
  */
41
- export async function mobileDismissAlert(opts = {}) {
45
+ export async function mobileDismissAlert(buttonLabel) {
42
46
  await this.uiautomator2.jwproxy.command(
43
47
  '/alert/dismiss',
44
48
  'POST',
45
- opts
49
+ {buttonLabel}
46
50
  );
47
51
  }
48
52
 
@@ -5,30 +5,33 @@ import {APK_EXTENSION} from '../extensions';
5
5
 
6
6
  /**
7
7
  * Install multiple APKs with `install-multiple` option.
8
- * @this {AndroidUiautomator2Driver}=
9
- * @param {import('./types').InstallMultipleApksOptions} opts
8
+ * @this {AndroidUiautomator2Driver}
9
+ * @param {string[]} apks The list of APKs to install. Each APK should be a path to a apk
10
+ * or downloadable URL as HTTP/HTTPS.
11
+ * @param {import('./types').InstallOptions} [options] Installation options.
10
12
  * @throws {Error} if an error occured while installing the given APKs.
11
13
  * @returns {Promise<void>}
12
14
  */
13
- export async function mobileInstallMultipleApks(opts) {
14
- if (!_.isArray(opts.apks) || _.isEmpty(opts.apks)) {
15
+ export async function mobileInstallMultipleApks(apks, options) {
16
+ if (!_.isArray(apks) || _.isEmpty(apks)) {
15
17
  throw new errors.InvalidArgumentError('No apks are given to install');
16
18
  }
17
- const apks = await B.all(
18
- opts.apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION]))
19
+ const configuredApks = await B.all(
20
+ apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION]))
19
21
  );
20
- await this.adb.installMultipleApks(apks, opts.options);
22
+ await this.adb.installMultipleApks(configuredApks, options);
21
23
  }
22
24
 
23
25
  /**
24
- * Puts the app to background and waits the given number of seconds Then restores the app
26
+ * Puts the app to background and waits the given number of seconds then restores the app
25
27
  * if necessary. The call is blocking.
28
+ *
26
29
  * @this {AndroidUiautomator2Driver}
27
- * @param {import('./types').BackgroundAppOptions} [opts={}]
30
+ * @param {number} [seconds=-1] The amount of seconds to wait between putting the app to background and restoring it.
31
+ * Any negative value means to not restore the app after putting it to background.
28
32
  * @returns {Promise<void>}
29
33
  */
30
- export async function mobileBackgroundApp(opts = {}) {
31
- const {seconds = -1} = opts;
34
+ export async function mobileBackgroundApp(seconds = -1) {
32
35
  await this.background(seconds);
33
36
  }
34
37
 
@@ -15,15 +15,6 @@ export async function getClipboard() {
15
15
  );
16
16
  }
17
17
 
18
- /**
19
- * @this {AndroidUiautomator2Driver}
20
- * @returns {Promise<string>} Base64-encoded content of the clipboard
21
- * or an empty string if the clipboard is empty.
22
- */
23
- export async function mobileGetClipboard() {
24
- return await this.getClipboard();
25
- }
26
-
27
18
  /**
28
19
  * @this {AndroidUiautomator2Driver}
29
20
  * @param {string} content Base64-encoded clipboard payload
@@ -41,15 +32,6 @@ export async function setClipboard(content, contentType, label) {
41
32
  );
42
33
  }
43
34
 
44
- /**
45
- * @this {AndroidUiautomator2Driver}
46
- * @param {import('./types').SetClipboardOpts} opts
47
- * @returns {Promise<void>}
48
- */
49
- export async function mobileSetClipboard(opts) {
50
- await this.setClipboard(opts.content, opts.contentType, opts.label);
51
- }
52
-
53
35
  /**
54
36
  * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
55
37
  */
@@ -1,7 +1,6 @@
1
1
  import B from 'bluebird';
2
2
  import _ from 'lodash';
3
3
  import {PROTOCOLS} from 'appium/driver';
4
- import {utils} from 'appium-android-driver';
5
4
 
6
5
  /**
7
6
  * @this {AndroidUiautomator2Driver}
@@ -229,12 +228,12 @@ export async function getElementRect(elementId) {
229
228
  /**
230
229
  * Sends text to the given element by replacing its previous content
231
230
  * @this {AndroidUiautomator2Driver}
232
- * @param {import('./types').ReplaceValueOptions} opts
231
+ * @param {string} elementId The id of the element whose content will be replaced.
232
+ * @param {string} text The actual text to set.
233
233
  * @throws {Error} If there was a faulre while setting the text
234
234
  * @returns {Promise<void>}
235
235
  */
236
- export async function mobileReplaceElementValue(opts) {
237
- const {elementId, text} = utils.requireArgs(['elementId', 'text'], opts);
236
+ export async function mobileReplaceElementValue(elementId, text) {
238
237
  await this.uiautomator2.jwproxy.command(
239
238
  `/element/${elementId}/value`,
240
239
  'POST',
@@ -6,12 +6,16 @@ import {errors} from 'appium/driver';
6
6
  * Performs a simple click/tap gesture
7
7
  *
8
8
  * @this {AndroidUiautomator2Driver}
9
- * @param {import('./types').ClickOptions} [opts={}]
9
+ * @param {string} [elementId] The id of the element to be clicked.
10
+ * If the element is missing then both click offset coordinates must be provided.
11
+ * If both the element id and offset are provided then the coordinates are parsed
12
+ * as relative offsets from the top left corner of the element.
13
+ * @param {number} [x] The x coordinate to click on.
14
+ * @param {number} [y] The y coordinate to click on.
10
15
  * @returns {Promise<void>}
11
16
  * @throws {Error} if provided options are not valid
12
17
  */
13
- export async function mobileClickGesture(opts = {}) {
14
- const {elementId, x, y} = opts;
18
+ export async function mobileClickGesture(elementId, x, y) {
15
19
  await this.uiautomator2.jwproxy.command(
16
20
  '/appium/gestures/click',
17
21
  'POST',
@@ -26,12 +30,18 @@ export async function mobileClickGesture(opts = {}) {
26
30
  * Performs a click that lasts for the given duration
27
31
  *
28
32
  * @this {AndroidUiautomator2Driver}
29
- * @param {import('./types').LongClickOptions} [opts={}]
33
+ * @param {string} [elementId] The id of the element to be clicked.
34
+ * If the element is missing then both click offset coordinates must be provided.
35
+ * If both the element id and offset are provided then the coordinates are parsed
36
+ * as relative offsets from the top left corner of the element.
37
+ * @param {number} [x] The x coordinate to click on.
38
+ * @param {number} [y] The y coordinate to click on.
39
+ * @param {number} [duration] Click duration in milliseconds. The value must not be negative.
40
+ * Default is 500.
30
41
  * @returns {Promise<void>}
31
42
  * @throws {Error} if provided options are not valid
32
43
  */
33
- export async function mobileLongClickGesture(opts = {}) {
34
- const {elementId, x, y, duration} = opts;
44
+ export async function mobileLongClickGesture(elementId, x, y, duration) {
35
45
  await this.uiautomator2.jwproxy.command(
36
46
  '/appium/gestures/long_click',
37
47
  'POST',
@@ -46,12 +56,16 @@ export async function mobileLongClickGesture(opts = {}) {
46
56
  /**
47
57
  * Performs a click that lasts for the given duration
48
58
  * @this {AndroidUiautomator2Driver}
49
- * @param {import('./types').DoubleClickOptions} [opts={}]
59
+ * @param {string} [elementId] The id of the element to be clicked.
60
+ * If the element is missing then both click offset coordinates must be provided.
61
+ * If both the element id and offset are provided then the coordinates are parsed
62
+ * as relative offsets from the top left corner of the element.
63
+ * @param {number} [x] The x coordinate to click on.
64
+ * @param {number} [y] The y coordinate to click on.
50
65
  * @returns {Promise<void>}
51
66
  * @throws {Error} if provided options are not valid
52
67
  */
53
- export async function mobileDoubleClickGesture(opts = {}) {
54
- const {elementId, x, y} = opts;
68
+ export async function mobileDoubleClickGesture(elementId, x, y) {
55
69
  await this.uiautomator2.jwproxy.command(
56
70
  '/appium/gestures/double_click',
57
71
  'POST',
@@ -65,12 +79,28 @@ export async function mobileDoubleClickGesture(opts = {}) {
65
79
  /**
66
80
  * Drags this object to the specified location.
67
81
  * @this {AndroidUiautomator2Driver}
68
- * @param {import('./types').DragOptions} opts
82
+ * @param {string} [elementId] The id of the element to be dragged.
83
+ * If the element id is missing then the start coordinates must be provided.
84
+ * If both the element id and the start coordinates are provided then these
85
+ * coordinates are considered as offsets from the top left element corner.
86
+ * @param {number} [startX] The x coordinate where the dragging starts
87
+ * @param {number} [startY] The y coordinate where the dragging starts
88
+ * @param {number} [endX] The x coordinate where the dragging ends
89
+ * @param {number} [endY] The y coordinate where the dragging ends
90
+ * @param {number} [speed] The speed at which to perform this gesture in pixels per second.
91
+ * The value must not be negative.
92
+ * Default is 2500 * displayDensity.
69
93
  * @returns {Promise<void>}
70
94
  * @throws {Error} if provided options are not valid
71
95
  */
72
- export async function mobileDragGesture(opts) {
73
- const {elementId, startX, startY, endX, endY, speed} = opts;
96
+ export async function mobileDragGesture(
97
+ elementId,
98
+ startX,
99
+ startY,
100
+ endX,
101
+ endY,
102
+ speed,
103
+ ) {
74
104
  await this.uiautomator2.jwproxy.command(
75
105
  '/appium/gestures/drag',
76
106
  'POST',
@@ -88,11 +118,30 @@ export async function mobileDragGesture(opts) {
88
118
  *
89
119
  * @throws {Error} if provided options are not valid
90
120
  * @this {AndroidUiautomator2Driver}
91
- * @param {import('./types').FlingOptions} opts
121
+ * @param {string} direction Direction of the fling.
122
+ * Acceptable values are: `up`, `down`, `left` and `right` (case insensitive).
123
+ * @param {string} [elementId] The id of the element to be flinged.
124
+ * If the element id is missing then fling bounding area must be provided.
125
+ * If both the element id and the fling bounding area are provided then this
126
+ * area is effectively ignored.
127
+ * @param {number} [left] The left coordinate of the fling bounding area.
128
+ * @param {number} [top] The top coordinate of the fling bounding area.
129
+ * @param {number} [width] The width of the fling bounding area.
130
+ * @param {number} [height] The height of the fling bounding area.
131
+ * @param {number} [speed] The speed at which to perform this gesture in pixels per second.
132
+ * The value must be greater than the minimum fling velocity for the given view (50 by default).
133
+ * Default is 7500 * displayDensity.
92
134
  * @returns {Promise<boolean>} True if the object can still scroll in the given direction.
93
135
  */
94
- export async function mobileFlingGesture(opts) {
95
- const {elementId, left, top, width, height, direction, speed} = opts;
136
+ export async function mobileFlingGesture(
137
+ direction,
138
+ elementId,
139
+ left,
140
+ top,
141
+ width,
142
+ height,
143
+ speed,
144
+ ) {
96
145
  return /** @type {boolean} */ (
97
146
  await this.uiautomator2.jwproxy.command(
98
147
  '/appium/gestures/fling',
@@ -110,12 +159,31 @@ export async function mobileFlingGesture(opts) {
110
159
  /**
111
160
  * Performs a pinch close gesture.
112
161
  * @this {AndroidUiautomator2Driver}
113
- * @param {import('./types').PinchOptions} opts
162
+ * @param {number} percent The size of the pinch as a percentage of the pinch area size.
163
+ * Valid values must be float numbers in range 0..1, where 1.0 is 100%
164
+ * @param {string} [elementId] The id of the element to be pinched.
165
+ * If the element id is missing then pinch bounding area must be provided.
166
+ * If both the element id and the pinch bounding area are provided then the
167
+ * area is effectively ignored.
168
+ * @param {number} [left] The left coordinate of the pinch bounding area.
169
+ * @param {number} [top] The top coordinate of the pinch bounding area.
170
+ * @param {number} [width] The width of the pinch bounding area.
171
+ * @param {number} [height] The height of the pinch bounding area.
172
+ * @param {number} [speed] The speed at which to perform this gesture in pixels per second.
173
+ * The value must not be negative.
174
+ * Default is 2500 * displayDensity.
114
175
  * @returns {Promise<void>}
115
176
  * @throws {Error} if provided options are not valid
116
177
  */
117
- export async function mobilePinchCloseGesture(opts) {
118
- const {elementId, left, top, width, height, percent, speed} = opts;
178
+ export async function mobilePinchCloseGesture(
179
+ percent,
180
+ elementId,
181
+ left,
182
+ top,
183
+ width,
184
+ height,
185
+ speed,
186
+ ) {
119
187
  await this.uiautomator2.jwproxy.command(
120
188
  '/appium/gestures/pinch_close',
121
189
  'POST',
@@ -131,12 +199,31 @@ export async function mobilePinchCloseGesture(opts) {
131
199
  /**
132
200
  * Performs a pinch open gesture.
133
201
  * @this {AndroidUiautomator2Driver}
134
- * @param {import('./types').PinchOptions} opts
202
+ * @param {number} percent The size of the pinch as a percentage of the pinch area size.
203
+ * Valid values must be float numbers in range 0..1, where 1.0 is 100%
204
+ * @param {string} [elementId] The id of the element to be pinched.
205
+ * If the element id is missing then pinch bounding area must be provided.
206
+ * If both the element id and the pinch bounding area are provided then the
207
+ * area is effectively ignored.
208
+ * @param {number} [left] The left coordinate of the pinch bounding area.
209
+ * @param {number} [top] The top coordinate of the pinch bounding area.
210
+ * @param {number} [width] The width of the pinch bounding area.
211
+ * @param {number} [height] The height of the pinch bounding area.
212
+ * @param {number} [speed] The speed at which to perform this gesture in pixels per second.
213
+ * The value must not be negative.
214
+ * Default is 2500 * displayDensity.
135
215
  * @returns {Promise<void>}
136
216
  * @throws {Error} if provided options are not valid
137
217
  */
138
- export async function mobilePinchOpenGesture(opts) {
139
- const {elementId, left, top, width, height, percent, speed} = opts;
218
+ export async function mobilePinchOpenGesture(
219
+ percent,
220
+ elementId,
221
+ left,
222
+ top,
223
+ width,
224
+ height,
225
+ speed,
226
+ ) {
140
227
  await this.uiautomator2.jwproxy.command(
141
228
  '/appium/gestures/pinch_open',
142
229
  'POST',
@@ -152,12 +239,34 @@ export async function mobilePinchOpenGesture(opts) {
152
239
  /**
153
240
  * Performs a swipe gesture.
154
241
  * @this {AndroidUiautomator2Driver}
155
- * @param {import('./types').SwipeOptions} opts
242
+ * @param {string} direction Direction of the swipe.
243
+ * Acceptable values are: `up`, `down`, `left` and `right` (case insensitive).
244
+ * @param {number} percent The size of the swipe as a percentage of the swipe area size.
245
+ * Valid values must be float numbers in range 0..1, where 1.0 is 100%.
246
+ * @param {string} [elementId] The id of the element to be swiped.
247
+ * If the element id is missing then swipe bounding area must be provided.
248
+ * If both the element id and the swipe bounding area are provided then the
249
+ * area is effectively ignored.
250
+ * @param {number} [left] The left coordinate of the swipe bounding area.
251
+ * @param {number} [top] The top coordinate of the swipe bounding area.
252
+ * @param {number} [width] The width of the swipe bounding area.
253
+ * @param {number} [height] The height of the swipe bounding area.
254
+ * @param {number} [speed] The speed at which to perform this gesture in pixels per second.
255
+ * The value must not be negative.
256
+ * Default is 5000 * displayDensity.
156
257
  * @returns {Promise<void>}
157
258
  * @throws {Error} if provided options are not valid
158
259
  */
159
- export async function mobileSwipeGesture(opts) {
160
- const {elementId, left, top, width, height, direction, percent, speed} = opts;
260
+ export async function mobileSwipeGesture(
261
+ direction,
262
+ percent,
263
+ elementId,
264
+ left,
265
+ top,
266
+ width,
267
+ height,
268
+ speed,
269
+ ) {
161
270
  await this.uiautomator2.jwproxy.command(
162
271
  '/appium/gestures/swipe',
163
272
  'POST',
@@ -176,11 +285,33 @@ export async function mobileSwipeGesture(opts) {
176
285
  *
177
286
  * @throws {Error} if provided options are not valid
178
287
  * @this {AndroidUiautomator2Driver}
179
- * @param {import('./types').ScrollGestureOptions} opts
288
+ * @param {string} direction Direction of the scroll.
289
+ * Acceptable values are: `up`, `down`, `left` and `right` (case insensitive).
290
+ * @param {number} percent The size of the scroll as a percentage of the scrolling area size.
291
+ * Valid values must be float numbers greater than zero, where 1.0 is 100%.
292
+ * @param {string} [elementId] The id of the element to be scrolled.
293
+ * If the element id is missing then scroll bounding area must be provided.
294
+ * If both the element id and the scroll bounding area are provided then this
295
+ * area is effectively ignored.
296
+ * @param {number} [left] The left coordinate of the scroll bounding area.
297
+ * @param {number} [top] The top coordinate of the scroll bounding area.
298
+ * @param {number} [width] The width of the scroll bounding area.
299
+ * @param {number} [height] The height of the scroll bounding area.
300
+ * @param {number} [speed] The speed at which to perform this gesture in pixels per second.
301
+ * The value must not be negative.
302
+ * Default is 5000 * displayDensity.
180
303
  * @returns {Promise<boolean>} True if the object can still scroll in the given direction.
181
304
  */
182
- export async function mobileScrollGesture(opts) {
183
- const {elementId, left, top, width, height, direction, percent, speed} = opts;
305
+ export async function mobileScrollGesture(
306
+ direction,
307
+ percent,
308
+ elementId,
309
+ left,
310
+ top,
311
+ width,
312
+ height,
313
+ speed,
314
+ ) {
184
315
  return /** @type {boolean} */ (
185
316
  await this.uiautomator2.jwproxy.command(
186
317
  '/appium/gestures/scroll',
@@ -204,12 +335,16 @@ export async function mobileScrollGesture(opts) {
204
335
  * by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
205
336
  * is detected automatically.
206
337
  * @this {AndroidUiautomator2Driver}
207
- * @param {import('./types').ScrollElementToElementOpts} opts
338
+ * @param {string} elementId The identifier of the scrollable element, which is going to be scrolled.
339
+ * It is required this element is a valid scrollable container and it was located
340
+ * by `-android uiautomator` strategy.
341
+ * @param {string} elementToId The identifier of the item, which belongs to the scrollable element above,
342
+ * and which should become visible after the scrolling operation is finished.
343
+ * It is required this element was located by `-android uiautomator` strategy.
208
344
  * @returns {Promise<void>}
209
345
  * @throws {Error} if the scrolling operation cannot be performed
210
346
  */
211
- export async function mobileScrollBackTo(opts) {
212
- const {elementId, elementToId} = opts;
347
+ export async function mobileScrollBackTo(elementId, elementToId) {
213
348
  if (!elementId || !elementToId) {
214
349
  throw new errors.InvalidArgumentError(
215
350
  `Both elementId and elementToId arguments must be provided`
@@ -231,18 +366,29 @@ export async function mobileScrollBackTo(opts) {
231
366
  * to the very beginning of the scrollable control and tries to reach the destination element
232
367
  * by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
233
368
  * is detected automatically.
369
+ *
234
370
  * @this {AndroidUiautomator2Driver}
235
- * @param {import('./types').ScrollOptions} opts
371
+ * @param {string} strategy The following strategies are supported:
372
+ * - `accessibility id` (UiSelector().description)
373
+ * - `class name` (UiSelector().className)
374
+ * - `-android uiautomator` (UiSelector)
375
+ * @param {string} selector The corresponding lookup value for the given strategy.
376
+ * @param {string} [elementId] The identifier of an element. It is required this element is a valid scrollable container
377
+ * and it was located by `-android uiautomator` strategy.
378
+ * If this property is not provided then the first currently available scrollable view
379
+ * is selected for the interaction.
380
+ * @param {number} [maxSwipes] The maximum number of swipes to perform on the target scrollable view in order to reach
381
+ * the destination element. In case this value is unset then it would be retrieved from the
382
+ * scrollable element itself (via `getMaxSearchSwipes()` property).
236
383
  * @returns {Promise<void>}
237
384
  * @throws {Error} if the scrolling operation cannot be performed
238
385
  */
239
- export async function mobileScroll(opts) {
240
- const {
241
- elementId,
242
- strategy,
243
- selector,
244
- maxSwipes,
245
- } = opts;
386
+ export async function mobileScroll(
387
+ strategy,
388
+ selector,
389
+ elementId,
390
+ maxSwipes,
391
+ ) {
246
392
  if (!strategy || !selector) {
247
393
  throw new errors.InvalidArgumentError(
248
394
  `Both strategy and selector arguments must be provided`
@@ -1,3 +1,4 @@
1
+ import { errors } from 'appium/driver';
1
2
  import _ from 'lodash';
2
3
 
3
4
  /**
@@ -40,12 +41,16 @@ export async function longPressKeyCode(keycode, metastate, flags) {
40
41
 
41
42
  /**
42
43
  * @this {AndroidUiautomator2Driver}
43
- * @param {import('./types').PressKeyOptions} opts
44
+ * @param {number} keycode A valid Android key code. See https://developer.android.com/reference/android/view/KeyEvent
45
+ * for the list of available key codes.
46
+ * @param {number} [metastate] An integer in which each bit set to 1 represents a pressed meta key. See
47
+ * https://developer.android.com/reference/android/view/KeyEvent for more details.
48
+ * @param {string} [flags] Flags for the particular key event. See
49
+ * https://developer.android.com/reference/android/view/KeyEvent for more details.
50
+ * @param {boolean} [isLongPress=false] Whether to emulate long key press
44
51
  * @returns {Promise<void>}
45
52
  */
46
- export async function mobilePressKey(opts) {
47
- const {keycode, metastate, flags, isLongPress = false} = opts;
48
-
53
+ export async function mobilePressKey(keycode, metastate, flags, isLongPress = false) {
49
54
  await this.uiautomator2.jwproxy.command(
50
55
  `/appium/device/${isLongPress ? 'long_' : ''}press_keycode`,
51
56
  'POST',
@@ -61,15 +66,15 @@ export async function mobilePressKey(opts) {
61
66
  * Types the given Unicode string.
62
67
  * It is expected that the focus is already put
63
68
  * to the destination input field before this method is called.
69
+ *
64
70
  * @this {AndroidUiautomator2Driver}
65
- * @param {import('./types').TypingOptions} opts
71
+ * @param {string | number | boolean} text The text to type. Can be a string, number or boolean.
66
72
  * @returns {Promise<boolean>} `true` if the input text has been successfully sent to adb
67
73
  * @throws {Error} if `text` property has not been provided
68
74
  */
69
- export async function mobileType(opts) {
70
- const {text} = opts;
75
+ export async function mobileType(text) {
71
76
  if (_.isUndefined(text)) {
72
- throw this.log.errorWithException(`The 'text' argument is mandatory`);
77
+ throw new errors.InvalidArgumentError(`The 'text' argument is mandatory`);
73
78
  }
74
79
  return await this.settingsApp.typeUnicode(String(text));
75
80
  }
@@ -10,11 +10,13 @@ export async function setUrl(url) {
10
10
  /**
11
11
  * Start URL that take users directly to specific content in the app
12
12
  * @this {AndroidUiautomator2Driver}
13
- * @param {import('./types').DeepLinkOpts} opts
13
+ * @param {string} url The name of URL to start.
14
+ * @param {string} [pkg] The name of the package to start the URI with.
15
+ * @param {boolean} [waitForLaunch=true] If `false` then adb won't wait for
16
+ * the started activity to return the control.
14
17
  * @returns {Promise<void>}
15
18
  */
16
- export async function mobileDeepLink(opts) {
17
- const {url, package: pkg, waitForLaunch} = opts;
19
+ export async function mobileDeepLink(url, pkg, waitForLaunch) {
18
20
  return await this.adb.startUri(url, pkg, {waitForLaunch});
19
21
  }
20
22
 
@@ -49,10 +49,12 @@ export async function getScreenshot() {
49
49
  * Retrieves screenshots of each display available to Android.
50
50
  * This functionality is only supported since Android 10.
51
51
  * @this {AndroidUiautomator2Driver}
52
- * @param {import('./types').ScreenshotsOpts} [opts={}]
52
+ * @param {number | string} [displayId] Android display identifier to take a screenshot for.
53
+ * If not provided then screenshots of all displays are going to be returned.
54
+ * If no matches were found then an error is thrown.
53
55
  * @returns {Promise<import('@appium/types').StringRecord<import('./types').Screenshot>>}
54
56
  */
55
- export async function mobileScreenshots(opts = {}) {
57
+ export async function mobileScreenshots(displayId) {
56
58
  const displaysInfo = await /** @type {import('appium-adb').ADB} */ (this.adb).shell([
57
59
  'dumpsys',
58
60
  'SurfaceFlinger',
@@ -82,7 +84,6 @@ export async function mobileScreenshots(opts = {}) {
82
84
  'base64'
83
85
  );
84
86
 
85
- const {displayId} = opts;
86
87
  // @ts-ignore isNaN works properly here
87
88
  const displayIdStr = isNaN(displayId) ? null : `${displayId}`;
88
89
  if (displayIdStr) {