appium-uiautomator2-driver 2.29.11 → 2.31.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 +14 -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 +209 -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 +87 -0
  43. package/build/lib/commands/mixins.d.ts.map +1 -0
  44. package/build/lib/commands/mixins.js +26 -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 +325 -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 +904 -0
  71. package/build/lib/driver.d.ts.map +1 -0
  72. package/build/lib/driver.js +726 -485
  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 +44 -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 +262 -336
  115. package/lib/commands/gestures.js +252 -366
  116. package/lib/commands/index.js +11 -31
  117. package/lib/commands/mixins.ts +169 -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} +374 -239
  125. package/lib/execute-method-map.ts +573 -0
  126. package/lib/method-map.ts +11 -0
  127. package/lib/types.ts +57 -0
  128. package/lib/uiautomator2.js +21 -2
  129. package/lib/utils.js +2 -2
  130. package/npm-shrinkwrap.json +395 -528
  131. package/package.json +96 -70
  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
@@ -0,0 +1,473 @@
1
+ import {Rect, StringRecord} from '@appium/types';
2
+
3
+ /**
4
+ * Represents options for pressing a key on an Android device.
5
+ */
6
+ export interface PressKeyOptions {
7
+ /**
8
+ * A valid Android key code. See https://developer.android.com/reference/android/view/KeyEvent
9
+ * for the list of available key codes.
10
+ */
11
+ keycode: number;
12
+ /**
13
+ * An integer in which each bit set to 1 represents a pressed meta key. See
14
+ * https://developer.android.com/reference/android/view/KeyEvent for more details.
15
+ */
16
+ metastate?: number;
17
+ /**
18
+ * Flags for the particular key event. See
19
+ * https://developer.android.com/reference/android/view/KeyEvent for more details.
20
+ */
21
+ flags?: string;
22
+ /**
23
+ * Whether to emulate long key press. Defaults to `false`.
24
+ */
25
+ isLongPress: boolean;
26
+ }
27
+
28
+ export interface AcceptAlertOptions {
29
+ /**
30
+ * The name of the button to click in order to accept the alert. If the name is not provided
31
+ * then the script will try to detect the button automatically.
32
+ */
33
+ buttonLabel?: string;
34
+ }
35
+
36
+ export interface DismissAlertOptions {
37
+ /**
38
+ * The name of the button to click in order to dismiss the alert. If the name is not provided
39
+ * then the script will try to detect the button automatically.
40
+ */
41
+ buttonLabel?: string;
42
+ }
43
+
44
+ export interface GetAppStringsOptions {
45
+ /**
46
+ * The language abbreviation to fetch app strings mapping for. If no
47
+ * language is provided then strings for the default language on the device under test
48
+ * would be returned. Examples: en, fr
49
+ */
50
+ language?: string;
51
+ }
52
+
53
+ export type BatteryState = -1 | 1 | 2 | 3 | 4 | 5;
54
+
55
+ export interface BatteryInfo {
56
+ /**
57
+ * Battery level in range [0.0, 1.0], where 1.0 means 100% charge.
58
+ * -1 is returned if the actual value cannot be retrieved from the system.
59
+ */
60
+ level: number;
61
+ /**
62
+ * Battery state. The following values are possible:
63
+ * BATTERY_STATUS_UNKNOWN = 1
64
+ * BATTERY_STATUS_CHARGING = 2
65
+ * BATTERY_STATUS_DISCHARGING = 3
66
+ * BATTERY_STATUS_NOT_CHARGING = 4
67
+ * BATTERY_STATUS_FULL = 5
68
+ * -1 is returned if the actual value cannot be retrieved from the system.
69
+ */
70
+ state: BatteryState;
71
+ }
72
+
73
+ export interface ReplaceValueOptions {
74
+ /**
75
+ * The id of the element whose content will be replaced.
76
+ */
77
+ elementId: string;
78
+ /**
79
+ * The actual text to set.
80
+ */
81
+ text: string;
82
+ }
83
+
84
+ export type MapKey<T, K extends keyof T, N extends string> = Pick<T, Exclude<keyof T, K>> & {
85
+ [P in N]: T[K];
86
+ };
87
+
88
+ export interface DeepLinkOpts {
89
+ /**
90
+ * The name of URL to start.
91
+ */
92
+ url: string;
93
+ /**
94
+ * The name of the package to start the URI with.
95
+ */
96
+ package: string;
97
+ /**
98
+ * If `false` then adb won't wait for the started activity to return the control.
99
+ * @defaultValue true
100
+ */
101
+ waitForLaunch?: boolean;
102
+ }
103
+
104
+ export interface TypingOptions {
105
+ /**
106
+ * The text to type. Can be a string, number or boolean.
107
+ */
108
+ text: string | number | boolean;
109
+ }
110
+ export interface InstallOptions {
111
+ /**
112
+ * Set to true in order to allow test packages installation.
113
+ * @defaultValue false
114
+ */
115
+ allowTestPackages?: boolean;
116
+ /**
117
+ * Set to true to install the app on sdcard instead of the device memory.
118
+ * @defaultValue false
119
+ */
120
+ useSdcard?: boolean;
121
+ /**
122
+ * Set to true in order to grant all the permissions requested in the application's manifest
123
+ * automatically after the installation is completed under Android 6+.
124
+ * @defaultValue false
125
+ */
126
+ grantPermissions?: boolean;
127
+ /**
128
+ * Set it to false if you don't want the application to be upgraded/reinstalled
129
+ * if it is already present on the device.
130
+ * @defaultValue true
131
+ */
132
+ replace?: boolean;
133
+ /**
134
+ * Install apks partially. It is used for 'install-multiple'.
135
+ * https://android.stackexchange.com/questions/111064/what-is-a-partial-application-install-via-adb
136
+ * @defaultValue false
137
+ */
138
+ partialInstall?: boolean;
139
+ }
140
+
141
+ export interface InstallMultipleApksOptions {
142
+ /**
143
+ * The list of APKs to install. Each APK should be a path to a apk
144
+ * or downloadable URL as HTTP/HTTPS.
145
+ */
146
+ apks: string[];
147
+ /**
148
+ * The installation options.
149
+ */
150
+ options?: InstallOptions;
151
+ }
152
+ export interface BackgroundAppOptions {
153
+ /**
154
+ * The amount of seconds to wait between putting the app to background and restoring it.
155
+ * Any negative value means to not restore the app after putting it to background.
156
+ * @defaultValue -1
157
+ */
158
+ seconds?: number;
159
+ }
160
+
161
+ export interface ClickOptions {
162
+ /**
163
+ * The id of the element to be clicked. If the element is missing then both click offset coordinates must be provided. If both the element id and offset are provided then the coordinates are parsed as relative offsets from the top left corner of the element.
164
+ */
165
+ elementId?: string;
166
+ /**
167
+ * The x coordinate to click on.
168
+ */
169
+ x?: number;
170
+ /**
171
+ * The y coordinate to click on.
172
+ */
173
+ y?: number;
174
+ }
175
+
176
+ export interface LongClickOptions {
177
+ /**
178
+ * The id of the element to be clicked.
179
+ * If the element is missing then both click offset coordinates must be provided.
180
+ * If both the element id and offset are provided then the coordinates
181
+ * are parsed as relative offsets from the top left corner of the element.
182
+ */
183
+ elementId?: string;
184
+ /**
185
+ * The x coordinate to click on.
186
+ */
187
+ x?: number;
188
+ /**
189
+ * The y coordinate to click on.
190
+ */
191
+ y?: number;
192
+ /**
193
+ * Click duration in milliseconds. The value must not be negative.
194
+ * Default is 500.
195
+ */
196
+ duration?: number;
197
+ }
198
+
199
+ export type DoubleClickOptions = ClickOptions;
200
+
201
+ export interface DragOptions {
202
+ /**
203
+ * The id of the element to be dragged.
204
+ * If the element id is missing then the start coordinates must be provided.
205
+ * If both the element id and the start coordinates are provided then these
206
+ * coordinates are considered as offsets from the top left element corner.
207
+ */
208
+ elementId?: string;
209
+ /**
210
+ * The x coordinate where the dragging starts
211
+ */
212
+ startX?: number;
213
+ /**
214
+ * The y coordinate where the dragging starts
215
+ */
216
+ startY?: number;
217
+ /**
218
+ * The x coordinate where the dragging ends
219
+ */
220
+ endX?: number;
221
+ /**
222
+ * The y coordinate where the dragging ends
223
+ */
224
+ endY?: number;
225
+ /**
226
+ * The speed at which to perform this gesture in pixels per second.
227
+ * The value must not be negative.
228
+ * Default is 2500 * displayDensity.
229
+ */
230
+ speed?: number;
231
+ }
232
+
233
+ export interface FlingOptions {
234
+ /**
235
+ * The id of the element to be flinged.
236
+ * If the element id is missing then fling bounding area must be provided.
237
+ * If both the element id and the fling bounding area are provided then this
238
+ * area is effectively ignored.
239
+ */
240
+ elementId?: string;
241
+ /**
242
+ * The left coordinate of the fling bounding area.
243
+ */
244
+ left?: number;
245
+ /**
246
+ * The top coordinate of the fling bounding area.
247
+ */
248
+ top?: number;
249
+ /**
250
+ * The width of the fling bounding area.
251
+ */
252
+ width?: number;
253
+ /**
254
+ * The height of the fling bounding area.
255
+ */
256
+ height?: number;
257
+ /**
258
+ * Direction of the fling.
259
+ * Acceptable values are: `up`, `down`, `left` and `right` (case insensitive).
260
+ */
261
+ direction: string;
262
+ /**
263
+ * The speed at which to perform this gesture in pixels per second.
264
+ * The value must be greater than the minimum fling velocity for the given view (50 by default).
265
+ * Default is 7500 * displayDensity.
266
+ */
267
+ speed?: number;
268
+ }
269
+
270
+ export interface PinchOptions {
271
+ /**
272
+ * The id of the element to be pinched.
273
+ * If the element id is missing then pinch bounding area must be provided.
274
+ * If both the element id and the pinch bounding area are provided then the
275
+ * area is effectively ignored.
276
+ */
277
+ elementId?: string;
278
+ /**
279
+ * The left coordinate of the pinch bounding area.
280
+ */
281
+ left?: number;
282
+ /**
283
+ * The top coordinate of the pinch bounding area.
284
+ */
285
+ top?: number;
286
+ /**
287
+ * The width of the pinch bounding area.
288
+ */
289
+ width?: number;
290
+ /**
291
+ * The height of the pinch bounding area.
292
+ */
293
+ height?: number;
294
+ /**
295
+ * The size of the pinch as a percentage of the pinch area size.
296
+ * Valid values must be float numbers in range 0..1, where 1.0 is 100%
297
+ */
298
+ percent: number;
299
+ /**
300
+ * The speed at which to perform this gesture in pixels per second.
301
+ * The value must not be negative.
302
+ * Default is 2500 * displayDensity.
303
+ */
304
+ speed?: number;
305
+ }
306
+
307
+ export interface SwipeOptions {
308
+ /**
309
+ * The id of the element to be swiped.
310
+ * If the element id is missing then swipe bounding area must be provided.
311
+ * If both the element id and the swipe bounding area are provided then the
312
+ * area is effectively ignored.
313
+ */
314
+ elementId?: string;
315
+ /**
316
+ * The left coordinate of the swipe bounding area.
317
+ */
318
+ left?: number;
319
+ /**
320
+ * The top coordinate of the swipe bounding area.
321
+ */
322
+ top?: number;
323
+ /**
324
+ * The width of the swipe bounding area.
325
+ */
326
+ width?: number;
327
+ /**
328
+ * The height of the swipe bounding area.
329
+ */
330
+ height?: number;
331
+ /**
332
+ * Direction of the swipe.
333
+ * Acceptable values are: `up`, `down`, `left` and `right` (case insensitive).
334
+ */
335
+ direction: string;
336
+ /**
337
+ * The size of the swipe as a percentage of the swipe area size.
338
+ * Valid values must be float numbers in range 0..1, where 1.0 is 100%.
339
+ */
340
+ percent: number;
341
+ /**
342
+ * The speed at which to perform this gesture in pixels per second.
343
+ * The value must not be negative.
344
+ * Default is 5000 * displayDensity.
345
+ */
346
+ speed?: number;
347
+ }
348
+ export interface ScrollGestureOptions {
349
+ /**
350
+ * The id of the element to be scrolled.
351
+ * If the element id is missing then scroll bounding area must be provided.
352
+ * If both the element id and the scroll bounding area are provided then this
353
+ * area is effectively ignored.
354
+ */
355
+ elementId?: string;
356
+ /**
357
+ * The left coordinate of the scroll bounding area.
358
+ */
359
+ left?: number;
360
+ /**
361
+ * The top coordinate of the scroll bounding area.
362
+ */
363
+ top?: number;
364
+ /**
365
+ * The width of the scroll bounding area.
366
+ */
367
+ width?: number;
368
+ /**
369
+ * The height of the scroll bounding area.
370
+ */
371
+ height?: number;
372
+ /**
373
+ * Direction of the scroll.
374
+ * Acceptable values are: `up`, `down`, `left` and `right` (case insensitive).
375
+ */
376
+ direction: string;
377
+ /**
378
+ * The size of the scroll as a percentage of the scrolling area size.
379
+ * Valid values must be float numbers greater than zero, where 1.0 is 100%.
380
+ */
381
+ percent: number;
382
+ /**
383
+ * The speed at which to perform this gesture in pixels per second.
384
+ * The value must not be negative.
385
+ * Default is 5000 * displayDensity.
386
+ */
387
+ speed?: number;
388
+ }
389
+
390
+ export interface ScrollElementToElementOpts {
391
+ /**
392
+ * The identifier of the scrollable element, which is going to be scrolled.
393
+ * It is required this element is a valid scrollable container and it was located
394
+ * by `-android uiautomator` strategy.
395
+ */
396
+ elementId: string;
397
+ /**
398
+ * The identifier of the item, which belongs to the scrollable element above,
399
+ * and which should become visible after the scrolling operation is finished.
400
+ * It is required this element was located by `-android uiautomator` strategy.
401
+ */
402
+ elementToId: string;
403
+ }
404
+
405
+ export interface ScrollOptions {
406
+ /**
407
+ * The identifier of an element. It is required this element is a valid scrollable container
408
+ * and it was located by `-android uiautomator` strategy.
409
+ * If this property is not provided then the first currently available scrollable view
410
+ * is selected for the interaction.
411
+ */
412
+ elementId?: string;
413
+ /**
414
+ * The following strategies are supported:
415
+ * - `accessibility id` (UiSelector().description)
416
+ * - `class name` (UiSelector().className)
417
+ * - `-android uiautomator` (UiSelector)
418
+ */
419
+ strategy: string;
420
+ /**
421
+ * The corresponding lookup value for the given strategy.
422
+ */
423
+ selector: string;
424
+ /**
425
+ * The maximum number of swipes to perform on the target scrollable view in order to reach
426
+ * the destination element. In case this value is unset then it would be retrieved from the
427
+ * scrollable element itself (via `getMaxSearchSwipes()` property).
428
+ */
429
+ maxSwipes?: number;
430
+ /**
431
+ * @deprecated
432
+ */
433
+ element?: string;
434
+ }
435
+
436
+ export type RelativeRect = Pick<Rect, 'width' | 'height'> & {left: Rect['x']; top: Rect['y']};
437
+
438
+ export interface Screenshot {
439
+ /**
440
+ * Display identifier
441
+ */
442
+ id: string;
443
+ /**
444
+ * Display name
445
+ */
446
+ name?: string;
447
+ /**
448
+ * Is this the default display
449
+ */
450
+ isDefault: boolean;
451
+ /**
452
+ * Actual PNG screenshot encoded as base64
453
+ */
454
+ payload: string;
455
+ }
456
+
457
+ export interface ScreenshotsOpts {
458
+ /**
459
+ * Android display identifier to take a screenshot for.
460
+ * If not provided then screenshots of all displays are going to be returned.
461
+ * If no matches were found then an error is thrown.
462
+ */
463
+ displayId?: number | string;
464
+ }
465
+
466
+ export interface ActionResult {
467
+ repeats: number;
468
+ stepResults: StringRecord[][];
469
+ }
470
+
471
+ export interface ActionArgs {
472
+ name: string;
473
+ }
@@ -1,38 +1,50 @@
1
- import { imageUtil } from 'appium/support';
1
+ // @ts-check
2
2
 
