appium-uiautomator2-driver 6.7.5 → 6.7.7

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 (76) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/lib/commands/actions.d.ts +26 -29
  3. package/build/lib/commands/actions.d.ts.map +1 -1
  4. package/build/lib/commands/actions.js +19 -27
  5. package/build/lib/commands/actions.js.map +1 -1
  6. package/build/lib/commands/alert.d.ts +14 -22
  7. package/build/lib/commands/alert.d.ts.map +1 -1
  8. package/build/lib/commands/alert.js +8 -19
  9. package/build/lib/commands/alert.js.map +1 -1
  10. package/build/lib/commands/app-management.d.ts +7 -10
  11. package/build/lib/commands/app-management.d.ts.map +1 -1
  12. package/build/lib/commands/app-management.js +4 -14
  13. package/build/lib/commands/app-management.js.map +1 -1
  14. package/build/lib/commands/battery.d.ts +4 -5
  15. package/build/lib/commands/battery.d.ts.map +1 -1
  16. package/build/lib/commands/battery.js +4 -9
  17. package/build/lib/commands/battery.js.map +1 -1
  18. package/build/lib/commands/clipboard.d.ts +9 -13
  19. package/build/lib/commands/clipboard.d.ts.map +1 -1
  20. package/build/lib/commands/clipboard.js +7 -14
  21. package/build/lib/commands/clipboard.js.map +1 -1
  22. package/build/lib/commands/element.d.ts +64 -69
  23. package/build/lib/commands/element.d.ts.map +1 -1
  24. package/build/lib/commands/element.js +64 -84
  25. package/build/lib/commands/element.js.map +1 -1
  26. package/build/lib/commands/find.d.ts +13 -9
  27. package/build/lib/commands/find.d.ts.map +1 -1
  28. package/build/lib/commands/find.js +4 -16
  29. package/build/lib/commands/find.js.map +1 -1
  30. package/build/lib/commands/gestures.d.ts +87 -189
  31. package/build/lib/commands/gestures.d.ts.map +1 -1
  32. package/build/lib/commands/gestures.js +77 -204
  33. package/build/lib/commands/gestures.js.map +1 -1
  34. package/build/lib/commands/keyboard.d.ts +30 -41
  35. package/build/lib/commands/keyboard.d.ts.map +1 -1
  36. package/build/lib/commands/keyboard.js +22 -37
  37. package/build/lib/commands/keyboard.js.map +1 -1
  38. package/build/lib/commands/misc.d.ts +19 -35
  39. package/build/lib/commands/misc.d.ts.map +1 -1
  40. package/build/lib/commands/misc.js +15 -30
  41. package/build/lib/commands/misc.js.map +1 -1
  42. package/build/lib/commands/navigation.d.ts +11 -16
  43. package/build/lib/commands/navigation.d.ts.map +1 -1
  44. package/build/lib/commands/navigation.js +9 -17
  45. package/build/lib/commands/navigation.js.map +1 -1
  46. package/build/lib/commands/viewport.d.ts +23 -22
  47. package/build/lib/commands/viewport.d.ts.map +1 -1
  48. package/build/lib/commands/viewport.js +17 -24
  49. package/build/lib/commands/viewport.js.map +1 -1
  50. package/build/tsconfig.tsbuildinfo +1 -1
  51. package/lib/commands/actions.ts +95 -0
  52. package/lib/commands/alert.ts +46 -0
  53. package/lib/commands/app-management.ts +25 -0
  54. package/lib/commands/battery.ts +19 -0
  55. package/lib/commands/clipboard.ts +29 -0
  56. package/lib/commands/element.ts +180 -0
  57. package/lib/commands/find.ts +48 -0
  58. package/lib/commands/gestures.ts +297 -0
  59. package/lib/commands/keyboard.ts +102 -0
  60. package/lib/commands/misc.ts +67 -0
  61. package/lib/commands/navigation.ts +32 -0
  62. package/lib/commands/viewport.ts +78 -0
  63. package/npm-shrinkwrap.json +16 -46
  64. package/package.json +1 -1
  65. package/lib/commands/actions.js +0 -107
  66. package/lib/commands/alert.js +0 -63
  67. package/lib/commands/app-management.js +0 -32
  68. package/lib/commands/battery.js +0 -23
  69. package/lib/commands/clipboard.js +0 -37
  70. package/lib/commands/element.js +0 -261
  71. package/lib/commands/find.js +0 -47
  72. package/lib/commands/gestures.js +0 -446
  73. package/lib/commands/keyboard.js +0 -108
  74. package/lib/commands/misc.js +0 -109
  75. package/lib/commands/navigation.js +0 -33
  76. package/lib/commands/viewport.js +0 -100
