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.
- package/CHANGELOG.md +14 -0
- package/build/lib/commands/actions.d.ts +22 -1
- package/build/lib/commands/actions.d.ts.map +1 -1
- package/build/lib/commands/actions.js +30 -62
- package/build/lib/commands/actions.js.map +1 -1
- package/build/lib/commands/alert.d.ts +28 -1
- package/build/lib/commands/alert.d.ts.map +1 -1
- package/build/lib/commands/alert.js +42 -23
- package/build/lib/commands/alert.js.map +1 -1
- package/build/lib/commands/app-management.d.ts +19 -0
- package/build/lib/commands/app-management.d.ts.map +1 -0
- package/build/lib/commands/app-management.js +45 -0
- package/build/lib/commands/app-management.js.map +1 -0
- package/build/lib/commands/app-strings.d.ts +9 -0
- package/build/lib/commands/app-strings.d.ts.map +1 -1
- package/build/lib/commands/app-strings.js +11 -79
- package/build/lib/commands/app-strings.js.map +1 -1
- package/build/lib/commands/battery.d.ts +7 -0
- package/build/lib/commands/battery.d.ts.map +1 -1
- package/build/lib/commands/battery.js +14 -20
- package/build/lib/commands/battery.js.map +1 -1
- package/build/lib/commands/element.d.ts +100 -1
- package/build/lib/commands/element.d.ts.map +1 -1
- package/build/lib/commands/element.js +175 -125
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/execute.d.ts +25 -0
- package/build/lib/commands/execute.d.ts.map +1 -0
- package/build/lib/commands/execute.js +109 -0
- package/build/lib/commands/execute.js.map +1 -0
- package/build/lib/commands/find.d.ts +10 -0
- package/build/lib/commands/find.d.ts.map +1 -1
- package/build/lib/commands/find.js +25 -27
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/gestures.d.ts +103 -1
- package/build/lib/commands/gestures.d.ts.map +1 -1
- package/build/lib/commands/gestures.js +202 -173
- package/build/lib/commands/gestures.js.map +1 -1
- package/build/lib/commands/keyboard.d.ts +47 -0
- package/build/lib/commands/keyboard.d.ts.map +1 -0
- package/build/lib/commands/keyboard.js +92 -0
- package/build/lib/commands/keyboard.js.map +1 -0
- package/build/lib/commands/misc.d.ts +48 -0
- package/build/lib/commands/misc.d.ts.map +1 -0
- package/build/lib/commands/misc.js +75 -0
- package/build/lib/commands/misc.js.map +1 -0
- package/build/lib/commands/navigation.d.ts +20 -0
- package/build/lib/commands/navigation.d.ts.map +1 -0
- package/build/lib/commands/navigation.js +35 -0
- package/build/lib/commands/navigation.js.map +1 -0
- package/build/lib/commands/screenshot.d.ts +24 -1
- package/build/lib/commands/screenshot.d.ts.map +1 -1
- package/build/lib/commands/screenshot.js +87 -64
- package/build/lib/commands/screenshot.js.map +1 -1
- package/build/lib/commands/touch.d.ts +81 -0
- package/build/lib/commands/touch.d.ts.map +1 -1
- package/build/lib/commands/touch.js +158 -41
- package/build/lib/commands/touch.js.map +1 -1
- package/build/lib/commands/viewport.d.ts +37 -1
- package/build/lib/commands/viewport.d.ts.map +1 -1
- package/build/lib/commands/viewport.js +80 -36
- package/build/lib/commands/viewport.js.map +1 -1
- package/build/lib/driver.d.ts +94 -24
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +114 -28
- package/build/lib/driver.js.map +1 -1
- package/build/lib/helpers.d.ts +12 -6
- package/build/lib/helpers.d.ts.map +1 -1
- package/build/lib/helpers.js +18 -18
- package/build/lib/helpers.js.map +1 -1
- package/build/lib/method-map.d.ts +0 -23
- package/build/lib/method-map.d.ts.map +1 -1
- package/build/lib/uiautomator2.js +3 -3
- package/build/lib/uiautomator2.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/actions.js +37 -114
- package/lib/commands/alert.js +51 -37
- package/lib/commands/app-management.js +42 -0
- package/lib/commands/app-strings.js +9 -89
- package/lib/commands/battery.js +16 -26
- package/lib/commands/element.js +235 -214
- package/lib/commands/execute.js +120 -0
- package/lib/commands/find.js +31 -37
- package/lib/commands/gestures.js +252 -234
- package/lib/commands/keyboard.js +103 -0
- package/lib/commands/misc.js +106 -0
- package/lib/commands/navigation.js +31 -0
- package/lib/commands/screenshot.js +96 -77
- package/lib/commands/touch.js +190 -48
- package/lib/commands/viewport.js +100 -50
- package/lib/driver.ts +225 -36
- package/lib/helpers.js +15 -22
- package/lib/uiautomator2.js +3 -3
- package/npm-shrinkwrap.json +34 -34
- package/package.json +2 -2
- package/build/lib/commands/general.d.ts +0 -4
- package/build/lib/commands/general.d.ts.map +0 -1
- package/build/lib/commands/general.js +0 -214
- package/build/lib/commands/general.js.map +0 -1
- package/build/lib/commands/index.d.ts +0 -2
- package/build/lib/commands/index.d.ts.map +0 -1
- package/build/lib/commands/index.js +0 -14
- package/build/lib/commands/index.js.map +0 -1
- package/build/lib/commands/mixins.d.ts +0 -87
- package/build/lib/commands/mixins.d.ts.map +0 -1
- package/build/lib/commands/mixins.js +0 -26
- package/build/lib/commands/mixins.js.map +0 -1
- package/build/lib/utils.d.ts +0 -10
- package/build/lib/utils.d.ts.map +0 -1
- package/build/lib/utils.js +0 -26
- package/build/lib/utils.js.map +0 -1
- package/lib/commands/general.js +0 -289
- package/lib/commands/index.js +0 -11
- package/lib/commands/mixins.ts +0 -169
- package/lib/utils.js +0 -19
package/lib/commands/gestures.js
CHANGED
|
@@ -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
|
-
* @
|
|
10
|
-
* @
|
|
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
|
|
13
|
-
|
|
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
|
-
* @
|
|
19
|
-
* @param {
|
|
20
|
-
* @returns {
|
|
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
|
|
23
|
-
|
|
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
|
-
* @
|
|
29
|
-
* @param {
|
|
30
|
-
* @
|
|
31
|
-
* @
|
|
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
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
*
|
|
42
|
-
* @
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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/
|
|
98
|
+
'/appium/gestures/fling',
|
|
106
99
|
'POST',
|
|
107
100
|
{
|
|
108
101
|
origin: toOrigin(elementId),
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
area: toRect(left, top, width, height),
|
|
103
|
+
direction,
|
|
111
104
|
speed,
|
|
112
105
|
}
|
|
113
|
-
)
|
|
114
|
-
|
|
106
|
+
)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
115
109
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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/
|
|
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
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
|
|
297
|
+
// #endregion
|
|
280
298
|
|
|
281
299
|
/**
|
|
282
|
-
* @typedef {import('../
|
|
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
|
+
*/
|