appium-uiautomator2-driver 2.42.2 → 2.43.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 (114) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/build/lib/commands/actions.d.ts +22 -1
  3. package/build/lib/commands/actions.d.ts.map +1 -1
  4. package/build/lib/commands/actions.js +30 -62
  5. package/build/lib/commands/actions.js.map +1 -1
  6. package/build/lib/commands/alert.d.ts +28 -1
  7. package/build/lib/commands/alert.d.ts.map +1 -1
  8. package/build/lib/commands/alert.js +42 -23
  9. package/build/lib/commands/alert.js.map +1 -1
  10. package/build/lib/commands/app-management.d.ts +19 -0
  11. package/build/lib/commands/app-management.d.ts.map +1 -0
  12. package/build/lib/commands/app-management.js +45 -0
  13. package/build/lib/commands/app-management.js.map +1 -0
  14. package/build/lib/commands/app-strings.d.ts +9 -0
  15. package/build/lib/commands/app-strings.d.ts.map +1 -1
  16. package/build/lib/commands/app-strings.js +11 -79
  17. package/build/lib/commands/app-strings.js.map +1 -1
  18. package/build/lib/commands/battery.d.ts +7 -0
  19. package/build/lib/commands/battery.d.ts.map +1 -1
  20. package/build/lib/commands/battery.js +14 -20
  21. package/build/lib/commands/battery.js.map +1 -1
  22. package/build/lib/commands/element.d.ts +100 -1
  23. package/build/lib/commands/element.d.ts.map +1 -1
  24. package/build/lib/commands/element.js +175 -125
  25. package/build/lib/commands/element.js.map +1 -1
  26. package/build/lib/commands/execute.d.ts +25 -0
  27. package/build/lib/commands/execute.d.ts.map +1 -0
  28. package/build/lib/commands/execute.js +109 -0
  29. package/build/lib/commands/execute.js.map +1 -0
  30. package/build/lib/commands/find.d.ts +10 -0
  31. package/build/lib/commands/find.d.ts.map +1 -1
  32. package/build/lib/commands/find.js +25 -27
  33. package/build/lib/commands/find.js.map +1 -1
  34. package/build/lib/commands/gestures.d.ts +103 -1
  35. package/build/lib/commands/gestures.d.ts.map +1 -1
  36. package/build/lib/commands/gestures.js +202 -173
  37. package/build/lib/commands/gestures.js.map +1 -1
  38. package/build/lib/commands/keyboard.d.ts +47 -0
  39. package/build/lib/commands/keyboard.d.ts.map +1 -0
  40. package/build/lib/commands/keyboard.js +92 -0
  41. package/build/lib/commands/keyboard.js.map +1 -0
  42. package/build/lib/commands/misc.d.ts +48 -0
  43. package/build/lib/commands/misc.d.ts.map +1 -0
  44. package/build/lib/commands/misc.js +75 -0
  45. package/build/lib/commands/misc.js.map +1 -0
  46. package/build/lib/commands/navigation.d.ts +20 -0
  47. package/build/lib/commands/navigation.d.ts.map +1 -0
  48. package/build/lib/commands/navigation.js +35 -0
  49. package/build/lib/commands/navigation.js.map +1 -0
  50. package/build/lib/commands/screenshot.d.ts +24 -1
  51. package/build/lib/commands/screenshot.d.ts.map +1 -1
  52. package/build/lib/commands/screenshot.js +87 -64
  53. package/build/lib/commands/screenshot.js.map +1 -1
  54. package/build/lib/commands/touch.d.ts +81 -0
  55. package/build/lib/commands/touch.d.ts.map +1 -1
  56. package/build/lib/commands/touch.js +158 -41
  57. package/build/lib/commands/touch.js.map +1 -1
  58. package/build/lib/commands/viewport.d.ts +37 -1
  59. package/build/lib/commands/viewport.d.ts.map +1 -1
  60. package/build/lib/commands/viewport.js +80 -36
  61. package/build/lib/commands/viewport.js.map +1 -1
  62. package/build/lib/driver.d.ts +94 -24
  63. package/build/lib/driver.d.ts.map +1 -1
  64. package/build/lib/driver.js +114 -28
  65. package/build/lib/driver.js.map +1 -1
  66. package/build/lib/helpers.d.ts +12 -6
  67. package/build/lib/helpers.d.ts.map +1 -1
  68. package/build/lib/helpers.js +18 -18
  69. package/build/lib/helpers.js.map +1 -1
  70. package/build/lib/method-map.d.ts +0 -23
  71. package/build/lib/method-map.d.ts.map +1 -1
  72. package/build/lib/uiautomator2.js +3 -3
  73. package/build/lib/uiautomator2.js.map +1 -1
  74. package/build/tsconfig.tsbuildinfo +1 -1
  75. package/lib/commands/actions.js +37 -114
  76. package/lib/commands/alert.js +51 -37
  77. package/lib/commands/app-management.js +42 -0
  78. package/lib/commands/app-strings.js +9 -89
  79. package/lib/commands/battery.js +16 -26
  80. package/lib/commands/element.js +235 -214
  81. package/lib/commands/execute.js +120 -0
  82. package/lib/commands/find.js +31 -37
  83. package/lib/commands/gestures.js +252 -234
  84. package/lib/commands/keyboard.js +103 -0
  85. package/lib/commands/misc.js +106 -0
  86. package/lib/commands/navigation.js +31 -0
  87. package/lib/commands/screenshot.js +96 -77
  88. package/lib/commands/touch.js +190 -48
  89. package/lib/commands/viewport.js +100 -50
  90. package/lib/driver.ts +225 -36
  91. package/lib/helpers.js +15 -22
  92. package/lib/uiautomator2.js +3 -3
  93. package/npm-shrinkwrap.json +34 -34
  94. package/package.json +2 -2
  95. package/build/lib/commands/general.d.ts +0 -4
  96. package/build/lib/commands/general.d.ts.map +0 -1
  97. package/build/lib/commands/general.js +0 -214
  98. package/build/lib/commands/general.js.map +0 -1
  99. package/build/lib/commands/index.d.ts +0 -2
  100. package/build/lib/commands/index.d.ts.map +0 -1
  101. package/build/lib/commands/index.js +0 -14
  102. package/build/lib/commands/index.js.map +0 -1
  103. package/build/lib/commands/mixins.d.ts +0 -87
  104. package/build/lib/commands/mixins.d.ts.map +0 -1
  105. package/build/lib/commands/mixins.js +0 -26
  106. package/build/lib/commands/mixins.js.map +0 -1
  107. package/build/lib/utils.d.ts +0 -10
  108. package/build/lib/utils.d.ts.map +0 -1
  109. package/build/lib/utils.js +0 -26
  110. package/build/lib/utils.js.map +0 -1
  111. package/lib/commands/general.js +0 -289
  112. package/lib/commands/index.js +0 -11
  113. package/lib/commands/mixins.ts +0 -169
  114. package/lib/utils.js +0 -19