3
+ import {imageUtil} from 'appium/support';
4
+ import {mixin} from './mixins';
3
5
 
4
- let extensions = {}, commands = {};
6
+ /**
7
+ * @type {import('./mixins').UIA2ViewportMixin}
8
+ * @satisfies {import('@appium/types').ExternalDriver}
9
+ */
10
+ const ViewportMixin = {
11
+ // memoized in constructor
12
+ async getStatusBarHeight() {
13
+ const {statusBar} = /** @type {{statusBar: number}} */ (
14
+ await /** @type {import('../uiautomator2').UiAutomator2Server} */ (
15
+ this.uiautomator2
16
+ ).jwproxy.command(`/appium/device/system_bars`, 'GET', {})
17
+ );
18
+ return statusBar;
19
+ },
5
20
 
6
- // memoized in constructor
7
- commands.getStatusBarHeight = async function () {
8
- const {statusBar} = await this.uiautomator2.jwproxy.command(`/appium/device/system_bars`, 'GET', {});
9
- return statusBar;
10
- };
11
-
12
- // memoized in constructor
13
- commands.getDevicePixelRatio = async function () {
14
- return await this.uiautomator2.jwproxy.command('/appium/device/pixel_ratio', 'GET', {});
15
- };
21
+ // memoized in constructor
22
+ async getDevicePixelRatio() {
23
+ return String(
24
+ await /** @type {import('../uiautomator2').UiAutomator2Server} */ (
25
+ this.uiautomator2
26
+ ).jwproxy.command('/appium/device/pixel_ratio', 'GET', {})
27
+ );
28
+ },
16
29
 
17
- commands.getViewportScreenshot = async function () {
18
- const screenshot = await this.getScreenshot();
19
- const rect = await this.getViewPortRect();
20
- return await imageUtil.cropBase64Image(screenshot, rect);
21
- };
30
+ async getViewportScreenshot() {
31
+ const screenshot = await this.getScreenshot();
32
+ const rect = await this.getViewPortRect();
33
+ return await imageUtil.cropBase64Image(screenshot, rect);
34
+ },
22
35
 
23
- commands.getViewPortRect = async function () {
24
- const windowSize = await this.getWindowSize();
25
- const statusBarHeight = await this.getStatusBarHeight();
26
- // android returns the upscaled window size, so to get the true size of the
27
- // rect we have to downscale
28
- return {
29
- left: 0,
30
- top: statusBarHeight,
31
- width: windowSize.width,
32
- height: windowSize.height - statusBarHeight
33
- };
36
+ async getViewPortRect() {
37
+ const windowSize = await this.getWindowSize();
38
+ const statusBarHeight = await this.getStatusBarHeight();
39
+ // android returns the upscaled window size, so to get the true size of the
40
+ // rect we have to downscale
41
+ return {
42
+ left: 0,
43
+ top: statusBarHeight,
44
+ width: windowSize.width,
45
+ height: windowSize.height - statusBarHeight,
46
+ };
47
+ },
34
48
  };
35
49
 
36
- Object.assign(extensions, commands);
37
- export { commands };
38
- export default extensions;
50
+ mixin(ViewportMixin);
@@ -0,0 +1,53 @@
1
+ import {Constraints} from '@appium/types';
2
+ import {commonCapConstraints} from 'appium-android-driver';
3
+
4
+ const UIAUTOMATOR2_CONSTRAINTS = {
5
+ app: {
6
+ presence: true,
7
+ isString: true,
8
+ },
9
+ automationName: {
10
+ isString: true,
11
+ },
12
+ launchTimeout: {
13
+ isNumber: true,
14
+ },
15
+ uiautomator2ServerLaunchTimeout: {
16
+ isNumber: true,
17
+ },
18
+ uiautomator2ServerInstallTimeout: {
19
+ isNumber: true,
20
+ },
21
+ uiautomator2ServerReadTimeout: {
22
+ isNumber: true,
23
+ },
24
+ systemPort: {
25
+ isNumber: true,
26
+ },
27
+ mjpegServerPort: {
28
+ isNumber: true,
29
+ },
30
+ mjpegScreenshotUrl: {
31
+ isString: true,
32
+ },
33
+ skipServerInstallation: {
34
+ isBoolean: true,
35
+ },
36
+ androidCoverageEndIntent: {
37
+ isString: true,
38
+ },
39
+ disableSuppressAccessibilityService: {
40
+ isBoolean: true,
41
+ },
42
+ forceAppLaunch: {
43
+ isBoolean: true,
44
+ },
45
+ shouldTerminateApp: {
46
+ isBoolean: true,
47
+ },
48
+ ...commonCapConstraints,
49
+ } as const satisfies Constraints;
50
+
51
+ export default UIAUTOMATOR2_CONSTRAINTS;
52
+
53
+ export type Uiautomator2Constraints = typeof UIAUTOMATOR2_CONSTRAINTS;
@@ -46,6 +46,7 @@ const ALL_ATTRS = [
46
46
  ...STR_ATTRS,
47
47
  ];
48
48
 
49
+ /** @type {[string, string[]][]} */
49
50
  const ATTRIBUTE_ALIASES = [
50
51
  [RESOURCE_ID, ['id']],
51
52
  ['description', [
@@ -78,10 +79,12 @@ function toSnakeCase (str) {
78
79
  * @returns {string} Either 'true' or 'false'. If value is empty, return 'true'
79
80
  */
80
81
  function requireBoolean (css) {
82
+ // @ts-ignore Attributes should exist
81
83
  const val = _.toLower((css.value ?? css.argument)?.value) || 'true'; // an omitted boolean attribute means 'true' (e.g.: input[checked] means checked is true)
82
84
  if (['true', 'false'].includes(val)) {
83
85
  return val;
84
86
  }
87
+ // @ts-ignore The attribute should exist
85
88
  throw new Error(`'${css.name}' must be true, false or empty. Found '${css.value}'`);
86
89
  }
87
90
 
@@ -149,6 +152,7 @@ class CssConverter {
149
152
  * @returns {string} CSS attribute parsed as UiSelector
150
153
  */
151
154
  parseAttr (cssAttr) {
155
+ // @ts-ignore Value should be present
152
156
  const attrValue = cssAttr.value?.value;
153
157
  if (!_.isString(attrValue) && !_.isEmpty(attrValue)) {
154
158
  throw new Error(`'${cssAttr.name}=${attrValue}' is an invalid attribute. ` +
@@ -205,9 +209,10 @@ class CssConverter {
205
209
  * Convert a CSS pseudo class to a UiSelector
206
210
  *
207
211
  * @param {import('css-selector-parser').AstPseudoClass} cssPseudo CSS Pseudo class
208
- * @returns {string?} Pseudo selector parsed as UiSelector
212
+ * @returns {string|null|undefined} Pseudo selector parsed as UiSelector
209
213
  */
210
214
  parsePseudo (cssPseudo) {
215
+ // @ts-ignore The attribute should exist
211
216
  const argValue = cssPseudo.argument?.value;
212
217
  if (!_.isString(argValue) && !_.isEmpty(argValue)) {
213
218
  throw new Error(`'${cssPseudo.name}=${argValue}'. ` +
@@ -236,6 +241,7 @@ class CssConverter {
236
241
  }
237
242
 
238
243
  let uiAutomatorSelector = 'new UiSelector()';
244
+ // @ts-ignore the attribute should exist
239
245
  const tagName = cssRule.tag?.name;
240
246
  if (tagName && tagName !== '*') {
241
247
  let androidClass = [tagName];
@@ -248,9 +254,11 @@ class CssConverter {
248
254
  uiAutomatorSelector += `.classNameMatches("${tagName}")`;
249
255
  }
250
256
  } else if (!_.isEmpty(cssRule.classNames)) {
257
+ // @ts-ignore the attribute should exist
251
258
  uiAutomatorSelector += `.classNameMatches("${cssRule.classNames.join('\\.')}")`;
252
259
  }
253
260
  if (!_.isEmpty(cssRule.ids)) {
261
+ // @ts-ignore The attribute should exist
254
262
  uiAutomatorSelector += `.resourceId("${this.formatIdLocator(cssRule.ids[0])}")`;
255
263
  }
256
264
  if (cssRule.attributes) {