@@ -0,0 +1,297 @@
1
+ import {errors} from 'appium/driver';
2
+ import {util} from 'appium/support';
3
+ import _ from 'lodash';
4
+ import type {Element as AppiumElement, Position} from '@appium/types';
5
+ import type {RelativeRect} from './types';
6
+ import type {AndroidUiautomator2Driver} from '../driver';
7
+
8
+ /**
9
+ * Performs a simple click/tap gesture.
10
+ * @param elementId - Optional element to use as the origin for the click. If not provided, uses screen coordinates.
11
+ * @param x - Optional X offset from the element origin or screen.
12
+ * @param y - Optional Y offset from the element origin or screen.
13
+ */
14
+ export async function mobileClickGesture(
15
+ this: AndroidUiautomator2Driver,
16
+ elementId?: AppiumElement | string,
17
+ x?: number,
18
+ y?: number,
19
+ ): Promise<void> {
20
+ await this.uiautomator2.jwproxy.command('/appium/gestures/click', 'POST', {
21
+ origin: toOrigin(elementId),
22
+ offset: toPoint(x, y),
23
+ });
24
+ }
25
+
26
+ /**
27
+ * Performs a long click with an optional duration.
28
+ * @param elementId - Optional element to use as the origin for the long click.
29
+ * @param x - Optional X offset from the element origin or screen.
30
+ * @param y - Optional Y offset from the element origin or screen.
31
+ * @param duration - Optional duration of the long press in milliseconds.
32
+ */
33
+ export async function mobileLongClickGesture(
34
+ this: AndroidUiautomator2Driver,
35
+ elementId?: AppiumElement | string,
36
+ x?: number,
37
+ y?: number,
38
+ duration?: number,
39
+ ): Promise<void> {
40
+ await this.uiautomator2.jwproxy.command('/appium/gestures/long_click', 'POST', {
41
+ origin: toOrigin(elementId),
42
+ offset: toPoint(x, y),
43
+ duration,
44
+ });
45
+ }
46
+
47
+ /**
48
+ * Performs a double-click gesture.
49
+ * @param elementId - Optional element to use as the origin for the double click.
50
+ * @param x - Optional X offset from the element origin or screen.
51
+ * @param y - Optional Y offset from the element origin or screen.
52
+ */
53
+ export async function mobileDoubleClickGesture(
54
+ this: AndroidUiautomator2Driver,
55
+ elementId?: AppiumElement | string,
56
+ x?: number,
57
+ y?: number,
58
+ ): Promise<void> {
59
+ await this.uiautomator2.jwproxy.command('/appium/gestures/double_click', 'POST', {
60
+ origin: toOrigin(elementId),
61
+ offset: toPoint(x, y),
62
+ });
63
+ }
64
+
65
+ /**
66
+ * Drags from a start point to an end point.
67
+ * @param elementId - Optional element to use as the origin for the drag.
68
+ * @param startX - X coordinate of the drag start point.
69
+ * @param startY - Y coordinate of the drag start point.
70
+ * @param endX - X coordinate of the drag end point.
71
+ * @param endY - Y coordinate of the drag end point.
72
+ * @param speed - Optional speed of the drag gesture.
73
+ */
74
+ export async function mobileDragGesture(
75
+ this: AndroidUiautomator2Driver,
76
+ elementId?: AppiumElement | string,
77
+ startX?: number,
78
+ startY?: number,
79
+ endX?: number,
80
+ endY?: number,
81
+ speed?: number,
82
+ ): Promise<void> {
83
+ await this.uiautomator2.jwproxy.command('/appium/gestures/drag', 'POST', {
84
+ origin: toOrigin(elementId),
85
+ start: toPoint(startX, startY),
86
+ end: toPoint(endX, endY),
87
+ speed,
88
+ });
89
+ }
90
+
91
+ /**
92
+ * Performs a fling gesture and reports if further scrolling is possible.
93
+ * @param direction - Direction of the fling ('up', 'down', 'left', 'right').
94
+ * @param elementId - Optional element to use as the origin for the fling.
95
+ * @param left - Optional left coordinate of the fling area.
96
+ * @param top - Optional top coordinate of the fling area.
97
+ * @param width - Optional width of the fling area.
98
+ * @param height - Optional height of the fling area.
99
+ * @param speed - Optional speed of the fling gesture.
100
+ * @returns True if further scrolling is possible, false otherwise.
101
+ */
102
+ export async function mobileFlingGesture(
103
+ this: AndroidUiautomator2Driver,
104
+ direction: string,
105
+ elementId?: AppiumElement | string,
106
+ left?: number,
107
+ top?: number,
108
+ width?: number,
109
+ height?: number,
110
+ speed?: number,
111
+ ): Promise<boolean> {
112
+ return (await this.uiautomator2.jwproxy.command('/appium/gestures/fling', 'POST', {
113
+ origin: toOrigin(elementId),
114
+ area: toRect(left, top, width, height),
115
+ direction,
116
+ speed,
117
+ })) as boolean;
118
+ }
119
+
120
+ /**
121
+ * Performs a pinch-close gesture.
122
+ * @param percent - Percentage of the pinch (0-100).
123
+ * @param elementId - Optional element to use as the origin for the pinch.
124
+ * @param left - Optional left coordinate of the pinch area.
125
+ * @param top - Optional top coordinate of the pinch area.
126
+ * @param width - Optional width of the pinch area.
127
+ * @param height - Optional height of the pinch area.
128
+ * @param speed - Optional speed of the pinch gesture.
129
+ */
130
+ export async function mobilePinchCloseGesture(
131
+ this: AndroidUiautomator2Driver,
132
+ percent: number,
133
+ elementId?: AppiumElement | string,
134
+ left?: number,
135
+ top?: number,
136
+ width?: number,
137
+ height?: number,
138
+ speed?: number,
139
+ ): Promise<void> {
140
+ await this.uiautomator2.jwproxy.command('/appium/gestures/pinch_close', 'POST', {
141
+ origin: toOrigin(elementId),
142
+ area: toRect(left, top, width, height),
143
+ percent,
144
+ speed,
145
+ });
146
+ }
147
+
148
+ /**
149
+ * Performs a pinch-open gesture.
150
+ * @param percent - Percentage of the pinch (0-100).
151
+ * @param elementId - Optional element to use as the origin for the pinch.
152
+ * @param left - Optional left coordinate of the pinch area.
153
+ * @param top - Optional top coordinate of the pinch area.
154
+ * @param width - Optional width of the pinch area.
155
+ * @param height - Optional height of the pinch area.
156
+ * @param speed - Optional speed of the pinch gesture.
157
+ */
158
+ export async function mobilePinchOpenGesture(
159
+ this: AndroidUiautomator2Driver,
160
+ percent: number,
161
+ elementId?: AppiumElement | string,
162
+ left?: number,
163
+ top?: number,
164
+ width?: number,
165
+ height?: number,
166
+ speed?: number,
167
+ ): Promise<void> {
168
+ await this.uiautomator2.jwproxy.command('/appium/gestures/pinch_open', 'POST', {
169
+ origin: toOrigin(elementId),
170
+ area: toRect(left, top, width, height),
171
+ percent,
172
+ speed,
173
+ });
174
+ }
175
+
176
+ /**
177
+ * Performs a swipe gesture for the given direction and percent.
178
+ * @param direction - Direction of the swipe ('up', 'down', 'left', 'right').
179
+ * @param percent - Percentage of the swipe distance (0-100).
180
+ * @param elementId - Optional element to use as the origin for the swipe.
181
+ * @param left - Optional left coordinate of the swipe area.
182
+ * @param top - Optional top coordinate of the swipe area.
183
+ * @param width - Optional width of the swipe area.
184
+ * @param height - Optional height of the swipe area.
185
+ * @param speed - Optional speed of the swipe gesture.
186
+ */
187
+ export async function mobileSwipeGesture(
188
+ this: AndroidUiautomator2Driver,
189
+ direction: string,
190
+ percent: number,
191
+ elementId?: AppiumElement | string,
192
+ left?: number,
193
+ top?: number,
194
+ width?: number,
195
+ height?: number,
196
+ speed?: number,
197
+ ): Promise<void> {
198
+ await this.uiautomator2.jwproxy.command('/appium/gestures/swipe', 'POST', {
199
+ origin: toOrigin(elementId),
200
+ area: toRect(left, top, width, height),
201
+ direction,
202
+ percent,
203
+ speed,
204
+ });
205
+ }
206
+
207
+ /**
208
+ * Performs a scroll gesture and reports if further scrolling is possible.
209
+ * @param direction - Direction of the scroll ('up', 'down', 'left', 'right').
210
+ * @param percent - Percentage of the scroll distance (0-100).
211
+ * @param elementId - Optional element to use as the origin for the scroll.
212
+ * @param left - Optional left coordinate of the scroll area.
213
+ * @param top - Optional top coordinate of the scroll area.
214
+ * @param width - Optional width of the scroll area.
215
+ * @param height - Optional height of the scroll area.
216
+ * @param speed - Optional speed of the scroll gesture.
217
+ * @returns True if further scrolling is possible, false otherwise.
218
+ */
219
+ export async function mobileScrollGesture(
220
+ this: AndroidUiautomator2Driver,
221
+ direction: string,
222
+ percent: number,
223
+ elementId?: AppiumElement | string,
224
+ left?: number,
225
+ top?: number,
226
+ width?: number,
227
+ height?: number,
228
+ speed?: number,
229
+ ): Promise<boolean> {
230
+ return (await this.uiautomator2.jwproxy.command('/appium/gestures/scroll', 'POST', {
231
+ origin: toOrigin(elementId),
232
+ area: toRect(left, top, width, height),
233
+ direction,
234
+ percent,
235
+ speed,
236
+ })) as boolean;
237
+ }
238
+
239
+ /**
240
+ * Scrolls a scrollable element until a target element becomes visible.
241
+ * @param elementId - ID of the scrollable element.
242
+ * @param elementToId - ID of the target element to scroll to.
243
+ * @throws {errors.InvalidArgumentError} If either elementId or elementToId is not provided.
244
+ */
245
+ export async function mobileScrollBackTo(
246
+ this: AndroidUiautomator2Driver,
247
+ elementId?: string,
248
+ elementToId?: string,
249
+ ): Promise<void> {
250
+ if (!elementId || !elementToId) {
251
+ throw new errors.InvalidArgumentError(`Both elementId and elementToId arguments must be provided`);
252
+ }
253
+ await this.uiautomator2.jwproxy.command(
254
+ `/appium/element/${util.unwrapElement(elementId)}/scroll_to/${util.unwrapElement(elementToId)}`,
255
+ 'POST',
256
+ {},
257
+ );
258
+ }
259
+
260
+ /**
261
+ * Scrolls until an element located by the given strategy is visible.
262
+ * @param strategy - Locator strategy to use (e.g., 'id', 'xpath', 'class name').
263
+ * @param selector - Selector string for the element to find.
264
+ * @param elementId - Optional element to use as the origin for scrolling.
265
+ * @param maxSwipes - Optional maximum number of swipes to perform.
266
+ * @throws {errors.InvalidArgumentError} If either strategy or selector is not provided.
267
+ */
268
+ export async function mobileScroll(
269
+ this: AndroidUiautomator2Driver,
270
+ strategy: string,
271
+ selector: string,
272
+ elementId?: AppiumElement | string,
273
+ maxSwipes?: number,
274
+ ): Promise<void> {
275
+ if (!strategy || !selector) {
276
+ throw new errors.InvalidArgumentError(`Both strategy and selector arguments must be provided`);
277
+ }
278
+ await this.uiautomator2.jwproxy.command('/gestures/scroll_to', 'POST', {
279
+ origin: toOrigin(elementId),
280
+ params: {strategy, selector, maxSwipes},
281
+ });
282
+ }
283
+
284
+ function toOrigin(element?: AppiumElement | string): AppiumElement | undefined {
285
+ return element ? (util.wrapElement(util.unwrapElement(element)) as AppiumElement) : undefined;
286
+ }
287
+
288
+ function toPoint(x?: number, y?: number): Partial<Position> | undefined {
289
+ return _.isFinite(x) && _.isFinite(y) ? {x, y} : undefined;
290
+ }
291
+
292
+ function toRect(left?: number, top?: number, width?: number, height?: number): RelativeRect | undefined {
293
+ return [left, top, width, height].some((v) => !_.isFinite(v))
294
+ ? undefined
295
+ : ({left, top, width, height} as RelativeRect);
296
+ }
297
+
@@ -0,0 +1,102 @@
1
+ import {errors} from 'appium/driver';
2
+ import _ from 'lodash';
3
+ import type {AndroidUiautomator2Driver} from '../driver';
4
+ import type {SendKeysOpts} from 'appium-android-driver';
5
+
6
+ /**
7
+ * Presses a key code with optional metastate and flags.
8
+ * @param keycode - Android key code to press.
9
+ * @param metastate - Optional meta state modifier keys.
10
+ * @param flags - Optional flags for the key event.
11
+ */
12
+ export async function pressKeyCode(
13
+ this: AndroidUiautomator2Driver,
14
+ keycode: string | number,
15
+ metastate?: number,
16
+ flags?: number,
17
+ ): Promise<void> {
18
+ await this.uiautomator2.jwproxy.command('/appium/device/press_keycode', 'POST', {
19
+ keycode,
20
+ metastate,
21
+ flags,
22
+ });
23
+ }
24
+
25
+ /**
26
+ * Long presses a key code with optional metastate and flags.
27
+ * @param keycode - Android key code to long press.
28
+ * @param metastate - Meta state modifier keys.
29
+ * @param flags - Optional flags for the key event.
30
+ */
31
+ export async function longPressKeyCode(
32
+ this: AndroidUiautomator2Driver,
33
+ keycode: string | number,
34
+ metastate: number,
35
+ flags?: number,
36
+ ): Promise<void> {
37
+ await this.uiautomator2.jwproxy.command('/appium/device/long_press_keycode', 'POST', {
38
+ keycode,
39
+ metastate,
40
+ flags,
41
+ });
42
+ }
43
+
44
+ /**
45
+ * Presses a key code with optional metastate, flags, and long press support.
46
+ * @param keycode - Android key code to press.
47
+ * @param metastate - Optional meta state modifier keys.
48
+ * @param flags - Optional flags for the key event.
49
+ * @param isLongPress - Whether to perform a long press. Defaults to false.
50
+ */
51
+ export async function mobilePressKey(
52
+ this: AndroidUiautomator2Driver,
53
+ keycode: number,
54
+ metastate?: number,
55
+ flags?: string,
56
+ isLongPress: boolean = false,
57
+ ): Promise<void> {
58
+ await this.uiautomator2.jwproxy.command(`/appium/device/${isLongPress ? 'long_' : ''}press_keycode`, 'POST', {
59
+ keycode,
60
+ metastate,
61
+ flags,
62
+ });
63
+ }
64
+
65
+ /**
66
+ * Types the given Unicode string. The focus should already be on the destination input field.
67
+ * @param text - Text to type. Can be a string, number, or boolean.
68
+ * @returns True if the input text has been successfully sent to adb.
69
+ * @throws {errors.InvalidArgumentError} If the text argument is not provided.
70
+ */
71
+ export async function mobileType(
72
+ this: AndroidUiautomator2Driver,
73
+ text: string | number | boolean,
74
+ ): Promise<boolean> {
75
+ if (_.isUndefined(text)) {
76
+ throw new errors.InvalidArgumentError(`The 'text' argument is mandatory`);
77
+ }
78
+ return await this.settingsApp.typeUnicode(String(text));
79
+ }
80
+
81
+ /**
82
+ * Sends keys to the current element.
83
+ * @param params - Options containing the text to send and optional replace flag.
84
+ */
85
+ export async function doSendKeys(this: AndroidUiautomator2Driver, params: SendKeysOpts): Promise<void> {
86
+ await this.uiautomator2.jwproxy.command('/keys', 'POST', params);
87
+ }
88
+
89
+ /**
90
+ * Sends a key event to the device.
91
+ * @param keycode - Android key code to send.
92
+ * @param metastate - Optional meta state (ignored in this implementation).
93
+ */
94
+ export async function keyevent(
95
+ this: AndroidUiautomator2Driver,
96
+ keycode: string | number,
97
+ metastate?: number,
98
+ ): Promise<void> {
99
+ this.log.debug(`Ignoring metastate ${metastate}`);
100
+ await this.adb.keyevent(keycode);
101
+ }
102
+
@@ -0,0 +1,67 @@
1
+ import type {Orientation, StringRecord} from '@appium/types';
2
+ import type {AndroidUiautomator2Driver} from '../driver';
3
+
4
+ /**
5
+ * Retrieves the current page source.
6
+ * @returns The XML page source of the current screen.
7
+ */
8
+ export async function getPageSource(this: AndroidUiautomator2Driver): Promise<string> {
9
+ return String(await this.uiautomator2.jwproxy.command('/source', 'GET', {}));
10
+ }
11
+
12
+ /**
13
+ * Gets the current device orientation.
14
+ * @returns The current device orientation ('LANDSCAPE' or 'PORTRAIT').
15
+ */
16
+ export async function getOrientation(this: AndroidUiautomator2Driver): Promise<Orientation> {
17
+ return (await this.uiautomator2.jwproxy.command(`/orientation`, 'GET', {})) as Orientation;
18
+ }
19
+
20
+ /**
21
+ * Sets the device orientation.
22
+ * @param orientation - The desired orientation ('LANDSCAPE' or 'PORTRAIT').
23
+ */
24
+ export async function setOrientation(
25
+ this: AndroidUiautomator2Driver,
26
+ orientation: Orientation,
27
+ ): Promise<void> {
28
+ const normalizedOrientation = orientation.toUpperCase() as Orientation;
29
+ await this.uiautomator2.jwproxy.command(`/orientation`, 'POST', {orientation: normalizedOrientation});
30
+ }
31
+
32
+ /**
33
+ * Opens the device notification shade.
34
+ */
35
+ export async function openNotifications(this: AndroidUiautomator2Driver): Promise<void> {
36
+ await this.uiautomator2.jwproxy.command('/appium/device/open_notifications', 'POST', {});
37
+ }
38
+
39
+ /**
40
+ * Stops proxying to Chromedriver and restores UIA2 proxy.
41
+ */
42
+ export function suspendChromedriverProxy(this: AndroidUiautomator2Driver): void {
43
+ if (!this.uiautomator2?.proxyReqRes || !this.uiautomator2?.proxyCommand) {
44
+ return;
45
+ }
46
+
47
+ this.chromedriver = undefined;
48
+ this.proxyReqRes = this.uiautomator2.proxyReqRes.bind(this.uiautomator2);
49
+ this.proxyCommand = this.uiautomator2.proxyCommand.bind(this.uiautomator2);
50
+ this.jwpProxyActive = true;
51
+ }
52
+
53
+ /**
54
+ * Retrieves device info via the UIA2 server.
55
+ * @returns Device information as a string record.
56
+ */
57
+ export async function mobileGetDeviceInfo(this: AndroidUiautomator2Driver): Promise<StringRecord> {
58
+ return (await this.uiautomator2.jwproxy.command('/appium/device/info', 'GET')) as StringRecord;
59
+ }
60
+
61
+ /**
62
+ * Resets the accessibility cache on the device.
63
+ */
64
+ export async function mobileResetAccessibilityCache(this: AndroidUiautomator2Driver): Promise<void> {
65
+ await this.uiautomator2.jwproxy.command('/appium/reset_ax_cache', 'POST', {});
66
+ }
67
+
@@ -0,0 +1,32 @@
1
+ import type {AndroidUiautomator2Driver} from '../driver';
2
+
3
+ /**
4
+ * Sets the URL for the current app.
5
+ * @param url - The URL to navigate to.
6
+ */
7
+ export async function setUrl(this: AndroidUiautomator2Driver, url: string): Promise<void> {
8
+ await this.adb.startUri(url, this.opts.appPackage as string);
9
+ }
10
+
11
+ /**
12
+ * Starts a URL that takes users directly to specific content in the app.
13
+ * @param url - The deep link URL to start.
14
+ * @param pkg - Optional package name to start the URI with. If not provided, uses the current app package.
15
+ * @param waitForLaunch - If false, adb won't wait for the started activity to return control. Defaults to true.
16
+ */
17
+ export async function mobileDeepLink(
18
+ this: AndroidUiautomator2Driver,
19
+ url: string,
20
+ pkg?: string,
21
+ waitForLaunch: boolean = true,
22
+ ): Promise<void> {
23
+ return await this.adb.startUri(url, pkg, {waitForLaunch});
24
+ }
25
+
26
+ /**
27
+ * Navigates back in the app.
28
+ */
29
+ export async function back(this: AndroidUiautomator2Driver): Promise<void> {
30
+ await this.adb.keyevent(4);
31
+ }
32
+
@@ -0,0 +1,78 @@
1
+ import type {Rect, Size} from '@appium/types';
2
+ import type {AndroidUiautomator2Driver} from '../driver';
3
+ import type {RelativeRect} from './types';
4
+
5
+ /**
6
+ * Gets the status bar height in pixels.
7
+ * @returns The status bar height in pixels.
8
+ */
9
+ export async function getStatusBarHeight(this: AndroidUiautomator2Driver): Promise<number> {
10
+ const {statusBar} = (await this.uiautomator2.jwproxy.command(`/appium/device/system_bars`, 'GET', {})) as {
11
+ statusBar: number;
12
+ };
13
+ return statusBar;
14
+ }
15
+
16
+ /**
17
+ * Gets the device pixel ratio.
18
+ * @returns The device pixel ratio as a string.
19
+ */
20
+ export async function getDevicePixelRatio(this: AndroidUiautomator2Driver): Promise<string> {
21
+ return String(await this.uiautomator2.jwproxy.command('/appium/device/pixel_ratio', 'GET', {}));
22
+ }
23
+
24
+ /**
25
+ * Gets the viewport rectangle coordinates.
26
+ * @returns The viewport rectangle (left, top, width, height), accounting for status bar height.
27
+ */
28
+ export async function getViewPortRect(this: AndroidUiautomator2Driver): Promise<RelativeRect> {
29
+ const windowSize = await this.getWindowSize();
30
+ const statusBarHeight = await this.getStatusBarHeight();
31
+ // android returns the upscaled window size, so to get the true size of the
32
+ // rect we have to downscale
33
+ return {
34
+ left: 0,
35
+ top: statusBarHeight,
36
+ width: windowSize.width,
37
+ height: windowSize.height - statusBarHeight,
38
+ };
39
+ }
40
+
41
+ /**
42
+ * Returns the viewport coordinates.
43
+ * @returns The viewport rectangle (left, top, width, height).
44
+ */
45
+ export async function mobileViewPortRect(this: AndroidUiautomator2Driver): Promise<RelativeRect> {
46
+ return await this.getViewPortRect();
47
+ }
48
+
49
+ /**
50
+ * Gets the window rectangle (W3C endpoint).
51
+ * @returns The window rectangle (x, y, width, height).
52
+ */
53
+ export async function getWindowRect(this: AndroidUiautomator2Driver): Promise<Rect> {
54
+ const {width, height} = await this.getWindowSize();
55
+ return {
56
+ width,
57
+ height,
58
+ x: 0,
59
+ y: 0,
60
+ };
61
+ }
62
+
63
+ /**
64
+ * Gets the display density.
65
+ * @returns The display density value.
66
+ */
67
+ export async function getDisplayDensity(this: AndroidUiautomator2Driver): Promise<number> {
68
+ return (await this.uiautomator2.jwproxy.command('/appium/device/display_density', 'GET', {})) as number;
69
+ }
70
+
71
+ /**
72
+ * Gets the window size.
73
+ * @returns The window size (width, height).
74
+ */
75
+ export async function getWindowSize(this: AndroidUiautomator2Driver): Promise<Size> {
76
+ return (await this.uiautomator2.jwproxy.command('/window/current/size', 'GET', {})) as Size;
77
+ }
78
+
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "appium-uiautomator2-driver",
3
- "version": "6.7.5",
3
+ "version": "6.7.7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "appium-uiautomator2-driver",
9
- "version": "6.7.5",
9
+ "version": "6.7.7",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "appium-adb": "^14.0.0",
@@ -626,9 +626,9 @@
626
626
  }