@@ -1,187 +1,189 @@
1
- // @ts-check
2
- import {mixin} from './mixins';
3
1
  import {util} from 'appium/support';
4
2
  import _ from 'lodash';
5
3
  import {errors} from 'appium/driver';
6
4
 
7
5
  /**
6
+ * Performs a simple click/tap gesture
8
7
  *
9
- * @param {import('@appium/types').Element|string} [element]
10
- * @returns {import('@appium/types').Element|undefined}
8
+ * @this {AndroidUiautomator2Driver}
9
+ * @param {import('./types').ClickOptions} [opts={}]
10
+ * @returns {Promise<void>}
11
+ * @throws {Error} if provided options are not valid
11
12
  */
12
- function toOrigin(element) {
13
- return element ? util.wrapElement(util.unwrapElement(element)) : undefined;
13
+ export async function mobileClickGesture(opts = {}) {
14
+ const {elementId, x, y} = opts;
15
+ await this.uiautomator2.jwproxy.command(
16
+ '/appium/gestures/click',
17
+ 'POST',
18
+ {
19
+ origin: toOrigin(elementId),
20
+ offset: toPoint(x, y),
21
+ }
22
+ );
14
23
  }
15
24
 
16
25
  /**
26
+ * Performs a click that lasts for the given duration
17
27
  *
18
- * @param {number} [x]
19
- * @param {number} [y]
20
- * @returns {Partial<import('@appium/types').Position>|undefined}
28
+ * @this {AndroidUiautomator2Driver}
29
+ * @param {import('./types').LongClickOptions} [opts={}]
30
+ * @returns {Promise<void>}
31
+ * @throws {Error} if provided options are not valid
21
32
  */
22
- function toPoint(x, y) {
23
- return _.isFinite(x) && _.isFinite(y) ? {x, y} : undefined;
33
+ export async function mobileLongClickGesture(opts = {}) {
34
+ const {elementId, x, y, duration} = opts;
35
+ await this.uiautomator2.jwproxy.command(
36
+ '/appium/gestures/long_click',
37
+ 'POST',
38
+ {
39
+ origin: toOrigin(elementId),
40
+ offset: toPoint(x, y),
41
+ duration,
42
+ }
43
+ );
24
44
  }
25
45
 
26
46
  /**
27
- *
28
- * @param {number} [left]
29
- * @param {number} [top]
30
- * @param {number} [width]
31
- * @param {number} [height]
32
- * @returns {Partial<import('./types').RelativeRect>|undefined}
47
+ * Performs a click that lasts for the given duration
48
+ * @this {AndroidUiautomator2Driver}
49
+ * @param {import('./types').DoubleClickOptions} [opts={}]
50
+ * @returns {Promise<void>}
51
+ * @throws {Error} if provided options are not valid
33
52
  */
34
- function toRect(left, top, width, height) {
35
- return [left, top, width, height].some((v) => !_.isFinite(v))
36
- ? undefined
37
- : {left, top, width, height};
53
+ export async function mobileDoubleClickGesture(opts = {}) {
54
+ const {elementId, x, y} = opts;
55
+ await this.uiautomator2.jwproxy.command(
56
+ '/appium/gestures/double_click',
57
+ 'POST',
58
+ {
59
+ origin: toOrigin(elementId),
60
+ offset: toPoint(x, y),
61
+ }
62
+ );
38
63
  }
39
64
 
40
65
  /**
41
- * @type {import('./mixins').UIA2GesturesMixin}
42
- * @satisfies {import('@appium/types').ExternalDriver}
66
+ * Drags this object to the specified location.
67
+ * @this {AndroidUiautomator2Driver}
68
+ * @param {import('./types').DragOptions} opts
69
+ * @returns {Promise<void>}
70
+ * @throws {Error} if provided options are not valid
43
71
  */
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 this.uiautomator2.jwproxy.command(
53
- '/appium/gestures/click',
54
- 'POST',
55
- {
56
- origin: toOrigin(elementId),
57
- offset: toPoint(x, y),
58
- }
59
- );
60
- },
61
-
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 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
- },
79
-
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 this.uiautomator2.jwproxy.command(
88
- '/appium/gestures/double_click',
89
- 'POST',
90
- {
91
- origin: toOrigin(elementId),
92
- offset: toPoint(x, y),
93
- }
94
- );
95
- },
72
+ export async function mobileDragGesture(opts) {
73
+ const {elementId, startX, startY, endX, endY, speed} = opts;
74
+ await this.uiautomator2.jwproxy.command(
75
+ '/appium/gestures/drag',
76
+ 'POST',
77
+ {
78
+ origin: toOrigin(elementId),
79
+ start: toPoint(startX, startY),
80
+ end: toPoint(endX, endY),
81
+ speed,
82
+ }
83
+ );
84
+ }
96
85
 
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;
86
+ /**
87
+ * Drags to the specified location.
88
+ *
89
+ * @throws {Error} if provided options are not valid
90
+ * @this {AndroidUiautomator2Driver}
91
+ * @param {import('./types').FlingOptions} opts
92
+ * @returns {Promise<boolean>} True if the object can still scroll in the given direction.
93
+ */
94
+ export async function mobileFlingGesture(opts) {
95
+ const {elementId, left, top, width, height, direction, speed} = opts;
96
+ return /** @type {boolean} */ (
104
97
  await this.uiautomator2.jwproxy.command(
105
- '/appium/gestures/drag',
98
+ '/appium/gestures/fling',
106
99
  'POST',
107
100
  {
108
101
  origin: toOrigin(elementId),
109
- start: toPoint(startX, startY),
110
- end: toPoint(endX, endY),
102
+ area: toRect(left, top, width, height),
103
+ direction,
111
104
  speed,
112
105
  }
113
- );
114
- },
106
+ )
107
+ );
108
+ }
115
109
 
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 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
- },
110
+ /**
111
+ * Performs a pinch close gesture.
112
+ * @this {AndroidUiautomator2Driver}
113
+ * @param {import('./types').PinchOptions} opts
114
+ * @returns {Promise<void>}
115
+ * @throws {Error} if provided options are not valid
116
+ */
117
+ export async function mobilePinchCloseGesture(opts) {
118
+ const {elementId, left, top, width, height, percent, speed} = opts;
119
+ await this.uiautomator2.jwproxy.command(
120
+ '/appium/gestures/pinch_close',
121
+ 'POST',
122
+ {
123
+ origin: toOrigin(elementId),
124
+ area: toRect(left, top, width, height),
125
+ percent,
126
+ speed,
127
+ }
128
+ );
129
+ }
137
130
 
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 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
- },
131
+ /**
132
+ * Performs a pinch open gesture.
133
+ * @this {AndroidUiautomator2Driver}
134
+ * @param {import('./types').PinchOptions} opts
135
+ * @returns {Promise<void>}
136
+ * @throws {Error} if provided options are not valid
137
+ */
138
+ export async function mobilePinchOpenGesture(opts) {
139
+ const {elementId, left, top, width, height, percent, speed} = opts;
140
+ await this.uiautomator2.jwproxy.command(
141
+ '/appium/gestures/pinch_open',
142
+ 'POST',
143
+ {
144
+ origin: toOrigin(elementId),
145
+ area: toRect(left, top, width, height),
146
+ percent,
147
+ speed,
148
+ }
149
+ );
150
+ }
156
151
 
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 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
- },
152
+ /**
153
+ * Performs a swipe gesture.
154
+ * @this {AndroidUiautomator2Driver}
155
+ * @param {import('./types').SwipeOptions} opts
156
+ * @returns {Promise<void>}
157
+ * @throws {Error} if provided options are not valid
158
+ */
159
+ export async function mobileSwipeGesture(opts) {
160
+ const {elementId, left, top, width, height, direction, percent, speed} = opts;
161
+ await this.uiautomator2.jwproxy.command(
162
+ '/appium/gestures/swipe',
163
+ 'POST',
164
+ {
165
+ origin: toOrigin(elementId),
166
+ area: toRect(left, top, width, height),
167
+ direction,
168
+ percent,
169
+ speed,
170
+ }
171
+ );
172
+ }
175
173
 
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;
174
+ /**
175
+ * Performs a scroll gesture.
176
+ *
177
+ * @throws {Error} if provided options are not valid
178
+ * @this {AndroidUiautomator2Driver}
179
+ * @param {import('./types').ScrollGestureOptions} opts
180
+ * @returns {Promise<boolean>} True if the object can still scroll in the given direction.
181
+ */
182
+ export async function mobileScrollGesture(opts) {
183
+ const {elementId, left, top, width, height, direction, percent, speed} = opts;
184
+ return /** @type {boolean} */ (
183
185
  await this.uiautomator2.jwproxy.command(
184
- '/appium/gestures/swipe',
186
+ '/appium/gestures/scroll',
185
187
  'POST',
186
188
  {
187
189
  origin: toOrigin(elementId),
@@ -190,94 +192,110 @@ const GesturesMixin = {
190
192
  percent,
191
193
  speed,
192
194
  }
193
- );
194
- },
195
+ )
196
+ );
197
+ }
195
198
 
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 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
- )
199
+ /**
200
+ * Scrolls the given scrollable element `elementId` until `elementToId`
201
+ * becomes visible. This function returns immediately if the `elementToId`
202
+ * is already visible in the view port. Otherwise it would scroll
203
+ * to the very beginning of the scrollable control and tries to reach the destination element
204
+ * by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
205
+ * is detected automatically.
206
+ * @this {AndroidUiautomator2Driver}
207
+ * @param {import('./types').ScrollElementToElementOpts} opts
208
+ * @returns {Promise<void>}
209
+ * @throws {Error} if the scrolling operation cannot be performed
210
+ */
211
+ export async function mobileScrollBackTo(opts) {
212
+ const {elementId, elementToId} = opts;
213
+ if (!elementId || !elementToId) {
214
+ throw new errors.InvalidArgumentError(
215
+ `Both elementId and elementToId arguments must be provided`
216
216
  );
217
- },
217
+ }
218
+ await this.uiautomator2.jwproxy.command(
219
+ `/appium/element/${util.unwrapElement(elementId)}/scroll_to/${util.unwrapElement(
220
+ elementToId
221
+ )}`,
222
+ 'POST',
223
+ {}
224
+ );
225
+ }
218
226
 
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 this.uiautomator2.jwproxy.command(
237
- `/appium/element/${util.unwrapElement(elementId)}/scroll_to/${util.unwrapElement(
238
- elementToId
239
- )}`,
240
- 'POST',
241
- {}
227
+ /**
228
+ * Scrolls the given scrollable element until the element identified
229
+ * by `strategy` and `selector` becomes visible. This function returns immediately if the
230
+ * destination element is already visible in the view port. Otherwise it would scroll
231
+ * to the very beginning of the scrollable control and tries to reach the destination element
232
+ * by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
233
+ * is detected automatically.
234
+ * @this {AndroidUiautomator2Driver}
235
+ * @param {import('./types').ScrollOptions} opts
236
+ * @returns {Promise<void>}
237
+ * @throws {Error} if the scrolling operation cannot be performed
238
+ */
239
+ export async function mobileScroll(opts) {
240
+ const {
241
+ element,
242
+ elementId, // `element` is deprecated, use `elementId` instead
243
+ strategy,
244
+ selector,
245
+ maxSwipes,
246
+ } = opts;
247
+ if (!strategy || !selector) {
248
+ throw new errors.InvalidArgumentError(
249
+ `Both strategy and selector arguments must be provided`
242
250
  );
243
- },
244
-
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
- );
251
+ }
252
+ await this.uiautomator2.jwproxy.command(
253
+ '/touch/scroll',
254
+ 'POST',
255
+ {
256
+ origin: toOrigin(elementId || element),
257
+ params: {strategy, selector, maxSwipes},
267
258
  }
268
- await this.uiautomator2.jwproxy.command(
269
- '/touch/scroll',
270
- 'POST',
271
- {
272
- origin: toOrigin(elementId || element),
273
- params: {strategy, selector, maxSwipes},
274
- }
275
- );
276
- },
277
- };
259
+ );
260
+ }
261
+
262
+ // #region Internal Helpers
263
+
264
+ /**
265
+ *
266
+ * @param {import('@appium/types').Element|string} [element]
267
+ * @returns {import('@appium/types').Element|undefined}
268
+ */
269
+ function toOrigin(element) {
270
+ return element ? util.wrapElement(util.unwrapElement(element)) : undefined;
271
+ }
272
+
273
+ /**
274
+ *
275
+ * @param {number} [x]
276
+ * @param {number} [y]
277
+ * @returns {Partial<import('@appium/types').Position>|undefined}
278
+ */
279
+ function toPoint(x, y) {
280
+ return _.isFinite(x) && _.isFinite(y) ? {x, y} : undefined;
281
+ }
282
+
283
+ /**
284
+ *
285
+ * @param {number} [left]
286
+ * @param {number} [top]
287
+ * @param {number} [width]
288
+ * @param {number} [height]
289
+ * @returns {Partial<import('./types').RelativeRect>|undefined}
290
+ */
291
+ function toRect(left, top, width, height) {
292
+ return [left, top, width, height].some((v) => !_.isFinite(v))
293
+ ? undefined
294
+ : {left, top, width, height};
295
+ }
278
296
 
