appium-uiautomator2-driver 6.7.5 → 6.7.6
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 +6 -0
- package/build/lib/commands/element.d.ts +35 -69
- package/build/lib/commands/element.d.ts.map +1 -1
- package/build/lib/commands/element.js +35 -84
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/gestures.d.ts +24 -189
- package/build/lib/commands/gestures.d.ts.map +1 -1
- package/build/lib/commands/gestures.js +14 -204
- package/build/lib/commands/gestures.js.map +1 -1
- package/build/lib/commands/misc.d.ts +15 -35
- package/build/lib/commands/misc.d.ts.map +1 -1
- package/build/lib/commands/misc.js +11 -30
- package/build/lib/commands/misc.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/element.ts +151 -0
- package/lib/commands/gestures.ts +234 -0
- package/lib/commands/misc.ts +63 -0
- package/npm-shrinkwrap.json +16 -46
- package/package.json +1 -1
- package/lib/commands/element.js +0 -261
- package/lib/commands/gestures.js +0 -446
- package/lib/commands/misc.js +0 -109
package/lib/commands/element.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import B from 'bluebird';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import {PROTOCOLS} from 'appium/driver';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @this {AndroidUiautomator2Driver}
|
|
7
|
-
* @returns {Promise<import('@appium/types').Element>}
|
|
8
|
-
*/
|
|
9
|
-
export async function active() {
|
|
10
|
-
return /** @type {import('@appium/types').Element} */ (
|
|
11
|
-
await this.uiautomator2.jwproxy.command(
|
|
12
|
-
'/element/active',
|
|
13
|
-
'GET'
|
|
14
|
-
)
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @this {AndroidUiautomator2Driver}
|
|
20
|
-
* @param {string} attribute
|
|
21
|
-
* @param {string} elementId
|
|
22
|
-
* @returns {Promise<string?>}
|
|
23
|
-
*/
|
|
24
|
-
export async function getAttribute(attribute, elementId) {
|
|
25
|
-
return String(
|
|
26
|
-
await this.uiautomator2.jwproxy.command(
|
|
27
|
-
`/element/${elementId}/attribute/${attribute}`,
|
|
28
|
-
'GET',
|
|
29
|
-
{}
|
|
30
|
-
)
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @this {AndroidUiautomator2Driver}
|
|
36
|
-
* @param {string} elementId
|
|
37
|
-
* @returns {Promise<boolean>}
|
|
38
|
-
*/
|
|
39
|
-
export async function elementDisplayed(elementId) {
|
|
40
|
-
return toBool(await this.getAttribute('displayed', elementId));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @this {AndroidUiautomator2Driver}
|
|
45
|
-
* @param {string} elementId
|
|
46
|
-
* @returns {Promise<boolean>}
|
|
47
|
-
*/
|
|
48
|
-
export async function elementEnabled(elementId) {
|
|
49
|
-
return toBool(await this.getAttribute('enabled', elementId));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @this {AndroidUiautomator2Driver}
|
|
54
|
-
* @param {string} elementId
|
|
55
|
-
* @returns {Promise<boolean>}
|
|
56
|
-
*/
|
|
57
|
-
export async function elementSelected(elementId) {
|
|
58
|
-
return toBool(await this.getAttribute('selected', elementId));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @this {AndroidUiautomator2Driver}
|
|
63
|
-
* @param {string} elementId
|
|
64
|
-
* @returns {Promise<string>}
|
|
65
|
-
*/
|
|
66
|
-
export async function getName(elementId) {
|
|
67
|
-
return /** @type {string} */ (
|
|
68
|
-
await this.uiautomator2.jwproxy.command(
|
|
69
|
-
`/element/${elementId}/name`,
|
|
70
|
-
'GET',
|
|
71
|
-
{}
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @this {AndroidUiautomator2Driver}
|
|
78
|
-
* @param {string} elementId
|
|
79
|
-
* @returns {Promise<import('@appium/types').Position>}
|
|
80
|
-
*/
|
|
81
|
-
export async function getLocation(elementId) {
|
|
82
|
-
return /** @type {import('@appium/types').Position} */ (
|
|
83
|
-
await this.uiautomator2.jwproxy.command(
|
|
84
|
-
`/element/${elementId}/location`,
|
|
85
|
-
'GET',
|
|
86
|
-
{}
|
|
87
|
-
)
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @this {AndroidUiautomator2Driver}
|
|
93
|
-
* @param {string} elementId
|
|
94
|
-
* @returns {Promise<import('@appium/types').Size>}
|
|
95
|
-
*/
|
|
96
|
-
export async function getSize(elementId) {
|
|
97
|
-
return /** @type {import('@appium/types').Size} */ (
|
|
98
|
-
await this.uiautomator2.jwproxy.command(
|
|
99
|
-
`/element/${elementId}/size`,
|
|
100
|
-
'GET',
|
|
101
|
-
{}
|
|
102
|
-
)
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* @this {AndroidUiautomator2Driver}
|
|
108
|
-
* @param {import('appium-android-driver').DoSetElementValueOpts} params
|
|
109
|
-
* @returns {Promise<void>}
|
|
110
|
-
*/
|
|
111
|
-
export async function doSetElementValue(params) {
|
|
112
|
-
await this.uiautomator2.jwproxy.command(
|
|
113
|
-
`/element/${params.elementId}/value`,
|
|
114
|
-
'POST',
|
|
115
|
-
params
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @this {AndroidUiautomator2Driver}
|
|
121
|
-
* @param {string|string[]} keys
|
|
122
|
-
* @param {string} elementId
|
|
123
|
-
* @returns {Promise<void>}
|
|
124
|
-
*/
|
|
125
|
-
export async function setValueImmediate(keys, elementId) {
|
|
126
|
-
await this.uiautomator2.jwproxy.command(
|
|
127
|
-
`/element/${elementId}/value`,
|
|
128
|
-
'POST',
|
|
129
|
-
{
|
|
130
|
-
elementId,
|
|
131
|
-
text: _.isArray(keys) ? keys.join('') : keys,
|
|
132
|
-
replace: false,
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @this {AndroidUiautomator2Driver}
|
|
139
|
-
* @param {string} elementId
|
|
140
|
-
* @returns {Promise<string>}
|
|
141
|
-
*/
|
|
142
|
-
export async function getText(elementId) {
|
|
143
|
-
return String(
|
|
144
|
-
await this.uiautomator2.jwproxy.command(
|
|
145
|
-
`/element/${elementId}/text`,
|
|
146
|
-
'GET',
|
|
147
|
-
{}
|
|
148
|
-
)
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* @this {AndroidUiautomator2Driver}
|
|
154
|
-
* @param {string} element
|
|
155
|
-
* @returns {Promise<void>}
|
|
156
|
-
*/
|
|
157
|
-
export async function click(element) {
|
|
158
|
-
await this.uiautomator2.jwproxy.command(
|
|
159
|
-
`/element/${element}/click`,
|
|
160
|
-
'POST',
|
|
161
|
-
{element}
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* @this {AndroidUiautomator2Driver}
|
|
167
|
-
* @param {string} element
|
|
168
|
-
* @returns {Promise<string>}
|
|
169
|
-
*/
|
|
170
|
-
export async function getElementScreenshot(element) {
|
|
171
|
-
return String(
|
|
172
|
-
await this.uiautomator2.jwproxy.command(
|
|
173
|
-
`/element/${element}/screenshot`,
|
|
174
|
-
'GET',
|
|
175
|
-
{}
|
|
176
|
-
)
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @this {AndroidUiautomator2Driver}
|
|
182
|
-
* @param {string} elementId
|
|
183
|
-
* @returns {Promise<void>}
|
|
184
|
-
*/
|
|
185
|
-
export async function clear(elementId) {
|
|
186
|
-
await this.uiautomator2.jwproxy.command(
|
|
187
|
-
`/element/${elementId}/clear`,
|
|
188
|
-
'POST',
|
|
189
|
-
{
|
|
190
|
-
elementId,
|
|
191
|
-
}
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* @this {AndroidUiautomator2Driver}
|
|
197
|
-
* @param {string} elementId
|
|
198
|
-
* @returns {Promise<import('@appium/types').Rect>}
|
|
199
|
-
*/
|
|
200
|
-
export async function getElementRect(elementId) {
|
|
201
|
-
const chromedriver = /** @type {import('appium-chromedriver').default} */ (this.chromedriver);
|
|
202
|
-
if (this.isWebContext()) {
|
|
203
|
-
this.log.debug(
|
|
204
|
-
`Detected downstream chromedriver protocol: ${chromedriver.jwproxy.downstreamProtocol}`
|
|
205
|
-
);
|
|
206
|
-
if (chromedriver.jwproxy.downstreamProtocol === PROTOCOLS.MJSONWP) {
|
|
207
|
-
const [{x, y}, {width, height}] =
|
|
208
|
-
/** @type {[import('@appium/types').Position, import('@appium/types').Size]} */ (
|
|
209
|
-
await B.all([
|
|
210
|
-
chromedriver.jwproxy.command(`/element/${elementId}/location`, 'GET'),
|
|
211
|
-
chromedriver.jwproxy.command(`/element/${elementId}/size`, 'GET'),
|
|
212
|
-
])
|
|
213
|
-
);
|
|
214
|
-
return {x, y, width, height};
|
|
215
|
-
}
|
|
216
|
-
return /** @type {import('@appium/types').Rect} */ (
|
|
217
|
-
await chromedriver.jwproxy.command(`/element/${elementId}/rect`, 'GET')
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
return /** @type {import('@appium/types').Rect} */ (
|
|
221
|
-
await this.uiautomator2.jwproxy.command(
|
|
222
|
-
`/element/${elementId}/rect`,
|
|
223
|
-
'GET'
|
|
224
|
-
)
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Sends text to the given element by replacing its previous content
|
|
230
|
-
* @this {AndroidUiautomator2Driver}
|
|
231
|
-
* @param {string} elementId The id of the element whose content will be replaced.
|
|
232
|
-
* @param {string} text The actual text to set.
|
|
233
|
-
* @throws {Error} If there was a faulre while setting the text
|
|
234
|
-
* @returns {Promise<void>}
|
|
235
|
-
*/
|
|
236
|
-
export async function mobileReplaceElementValue(elementId, text) {
|
|
237
|
-
await this.uiautomator2.jwproxy.command(
|
|
238
|
-
`/element/${elementId}/value`,
|
|
239
|
-
'POST',
|
|
240
|
-
{
|
|
241
|
-
text,
|
|
242
|
-
replace: true,
|
|
243
|
-
}
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// #region Internal Helpers
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* @param {any} s
|
|
251
|
-
* @returns {boolean}
|
|
252
|
-
*/
|
|
253
|
-
function toBool(s) {
|
|
254
|
-
return _.isString(s) ? s.toLowerCase() === 'true' : !!s;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// #endregion
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
|
|
261
|
-
*/
|
package/lib/commands/gestures.js
DELETED
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
import {util} from 'appium/support';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import {errors} from 'appium/driver';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Performs a simple click/tap gesture
|
|
7
|
-
*
|
|
8
|
-
* @this {AndroidUiautomator2Driver}
|
|
9
|
-
* @param {string} [elementId] The id of the element to be clicked.
|
|
10
|
-
* If the element is missing then both click offset coordinates must be provided.
|
|
11
|
-
* If both the element id and offset are provided then the coordinates are parsed
|
|
12
|
-
* as relative offsets from the top left corner of the element.
|
|
13
|
-
* @param {number} [x] The x coordinate to click on.
|
|
14
|
-
* @param {number} [y] The y coordinate to click on.
|
|
15
|
-
* @returns {Promise<void>}
|
|
16
|
-
* @throws {Error} if provided options are not valid
|
|
17
|
-
*/
|
|
18
|
-
export async function mobileClickGesture(elementId, x, y) {
|
|
19
|
-
await this.uiautomator2.jwproxy.command(
|
|
20
|
-
'/appium/gestures/click',
|
|
21
|
-
'POST',
|
|
22
|
-
{
|
|
23
|
-
origin: toOrigin(elementId),
|
|
24
|
-
offset: toPoint(x, y),
|
|
25
|
-
}
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Performs a click that lasts for the given duration
|
|
31
|
-
*
|
|
32
|
-
* @this {AndroidUiautomator2Driver}
|
|
33
|
-
* @param {string} [elementId] The id of the element to be clicked.
|
|
34
|
-
* If the element is missing then both click offset coordinates must be provided.
|
|
35
|
-
* If both the element id and offset are provided then the coordinates are parsed
|
|
36
|
-
* as relative offsets from the top left corner of the element.
|
|
37
|
-
* @param {number} [x] The x coordinate to click on.
|
|
38
|
-
* @param {number} [y] The y coordinate to click on.
|
|
39
|
-
* @param {number} [duration] Click duration in milliseconds. The value must not be negative.
|
|
40
|
-
* Default is 500.
|
|
41
|
-
* @returns {Promise<void>}
|
|
42
|
-
* @throws {Error} if provided options are not valid
|
|
43
|
-
*/
|
|
44
|
-
export async function mobileLongClickGesture(elementId, x, y, duration) {
|
|
45
|
-
await this.uiautomator2.jwproxy.command(
|
|
46
|
-
'/appium/gestures/long_click',
|
|
47
|
-
'POST',
|
|
48
|
-
{
|
|
49
|
-
origin: toOrigin(elementId),
|
|
50
|
-
offset: toPoint(x, y),
|
|
51
|
-
duration,
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Performs a click that lasts for the given duration
|
|
58
|
-
* @this {AndroidUiautomator2Driver}
|
|
59
|
-
* @param {string} [elementId] The id of the element to be clicked.
|
|
60
|
-
* If the element is missing then both click offset coordinates must be provided.
|
|
61
|
-
* If both the element id and offset are provided then the coordinates are parsed
|
|
62
|
-
* as relative offsets from the top left corner of the element.
|
|
63
|
-
* @param {number} [x] The x coordinate to click on.
|
|
64
|
-
* @param {number} [y] The y coordinate to click on.
|
|
65
|
-
* @returns {Promise<void>}
|
|
66
|
-
* @throws {Error} if provided options are not valid
|
|
67
|
-
*/
|
|
68
|
-
export async function mobileDoubleClickGesture(elementId, x, y) {
|
|
69
|
-
await this.uiautomator2.jwproxy.command(
|
|
70
|
-
'/appium/gestures/double_click',
|
|
71
|
-
'POST',
|
|
72
|
-
{
|
|
73
|
-
origin: toOrigin(elementId),
|
|
74
|
-
offset: toPoint(x, y),
|
|
75
|
-
}
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Drags this object to the specified location.
|
|
81
|
-
* @this {AndroidUiautomator2Driver}
|
|
82
|
-
* @param {string} [elementId] The id of the element to be dragged.
|
|
83
|
-
* If the element id is missing then the start coordinates must be provided.
|
|
84
|
-
* If both the element id and the start coordinates are provided then these
|
|
85
|
-
* coordinates are considered as offsets from the top left element corner.
|
|
86
|
-
* @param {number} [startX] The x coordinate where the dragging starts
|
|
87
|
-
* @param {number} [startY] The y coordinate where the dragging starts
|
|
88
|
-
* @param {number} [endX] The x coordinate where the dragging ends
|
|
89
|
-
* @param {number} [endY] The y coordinate where the dragging ends
|
|
90
|
-
* @param {number} [speed] The speed at which to perform this gesture in pixels per second.
|
|
91
|
-
* The value must not be negative.
|
|
92
|
-
* Default is 2500 * displayDensity.
|
|
93
|
-
* @returns {Promise<void>}
|
|
94
|
-
* @throws {Error} if provided options are not valid
|
|
95
|
-
*/
|
|
96
|
-
export async function mobileDragGesture(
|
|
97
|
-
elementId,
|
|
98
|
-
startX,
|
|
99
|
-
startY,
|
|
100
|
-
endX,
|
|
101
|
-
endY,
|
|
102
|
-
speed,
|
|
103
|
-
) {
|
|
104
|
-
await this.uiautomator2.jwproxy.command(
|
|
105
|
-
'/appium/gestures/drag',
|
|
106
|
-
'POST',
|
|
107
|
-
{
|
|
108
|
-
origin: toOrigin(elementId),
|
|
109
|
-
start: toPoint(startX, startY),
|
|
110
|
-
end: toPoint(endX, endY),
|
|
111
|
-
speed,
|
|
112
|
-
}
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Drags to the specified location.
|
|
118
|
-
*
|
|
119
|
-
* @throws {Error} if provided options are not valid
|
|
120
|
-
* @this {AndroidUiautomator2Driver}
|
|
121
|
-
* @param {string} direction Direction of the fling.
|
|
122
|
-
* Acceptable values are: `up`, `down`, `left` and `right` (case insensitive).
|
|
123
|
-
* @param {string} [elementId] The id of the element to be flinged.
|
|
124
|
-
* If the element id is missing then fling bounding area must be provided.
|
|
125
|
-
* If both the element id and the fling bounding area are provided then this
|
|
126
|
-
* area is effectively ignored.
|
|
127
|
-
* @param {number} [left] The left coordinate of the fling bounding area.
|
|
128
|
-
* @param {number} [top] The top coordinate of the fling bounding area.
|
|
129
|
-
* @param {number} [width] The width of the fling bounding area.
|
|
130
|
-
* @param {number} [height] The height of the fling bounding area.
|
|
131
|
-
* @param {number} [speed] The speed at which to perform this gesture in pixels per second.
|
|
132
|
-
* The value must be greater than the minimum fling velocity for the given view (50 by default).
|
|
133
|
-
* Default is 7500 * displayDensity.
|
|
134
|
-
* @returns {Promise<boolean>} True if the object can still scroll in the given direction.
|
|
135
|
-
*/
|
|
136
|
-
export async function mobileFlingGesture(
|
|
137
|
-
direction,
|
|
138
|
-
elementId,
|
|
139
|
-
left,
|
|
140
|
-
top,
|
|
141
|
-
width,
|
|
142
|
-
height,
|
|
143
|
-
speed,
|
|
144
|
-
) {
|
|
145
|
-
return /** @type {boolean} */ (
|
|
146
|
-
await this.uiautomator2.jwproxy.command(
|
|
147
|
-
'/appium/gestures/fling',
|
|
148
|
-
'POST',
|
|
149
|
-
{
|
|
150
|
-
origin: toOrigin(elementId),
|
|
151
|
-
area: toRect(left, top, width, height),
|
|
152
|
-
direction,
|
|
153
|
-
speed,
|
|
154
|
-
}
|
|
155
|
-
)
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Performs a pinch close gesture.
|
|
161
|
-
* @this {AndroidUiautomator2Driver}
|
|
162
|
-
* @param {number} percent The size of the pinch as a percentage of the pinch area size.
|
|
163
|
-
* Valid values must be float numbers in range 0..1, where 1.0 is 100%
|
|
164
|
-
* @param {string} [elementId] The id of the element to be pinched.
|
|
165
|
-
* If the element id is missing then pinch bounding area must be provided.
|
|
166
|
-
* If both the element id and the pinch bounding area are provided then the
|
|
167
|
-
* area is effectively ignored.
|
|
168
|
-
* @param {number} [left] The left coordinate of the pinch bounding area.
|
|
169
|
-
* @param {number} [top] The top coordinate of the pinch bounding area.
|
|
170
|
-
* @param {number} [width] The width of the pinch bounding area.
|
|
171
|
-
* @param {number} [height] The height of the pinch bounding area.
|
|
172
|
-
* @param {number} [speed] The speed at which to perform this gesture in pixels per second.
|
|
173
|
-
* The value must not be negative.
|
|
174
|
-
* Default is 2500 * displayDensity.
|
|
175
|
-
* @returns {Promise<void>}
|
|
176
|
-
* @throws {Error} if provided options are not valid
|
|
177
|
-
*/
|
|
178
|
-
export async function mobilePinchCloseGesture(
|
|
179
|
-
percent,
|
|
180
|
-
elementId,
|
|
181
|
-
left,
|
|
182
|
-
top,
|
|
183
|
-
width,
|
|
184
|
-
height,
|
|
185
|
-
speed,
|
|
186
|
-
) {
|
|
187
|
-
await this.uiautomator2.jwproxy.command(
|
|
188
|
-
'/appium/gestures/pinch_close',
|
|
189
|
-
'POST',
|
|
190
|
-
{
|
|
191
|
-
origin: toOrigin(elementId),
|
|
192
|
-
area: toRect(left, top, width, height),
|
|
193
|
-
percent,
|
|
194
|
-
speed,
|
|
195
|
-
}
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Performs a pinch open gesture.
|
|
201
|
-
* @this {AndroidUiautomator2Driver}
|
|
202
|
-
* @param {number} percent The size of the pinch as a percentage of the pinch area size.
|
|
203
|
-
* Valid values must be float numbers in range 0..1, where 1.0 is 100%
|
|
204
|
-
* @param {string} [elementId] The id of the element to be pinched.
|
|
205
|
-
* If the element id is missing then pinch bounding area must be provided.
|
|
206
|
-
* If both the element id and the pinch bounding area are provided then the
|
|
207
|
-
* area is effectively ignored.
|
|
208
|
-
* @param {number} [left] The left coordinate of the pinch bounding area.
|
|
209
|
-
* @param {number} [top] The top coordinate of the pinch bounding area.
|
|
210
|
-
* @param {number} [width] The width of the pinch bounding area.
|
|
211
|
-
* @param {number} [height] The height of the pinch bounding area.
|
|
212
|
-
* @param {number} [speed] The speed at which to perform this gesture in pixels per second.
|
|
213
|
-
* The value must not be negative.
|
|
214
|
-
* Default is 2500 * displayDensity.
|
|
215
|
-
* @returns {Promise<void>}
|
|
216
|
-
* @throws {Error} if provided options are not valid
|
|
217
|
-
*/
|
|
218
|
-
export async function mobilePinchOpenGesture(
|
|
219
|
-
percent,
|
|
220
|
-
elementId,
|
|
221
|
-
left,
|
|
222
|
-
top,
|
|
223
|
-
width,
|
|
224
|
-
height,
|
|
225
|
-
speed,
|
|
226
|
-
) {
|
|
227
|
-
await this.uiautomator2.jwproxy.command(
|
|
228
|
-
'/appium/gestures/pinch_open',
|
|
229
|
-
'POST',
|
|
230
|
-
{
|
|
231
|
-
origin: toOrigin(elementId),
|
|
232
|
-
area: toRect(left, top, width, height),
|
|
233
|
-
percent,
|
|
234
|
-
speed,
|
|
235
|
-
}
|
|
236
|
-
);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Performs a swipe gesture.
|
|
241
|
-
* @this {AndroidUiautomator2Driver}
|
|
242
|
-
* @param {string} direction Direction of the swipe.
|
|
243
|
-
* Acceptable values are: `up`, `down`, `left` and `right` (case insensitive).
|
|
244
|
-
* @param {number} percent The size of the swipe as a percentage of the swipe area size.
|
|
245
|
-
* Valid values must be float numbers in range 0..1, where 1.0 is 100%.
|
|
246
|
-
* @param {string} [elementId] The id of the element to be swiped.
|
|
247
|
-
* If the element id is missing then swipe bounding area must be provided.
|
|
248
|
-
* If both the element id and the swipe bounding area are provided then the
|
|
249
|
-
* area is effectively ignored.
|
|
250
|
-
* @param {number} [left] The left coordinate of the swipe bounding area.
|
|
251
|
-
* @param {number} [top] The top coordinate of the swipe bounding area.
|
|
252
|
-
* @param {number} [width] The width of the swipe bounding area.
|
|
253
|
-
* @param {number} [height] The height of the swipe bounding area.
|
|
254
|
-
* @param {number} [speed] The speed at which to perform this gesture in pixels per second.
|
|
255
|
-
* The value must not be negative.
|
|
256
|
-
* Default is 5000 * displayDensity.
|
|
257
|
-
* @returns {Promise<void>}
|
|
258
|
-
* @throws {Error} if provided options are not valid
|
|
259
|
-
*/
|
|
260
|
-
export async function mobileSwipeGesture(
|
|
261
|
-
direction,
|
|
262
|
-
percent,
|
|
263
|
-
elementId,
|
|
264
|
-
left,
|
|
265
|
-
top,
|
|
266
|
-
width,
|
|
267
|
-
height,
|
|
268
|
-
speed,
|
|
269
|
-
) {
|
|
270
|
-
await this.uiautomator2.jwproxy.command(
|
|
271
|
-
'/appium/gestures/swipe',
|
|
272
|
-
'POST',
|
|
273
|
-
{
|
|
274
|
-
origin: toOrigin(elementId),
|
|
275
|
-
area: toRect(left, top, width, height),
|
|
276
|
-
direction,
|
|
277
|
-
percent,
|
|
278
|
-
speed,
|
|
279
|
-
}
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Performs a scroll gesture.
|
|
285
|
-
*
|
|
286
|
-
* @throws {Error} if provided options are not valid
|
|
287
|
-
* @this {AndroidUiautomator2Driver}
|
|
288
|
-
* @param {string} direction Direction of the scroll.
|
|
289
|
-
* Acceptable values are: `up`, `down`, `left` and `right` (case insensitive).
|
|
290
|
-
* @param {number} percent The size of the scroll as a percentage of the scrolling area size.
|
|
291
|
-
* Valid values must be float numbers greater than zero, where 1.0 is 100%.
|
|
292
|
-
* @param {string} [elementId] The id of the element to be scrolled.
|
|
293
|
-
* If the element id is missing then scroll bounding area must be provided.
|
|
294
|
-
* If both the element id and the scroll bounding area are provided then this
|
|
295
|
-
* area is effectively ignored.
|
|
296
|
-
* @param {number} [left] The left coordinate of the scroll bounding area.
|
|
297
|
-
* @param {number} [top] The top coordinate of the scroll bounding area.
|
|
298
|
-
* @param {number} [width] The width of the scroll bounding area.
|
|
299
|
-
* @param {number} [height] The height of the scroll bounding area.
|
|
300
|
-
* @param {number} [speed] The speed at which to perform this gesture in pixels per second.
|
|
301
|
-
* The value must not be negative.
|
|
302
|
-
* Default is 5000 * displayDensity.
|
|
303
|
-
* @returns {Promise<boolean>} True if the object can still scroll in the given direction.
|
|
304
|
-
*/
|
|
305
|
-
export async function mobileScrollGesture(
|
|
306
|
-
direction,
|
|
307
|
-
percent,
|
|
308
|
-
elementId,
|
|
309
|
-
left,
|
|
310
|
-
top,
|
|
311
|
-
width,
|
|
312
|
-
height,
|
|
313
|
-
speed,
|
|
314
|
-
) {
|
|
315
|
-
return /** @type {boolean} */ (
|
|
316
|
-
await this.uiautomator2.jwproxy.command(
|
|
317
|
-
'/appium/gestures/scroll',
|
|
318
|
-
'POST',
|
|
319
|
-
{
|
|
320
|
-
origin: toOrigin(elementId),
|
|
321
|
-
area: toRect(left, top, width, height),
|
|
322
|
-
direction,
|
|
323
|
-
percent,
|
|
324
|
-
speed,
|
|
325
|
-
}
|
|
326
|
-
)
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Scrolls the given scrollable element `elementId` until `elementToId`
|
|
332
|
-
* becomes visible. This function returns immediately if the `elementToId`
|
|
333
|
-
* is already visible in the view port. Otherwise it would scroll
|
|
334
|
-
* to the very beginning of the scrollable control and tries to reach the destination element
|
|
335
|
-
* by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
|
|
336
|
-
* is detected automatically.
|
|
337
|
-
* @this {AndroidUiautomator2Driver}
|
|
338
|
-
* @param {string} elementId The identifier of the scrollable element, which is going to be scrolled.
|
|
339
|
-
* It is required this element is a valid scrollable container and it was located
|
|
340
|
-
* by `-android uiautomator` strategy.
|
|
341
|
-
* @param {string} elementToId The identifier of the item, which belongs to the scrollable element above,
|
|
342
|
-
* and which should become visible after the scrolling operation is finished.
|
|
343
|
-
* It is required this element was located by `-android uiautomator` strategy.
|
|
344
|
-
* @returns {Promise<void>}
|
|
345
|
-
* @throws {Error} if the scrolling operation cannot be performed
|
|
346
|
-
*/
|
|
347
|
-
export async function mobileScrollBackTo(elementId, elementToId) {
|
|
348
|
-
if (!elementId || !elementToId) {
|
|
349
|
-
throw new errors.InvalidArgumentError(
|
|
350
|
-
`Both elementId and elementToId arguments must be provided`
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
await this.uiautomator2.jwproxy.command(
|
|
354
|
-
`/appium/element/${util.unwrapElement(elementId)}/scroll_to/${util.unwrapElement(
|
|
355
|
-
elementToId
|
|
356
|
-
)}`,
|
|
357
|
-
'POST',
|
|
358
|
-
{}
|
|
359
|
-
);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Scrolls the given scrollable element until the element identified
|
|
364
|
-
* by `strategy` and `selector` becomes visible. This function returns immediately if the
|
|
365
|
-
* destination element is already visible in the view port. Otherwise it would scroll
|
|
366
|
-
* to the very beginning of the scrollable control and tries to reach the destination element
|
|
367
|
-
* by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
|
|
368
|
-
* is detected automatically.
|
|
369
|
-
*
|
|
370
|
-
* @this {AndroidUiautomator2Driver}
|
|
371
|
-
* @param {string} strategy The following strategies are supported:
|
|
372
|
-
* - `accessibility id` (UiSelector().description)
|
|
373
|
-
* - `class name` (UiSelector().className)
|
|
374
|
-
* - `-android uiautomator` (UiSelector)
|
|
375
|
-
* @param {string} selector The corresponding lookup value for the given strategy.
|
|
376
|
-
* @param {string} [elementId] The identifier of an element. It is required this element is a valid scrollable container
|
|
377
|
-
* and it was located by `-android uiautomator` strategy.
|
|
378
|
-
* If this property is not provided then the first currently available scrollable view
|
|
379
|
-
* is selected for the interaction.
|
|
380
|
-
* @param {number} [maxSwipes] The maximum number of swipes to perform on the target scrollable view in order to reach
|
|
381
|
-
* the destination element. In case this value is unset then it would be retrieved from the
|
|
382
|
-
* scrollable element itself (via `getMaxSearchSwipes()` property).
|
|
383
|
-
* @returns {Promise<void>}
|
|
384
|
-
* @throws {Error} if the scrolling operation cannot be performed
|
|
385
|
-
*/
|
|
386
|
-
export async function mobileScroll(
|
|
387
|
-
strategy,
|
|
388
|
-
selector,
|
|
389
|
-
elementId,
|
|
390
|
-
maxSwipes,
|
|
391
|
-
) {
|
|
392
|
-
if (!strategy || !selector) {
|
|
393
|
-
throw new errors.InvalidArgumentError(
|
|
394
|
-
`Both strategy and selector arguments must be provided`
|
|
395
|
-
);
|
|
396
|
-
}
|
|
397
|
-
await this.uiautomator2.jwproxy.command(
|
|
398
|
-
'/gestures/scroll_to',
|
|
399
|
-
'POST',
|
|
400
|
-
{
|
|
401
|
-
origin: toOrigin(elementId),
|
|
402
|
-
params: {strategy, selector, maxSwipes},
|
|
403
|
-
}
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// #region Internal Helpers
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
*
|
|
411
|
-
* @param {import('@appium/types').Element|string} [element]
|
|
412
|
-
* @returns {import('@appium/types').Element|undefined}
|
|
413
|
-
*/
|
|
414
|
-
function toOrigin(element) {
|
|
415
|
-
return element ? util.wrapElement(util.unwrapElement(element)) : undefined;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
*
|
|
420
|
-
* @param {number} [x]
|
|
421
|
-
* @param {number} [y]
|
|
422
|
-
* @returns {Partial<import('@appium/types').Position>|undefined}
|
|
423
|
-
*/
|
|
424
|
-
function toPoint(x, y) {
|
|
425
|
-
return _.isFinite(x) && _.isFinite(y) ? {x, y} : undefined;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
*
|
|
430
|
-
* @param {number} [left]
|
|
431
|
-
* @param {number} [top]
|
|
432
|
-
* @param {number} [width]
|
|
433
|
-
* @param {number} [height]
|
|
434
|
-
* @returns {Partial<import('./types').RelativeRect>|undefined}
|
|
435
|
-
*/
|
|
436
|
-
function toRect(left, top, width, height) {
|
|
437
|
-
return [left, top, width, height].some((v) => !_.isFinite(v))
|
|
438
|
-
? undefined
|
|
439
|
-
: {left, top, width, height};
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
// #endregion
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
|
|
446
|
-
*/
|