627
627
  },
628
628
  "node_modules/appium-adb": {
629
- "version": "14.1.7",
630
- "resolved": "https://registry.npmjs.org/appium-adb/-/appium-adb-14.1.7.tgz",
631
- "integrity": "sha512-/06TJ7maIJ4RzKmXdnqVNBhBZqoxAwoDeYBEaRm8Dbsa803Io16CJ94R3ncpQwlD5r5bsj4YMmwdZtVZKMjsLw==",
629
+ "version": "14.1.8",
630
+ "resolved": "https://registry.npmjs.org/appium-adb/-/appium-adb-14.1.8.tgz",
631
+ "integrity": "sha512-GjJg3/1ZmwFk2YEWsPc/4CuejnpC4G3UN7ZP0dlBpYNHmbaLuUswnZnAhGpp/7yU2cAZXWZf43/5aJdFeoRxJg==",
632
632
  "license": "Apache-2.0",
633
633
  "dependencies": {
634
634
  "@appium/support": "^7.0.0-rc.1",
@@ -639,22 +639,7 @@
639
639
  "lodash": "^4.0.0",
640
640
  "lru-cache": "^11.1.0",
641
641
  "semver": "^7.0.0",
642
- "teen_process": "^3.0.0"
643
- },
644
- "engines": {
645
- "node": "^20.19.0 || ^22.12.0 || >=24.0.0",
646
- "npm": ">=10"
647
- }
648
- },
649
- "node_modules/appium-adb/node_modules/teen_process": {
650
- "version": "3.0.6",
651
- "resolved": "https://registry.npmjs.org/teen_process/-/teen_process-3.0.6.tgz",
652
- "integrity": "sha512-nUw1B4MogSZzzy67n37IM1vg4doj+bWOZ7VwIFZGfD7MDmO+FRlhQlA2+22xJnTELVDDlOaTAMpKuuMI2vkDtg==",
653
- "license": "Apache-2.0",
654
- "dependencies": {
655
- "bluebird": "^3.7.2",
656
- "lodash": "^4.17.21",
657
- "shell-quote": "^1.8.1"
642
+ "teen_process": "^4.0.4"
658
643
  },
659
644
  "engines": {
660
645
  "node": "^20.19.0 || ^22.12.0 || >=24.0.0",
@@ -662,9 +647,9 @@
662
647
  }
663
648
  },