279
- mixin(GesturesMixin);
297
+ // #endregion
280
298
 
281
299
  /**
282
- * @typedef {import('../uiautomator2').UiAutomator2Server} UiAutomator2Server
300
+ * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
283
301
  */
@@ -0,0 +1,103 @@
1
+ import _ from 'lodash';
2
+
3
+ /**
4
+ * @this {AndroidUiautomator2Driver}
5
+ * @param {string|number} keycode
6
+ * @param {number} [metastate]
7
+ * @param {number} [flags]
8
+ * @returns {Promise<void>}
9
+ */
10
+ export async function pressKeyCode(keycode, metastate, flags) {
11
+ await this.uiautomator2.jwproxy.command(
12
+ '/appium/device/press_keycode',
13
+ 'POST',
14
+ {
15
+ keycode,
16
+ metastate,
17
+ flags,
18
+ }
19
+ );
20
+ }
21
+
22
+ /**
23
+ * @this {AndroidUiautomator2Driver}
24
+ * @param {string|number} keycode
25
+ * @param {number} metastate
26
+ * @param {number} [flags]
27
+ * @returns {Promise<void>}
28
+ */
29
+ export async function longPressKeyCode(keycode, metastate, flags) {
30
+ await this.uiautomator2.jwproxy.command(
31
+ '/appium/device/long_press_keycode',
32
+ 'POST',
33
+ {
34
+ keycode,
35
+ metastate,
36
+ flags,
37
+ }
38
+ );
39
+ }
40
+
41
+ /**
42
+ * @this {AndroidUiautomator2Driver}
43
+ * @param {import('./types').PressKeyOptions} opts
44
+ * @returns {Promise<void>}
45
+ */
46
+ export async function mobilePressKey(opts) {
47
+ const {keycode, metastate, flags, isLongPress = false} = opts;
48
+
49
+ await this.uiautomator2.jwproxy.command(
50
+ `/appium/device/${isLongPress ? 'long_' : ''}press_keycode`,
51
+ 'POST',
52
+ {
53
+ keycode,
54
+ metastate,
55
+ flags,
56
+ }
57
+ );
58
+ }
59
+
60
+ /**
61
+ * Types the given Unicode string.
62
+ * It is expected that the focus is already put
63
+ * to the destination input field before this method is called.
64
+ * @this {AndroidUiautomator2Driver}
65
+ * @param {import('./types').TypingOptions} opts
66
+ * @returns {Promise<boolean>} `true` if the input text has been successfully sent to adb
67
+ * @throws {Error} if `text` property has not been provided
68
+ */
69
+ export async function mobileType(opts) {
70
+ const {text} = opts;
71
+ if (_.isUndefined(text)) {
72
+ throw this.log.errorAndThrow(`The 'text' argument is mandatory`);
73
+ }
74
+ return await this.settingsApp.typeUnicode(String(text));
75
+ }
76
+
77
+ /**
78
+ * @this {AndroidUiautomator2Driver}
79
+ * @param {import('appium-android-driver').SendKeysOpts} params
80
+ * @returns {Promise<void>}
81
+ */
82
+ export async function doSendKeys(params) {
83
+ await this.uiautomator2.jwproxy.command(
84
+ '/keys',
85
+ 'POST',
86
+ params
87
+ );
88
+ }
89
+
90
+ /**
91
+ * @this {AndroidUiautomator2Driver}
92
+ * @param {string|number} keycode
93
+ * @param {number} [metastate]
94
+ * @returns {Promise<void>}
95
+ */
96
+ export async function keyevent(keycode, metastate) {
97
+ this.log.debug(`Ignoring metastate ${metastate}`);
98
+ await this.adb.keyevent(keycode);
99
+ }
100
+
101
+ /**
102
+ * @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
103
+ */