664
649
  "node_modules/appium-android-driver": {
665
- "version": "12.6.1",
666
- "resolved": "https://registry.npmjs.org/appium-android-driver/-/appium-android-driver-12.6.1.tgz",
667
- "integrity": "sha512-JFO6ouwGHYgC/knkPBVvKwtAqtaiCIPgUlVGmCngCtnLt2Zk4B0Sv+M1J8Elm1olFpCv/Jmb6kRxcEqHh1yRjg==",
650
+ "version": "12.6.2",
651
+ "resolved": "https://registry.npmjs.org/appium-android-driver/-/appium-android-driver-12.6.2.tgz",
652
+ "integrity": "sha512-jQbYHQXtBGgcpXskEvv2s+xtvC1MvcSOU5HD8eKdHpVZvQEnTdcOx3mZyG31UgxryVwj/rboIKRseDy4fTaXew==",
668
653
  "license": "Apache-2.0",
669
654
  "dependencies": {
670
655
  "@appium/support": "^7.0.0-rc.1",
@@ -681,7 +666,7 @@
681
666
  "moment-timezone": "^0.x",
682
667
  "portscanner": "^2.2.0",
683
668
  "semver": "^7.0.0",
684
- "teen_process": "^3.0.0",
669
+ "teen_process": "^4.0.7",
685
670
  "ws": "^8.0.0"
686
671
  },
687
672
  "engines": {
@@ -692,25 +677,10 @@
692
677
  "appium": "^3.0.0-rc.2"
693
678
  }
694
679
  },
695
- "node_modules/appium-android-driver/node_modules/teen_process": {
696
- "version": "3.0.6",
697
- "resolved": "https://registry.npmjs.org/teen_process/-/teen_process-3.0.6.tgz",
698
- "integrity": "sha512-nUw1B4MogSZzzy67n37IM1vg4doj+bWOZ7VwIFZGfD7MDmO+FRlhQlA2+22xJnTELVDDlOaTAMpKuuMI2vkDtg==",
699
- "license": "Apache-2.0",
700
- "dependencies": {
701
- "bluebird": "^3.7.2",
702
- "lodash": "^4.17.21",
703
- "shell-quote": "^1.8.1"
704
- },
705
- "engines": {
706
- "node": "^20.19.0 || ^22.12.0 || >=24.0.0",
707
- "npm": ">=10"
708
- }
709
- },
710
680
  "node_modules/appium-chromedriver": {
711
- "version": "8.0.31",
712
- "resolved": "https://registry.npmjs.org/appium-chromedriver/-/appium-chromedriver-8.0.31.tgz",
713
- "integrity": "sha512-hmamyXXsRwzhYoMbNzfdL1t/lCb0o0vLf63WpK/SgLwlcO2ut6MunT729KQSlFzOlLpndtE1H+LCX5KFyPDuMw==",
681
+ "version": "8.1.0",
682
+ "resolved": "https://registry.npmjs.org/appium-chromedriver/-/appium-chromedriver-8.1.0.tgz",
683
+ "integrity": "sha512-zrruUWsDYSk5fdApN7yv9CY35VUp45oTOct+Hc+IidPXPQDyuHcgyeMgpTY8y4FhiiQ89fD4NZNsjwAcqbIxuA==",
714
684
  "license": "Apache-2.0",
715
685
  "dependencies": {
716
686
  "@appium/base-driver": "^10.0.0-rc.2",
@@ -4089,9 +4059,9 @@
4089
4059
  }
4090
4060
  },
4091
4061
  "node_modules/teen_process": {
4092
- "version": "4.0.5",
4093
- "resolved": "https://registry.npmjs.org/teen_process/-/teen_process-4.0.5.tgz",
4094
- "integrity": "sha512-ZQQ2Vjs1/maFzpzfsZRAlQVSZrUBsKzAItaxSLImsHRTdI8hVt9Jm0JHyWFbrvvAf78V55BM3ZgNeQpXcXsWpw==",
4062
+ "version": "4.0.7",
4063
+ "resolved": "https://registry.npmjs.org/teen_process/-/teen_process-4.0.7.tgz",
4064
+ "integrity": "sha512-t7+1xY+WfihWM8M2JxL9ueH/SfDE7bhMuuVMR8bqrttQ0nn95hvOpGqThtZ2S/4+RvrJx2+UWO9no7wDFrOdsw==",
4095
4065
  "license": "Apache-2.0",
4096
4066
  "dependencies": {
4097
4067
  "bluebird": "^3.7.2",