appium-uiautomator2-driver 2.29.10 → 2.30.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.
- package/CHANGELOG.md +14 -0
- package/build/index.d.ts +4 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +8 -16
- package/build/index.js.map +1 -0
- package/build/lib/commands/actions.d.ts +2 -0
- package/build/lib/commands/actions.d.ts.map +1 -0
- package/build/lib/commands/actions.js +67 -65
- package/build/lib/commands/actions.js.map +1 -1
- package/build/lib/commands/alert.d.ts +2 -0
- package/build/lib/commands/alert.d.ts.map +1 -0
- package/build/lib/commands/alert.js +28 -29
- package/build/lib/commands/alert.js.map +1 -1
- package/build/lib/commands/app-strings.d.ts +3 -0
- package/build/lib/commands/app-strings.d.ts.map +1 -0
- package/build/lib/commands/app-strings.js +86 -58
- package/build/lib/commands/app-strings.js.map +1 -1
- package/build/lib/commands/battery.d.ts +2 -0
- package/build/lib/commands/battery.d.ts.map +1 -0
- package/build/lib/commands/battery.js +26 -18
- package/build/lib/commands/battery.js.map +1 -1
- package/build/lib/commands/element.d.ts +2 -0
- package/build/lib/commands/element.d.ts.map +1 -0
- package/build/lib/commands/element.js +140 -162
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/find.d.ts +2 -0
- package/build/lib/commands/find.d.ts.map +1 -0
- package/build/lib/commands/find.js +39 -27
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/general.d.ts +4 -0
- package/build/lib/commands/general.d.ts.map +1 -0
- package/build/lib/commands/general.js +217 -216
- package/build/lib/commands/general.js.map +1 -1
- package/build/lib/commands/gestures.d.ts +2 -0
- package/build/lib/commands/gestures.d.ts.map +1 -0
- package/build/lib/commands/gestures.js +206 -194
- package/build/lib/commands/gestures.js.map +1 -1
- package/build/lib/commands/index.d.ts +2 -0
- package/build/lib/commands/index.d.ts.map +1 -0
- package/build/lib/commands/index.js +13 -23
- package/build/lib/commands/index.js.map +1 -1
- package/build/lib/commands/mixins.d.ts +84 -0
- package/build/lib/commands/mixins.d.ts.map +1 -0
- package/build/lib/commands/mixins.js +23 -0
- package/build/lib/commands/mixins.js.map +1 -0
- package/build/lib/commands/screenshot.d.ts +2 -0
- package/build/lib/commands/screenshot.d.ts.map +1 -0
- package/build/lib/commands/screenshot.js +77 -63
- package/build/lib/commands/screenshot.js.map +1 -1
- package/build/lib/commands/touch.d.ts +2 -0
- package/build/lib/commands/touch.d.ts.map +1 -0
- package/build/lib/commands/touch.js +48 -39
- package/build/lib/commands/touch.js.map +1 -1
- package/build/lib/commands/types.d.ts +452 -0
- package/build/lib/commands/types.d.ts.map +1 -0
- package/build/lib/commands/types.js +3 -0
- package/build/lib/commands/types.js.map +1 -0
- package/build/lib/commands/viewport.d.ts +2 -0
- package/build/lib/commands/viewport.d.ts.map +1 -0
- package/build/lib/commands/viewport.js +37 -37
- package/build/lib/commands/viewport.js.map +1 -1
- package/build/lib/constraints.d.ts +334 -0
- package/build/lib/constraints.d.ts.map +1 -0
- package/build/lib/constraints.js +51 -0
- package/build/lib/constraints.js.map +1 -0
- package/build/lib/css-converter.d.ts +45 -0
- package/build/lib/css-converter.d.ts.map +1 -0
- package/build/lib/css-converter.js +272 -176
- package/build/lib/css-converter.js.map +1 -1
- package/build/lib/driver.d.ts +912 -0
- package/build/lib/driver.d.ts.map +1 -0
- package/build/lib/driver.js +738 -483
- package/build/lib/driver.js.map +1 -1
- package/build/lib/execute-method-map.d.ts +477 -0
- package/build/lib/execute-method-map.d.ts.map +1 -0
- package/build/lib/execute-method-map.js +542 -0
- package/build/lib/execute-method-map.js.map +1 -0
- package/build/lib/extensions.d.ts +3 -0
- package/build/lib/extensions.d.ts.map +1 -0
- package/build/lib/extensions.js +3 -7
- package/build/lib/extensions.js.map +1 -1
- package/build/lib/helpers.d.ts +7 -0
- package/build/lib/helpers.d.ts.map +1 -0
- package/build/lib/helpers.js +36 -30
- package/build/lib/helpers.js.map +1 -1
- package/build/lib/logger.d.ts +3 -0
- package/build/lib/logger.d.ts.map +1 -0
- package/build/lib/logger.js +5 -11
- package/build/lib/logger.js.map +1 -1
- package/build/lib/method-map.d.ts +389 -0
- package/build/lib/method-map.d.ts.map +1 -0
- package/build/lib/method-map.js +11 -18
- package/build/lib/method-map.js.map +1 -1
- package/build/lib/types.d.ts +45 -0
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/types.js +3 -0
- package/build/lib/types.js.map +1 -0
- package/build/lib/uiautomator2.d.ts +45 -0
- package/build/lib/uiautomator2.d.ts.map +1 -0
- package/build/lib/uiautomator2.js +334 -297
- package/build/lib/uiautomator2.js.map +1 -1
- package/build/lib/utils.d.ts +10 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +23 -16
- package/build/lib/utils.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -0
- package/index.js +5 -3
- package/lib/commands/actions.js +115 -101
- package/lib/commands/alert.js +36 -44
- package/lib/commands/app-strings.js +79 -58
- package/lib/commands/battery.js +27 -28
- package/lib/commands/element.js +231 -134
- package/lib/commands/find.js +40 -21
- package/lib/commands/general.js +271 -336
- package/lib/commands/gestures.js +252 -366
- package/lib/commands/index.js +11 -31
- package/lib/commands/mixins.ts +167 -0
- package/lib/commands/screenshot.js +80 -76
- package/lib/commands/touch.js +64 -31
- package/lib/commands/types.ts +473 -0
- package/lib/commands/viewport.js +43 -31
- package/lib/constraints.ts +53 -0
- package/lib/css-converter.js +9 -1
- package/lib/{driver.js → driver.ts} +383 -225
- package/lib/execute-method-map.ts +573 -0
- package/lib/method-map.ts +11 -0
- package/lib/types.ts +59 -0
- package/lib/uiautomator2.js +21 -2
- package/lib/utils.js +2 -2
- package/npm-shrinkwrap.json +396 -528
- package/package.json +96 -70
- package/build/lib/desired-caps.js +0 -72
- package/build/lib/desired-caps.js.map +0 -1
- package/lib/desired-caps.js +0 -70
- package/lib/method-map.js +0 -11
package/lib/commands/gestures.js
CHANGED
|
@@ -1,397 +1,283 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
import {mixin} from './mixins';
|
|
3
|
+
import {util} from 'appium/support';
|
|
2
4
|
import _ from 'lodash';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const commands = {};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function toOrigin (element) {
|
|
9
|
-
return element ? util.wrapElement(util.unwrapElement(element)) : undefined;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function toPoint (x, y) {
|
|
13
|
-
return _.isFinite(x) && _.isFinite(y) ? {x, y} : undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function toRect (left, top, width, height) {
|
|
17
|
-
return [left, top, width, height].some((v) => !_.isFinite(v))
|
|
18
|
-
? undefined
|
|
19
|
-
: {left, top, width, height};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @typedef {Object} ClickOptions
|
|
24
|
-
* @property {?string} elementId - The id of the element to be clicked.
|
|
25
|
-
* If the element is missing then both click offset coordinates must be provided.
|
|
26
|
-
* If both the element id and offset are provided then the coordinates
|
|
27
|
-
* are parsed as relative offsets from the top left corner of the element.
|
|
28
|
-
* @property {?number} x - The x coordinate to click on
|
|
29
|
-
* @property {?number} y - The y coordinate to click on
|
|
30
|
-
*/
|
|
5
|
+
import {errors} from 'appium/driver';
|
|
31
6
|
|
|
32
7
|
/**
|
|
33
|
-
* Performs a simple click/tap gesture
|
|
34
8
|
*
|
|
35
|
-
* @param {
|
|
36
|
-
* @
|
|
37
|
-
*/
|
|
38
|
-
commands.mobileClickGesture = async function mobileClickGesture (opts = {}) {
|
|
39
|
-
const {
|
|
40
|
-
elementId,
|
|
41
|
-
x, y,
|
|
42
|
-
} = opts;
|
|
43
|
-
return await this.uiautomator2.jwproxy.command('/appium/gestures/click', 'POST', {
|
|
44
|
-
origin: toOrigin(elementId),
|
|
45
|
-
offset: toPoint(x, y),
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @typedef {Object} LongClickOptions
|
|
51
|
-
* @property {?string} elementId - The id of the element to be clicked.
|
|
52
|
-
* If the element is missing then both click offset coordinates must be provided.
|
|
53
|
-
* If both the element id and offset are provided then the coordinates
|
|
54
|
-
* are parsed as relative offsets from the top left corner of the element.
|
|
55
|
-
* @property {?number} x - The x coordinate to click on
|
|
56
|
-
* @property {?number} y - The y coordinate to click on
|
|
57
|
-
* @property {?number} duration [500] - Click duration in milliseconds.
|
|
58
|
-
* The value must not be negative
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Performs a click that lasts for the given duration
|
|
63
|
-
*
|
|
64
|
-
* @param {?LongClickOptions} opts
|
|
65
|
-
* @throws {Error} if provided options are not valid
|
|
66
|
-
*/
|
|
67
|
-
commands.mobileLongClickGesture = async function mobileLongClickGesture (opts = {}) {
|
|
68
|
-
const {
|
|
69
|
-
elementId,
|
|
70
|
-
x, y,
|
|
71
|
-
duration,
|
|
72
|
-
} = opts;
|
|
73
|
-
return await this.uiautomator2.jwproxy.command('/appium/gestures/long_click', 'POST', {
|
|
74
|
-
origin: toOrigin(elementId),
|
|
75
|
-
offset: toPoint(x, y),
|
|
76
|
-
duration,
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @typedef {Object} DoubleClickOptions
|
|
82
|
-
* @property {?string} elementId - The id of the element to be double clicked.
|
|
83
|
-
* If the element is missing then both click offset coordinates must be provided.
|
|
84
|
-
* If both the element id and offset are provided then the coordinates
|
|
85
|
-
* are parsed as relative offsets from the top left corner of the element.
|
|
86
|
-
* @property {?number} x - The x coordinate to double click on
|
|
87
|
-
* @property {?number} y - The y coordinate to double click on
|
|
9
|
+
* @param {import('@appium/types').Element|string} [element]
|
|
10
|
+
* @returns {import('@appium/types').Element|undefined}
|
|
88
11
|
*/
|
|
12
|
+
function toOrigin(element) {
|
|
13
|
+
return element ? util.wrapElement(util.unwrapElement(element)) : undefined;
|
|
14
|
+
}
|
|
89
15
|
|
|
90
16
|
/**
|
|
91
|
-
* Performs a click that lasts for the given duration
|
|
92
17
|
*
|
|
93
|
-
* @param {
|
|
94
|
-
* @
|
|
95
|
-
|
|
96
|
-
commands.mobileDoubleClickGesture = async function mobileDoubleClickGesture (opts = {}) {
|
|
97
|
-
const {
|
|
98
|
-
elementId,
|
|
99
|
-
x, y,
|
|
100
|
-
} = opts;
|
|
101
|
-
return await this.uiautomator2.jwproxy.command('/appium/gestures/double_click', 'POST', {
|
|
102
|
-
origin: toOrigin(elementId),
|
|
103
|
-
offset: toPoint(x, y),
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @typedef {Object} DragOptions
|
|
109
|
-
* @property {?string} elementId - The id of the element to be dragged.
|
|
110
|
-
* If the element id is missing then the start coordinates must be provided.
|
|
111
|
-
* If both the element id and the start coordinates are provided then these
|
|
112
|
-
* coordinates are considered as offsets from the top left element corner.
|
|
113
|
-
* @property {?number} startX - The x coordinate where the dragging starts
|
|
114
|
-
* @property {?number} startY - The y coordinate where the dragging starts
|
|
115
|
-
* @property {!number} endX - The x coordinate where the dragging ends
|
|
116
|
-
* @property {!number} endY - The y coordinate where the dragging ends
|
|
117
|
-
* @property {?number} speed [2500 * displayDensity] - The speed at which to perform
|
|
118
|
-
* this gesture in pixels per second. The value must not be negative
|
|
18
|
+
* @param {number} [x]
|
|
19
|
+
* @param {number} [y]
|
|
20
|
+
* @returns {Partial<import('@appium/types').Position>|undefined}
|
|
119
21
|
*/
|
|
22
|
+
function toPoint(x, y) {
|
|
23
|
+
return _.isFinite(x) && _.isFinite(y) ? {x, y} : undefined;
|
|
24
|
+
}
|
|
120
25
|
|
|
121
26
|
/**
|
|
122
|
-
* Drags this object to the specified location.
|
|
123
27
|
*
|
|
124
|
-
* @param {
|
|
125
|
-
* @
|
|
28
|
+
* @param {number} [left]
|
|
29
|
+
* @param {number} [top]
|
|
30
|
+
* @param {number} [width]
|
|
31
|
+
* @param {number} [height]
|
|
32
|
+
* @returns {Partial<import('./types').RelativeRect>|undefined}
|
|
126
33
|
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
speed,
|
|
133
|
-
} = opts;
|
|
134
|
-
return await this.uiautomator2.jwproxy.command('/appium/gestures/drag', 'POST', {
|
|
135
|
-
origin: toOrigin(elementId),
|
|
136
|
-
start: toPoint(startX, startY),
|
|
137
|
-
end: toPoint(endX, endY),
|
|
138
|
-
speed,
|
|
139
|
-
});
|
|
140
|
-
};
|
|
34
|
+
function toRect(left, top, width, height) {
|
|
35
|
+
return [left, top, width, height].some((v) => !_.isFinite(v))
|
|
36
|
+
? undefined
|
|
37
|
+
: {left, top, width, height};
|
|
38
|
+
}
|
|
141
39
|
|
|
142
40
|
/**
|
|
143
|
-
* @
|
|
144
|
-
* @
|
|
145
|
-
* If the element id is missing then fling bounding area must be provided.
|
|
146
|
-
* If both the element id and the fling bounding area are provided then this
|
|
147
|
-
* area is effectively ignored.
|
|
148
|
-
* @property {?number} left - The left coordinate of the fling bounding area
|
|
149
|
-
* @property {?number} top - The top coordinate of the fling bounding area
|
|
150
|
-
* @property {?number} width - The width of the fling bounding area
|
|
151
|
-
* @property {?number} height - The height of the fling bounding area
|
|
152
|
-
* @property {!string} direction - Direction of the fling.
|
|
153
|
-
* Acceptable values are: `up`, `down`, `left` and `right` (case insensitive)
|
|
154
|
-
* @property {?number} speed [7500 * displayDensity] - The speed at which to perform this
|
|
155
|
-
* gesture in pixels per second. The value must be greater than the minimum fling
|
|
156
|
-
* velocity for the given view (50 by default)
|
|
41
|
+
* @type {import('./mixins').UIA2GesturesMixin}
|
|
42
|
+
* @satisfies {import('@appium/types').ExternalDriver}
|
|
157
43
|
*/
|
|
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 /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
53
|
+
'/appium/gestures/click',
|
|
54
|
+
'POST',
|
|
55
|
+
{
|
|
56
|
+
origin: toOrigin(elementId),
|
|
57
|
+
offset: toPoint(x, y),
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
},
|
|
158
61
|
|
|
159
|
-
/**
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
direction,
|
|
177
|
-
speed,
|
|
178
|
-
});
|
|
179
|
-
};
|
|
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 /** @type {UiAutomator2Server} */ (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
|
+
},
|
|
180
79
|
|
|
181
|
-
/**
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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 /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
88
|
+
'/appium/gestures/double_click',
|
|
89
|
+
'POST',
|
|
90
|
+
{
|
|
91
|
+
origin: toOrigin(elementId),
|
|
92
|
+
offset: toPoint(x, y),
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
},
|
|
196
96
|
|
|
197
|
-
/**
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
});
|
|
216
|
-
};
|
|
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;
|
|
104
|
+
await /** @type {UiAutomator2Server} */ (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
|
+
},
|
|
217
115
|
|
|
218
|
-
/**
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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 /** @type {UiAutomator2Server} */ (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
|
+
},
|
|
238
137
|
|
|
239
|
-
/**
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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 /** @type {UiAutomator2Server} */ (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
|
+
},
|
|
256
156
|
|
|
257
|
-
/**
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
percent,
|
|
276
|
-
speed,
|
|
277
|
-
});
|
|
278
|
-
};
|
|
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 /** @type {UiAutomator2Server} */ (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
|
+
},
|
|
279
175
|
|
|
280
|
-
/**
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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;
|
|
183
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
184
|
+
'/appium/gestures/swipe',
|
|
185
|
+
'POST',
|
|
186
|
+
{
|
|
187
|
+
origin: toOrigin(elementId),
|
|
188
|
+
area: toRect(left, top, width, height),
|
|
189
|
+
direction,
|
|
190
|
+
percent,
|
|
191
|
+
speed,
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
},
|
|
297
195
|
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
};
|
|
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 /** @type {UiAutomator2Server} */ (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
|
+
)
|
|
216
|
+
);
|
|
217
|
+
},
|
|
321
218
|
|
|
322
|
-
/**
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
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 /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
237
|
+
`/appium/element/${util.unwrapElement(elementId)}/scroll_to/${util.unwrapElement(
|
|
238
|
+
elementToId
|
|
239
|
+
)}`,
|
|
240
|
+
'POST',
|
|
241
|
+
{}
|
|
242
|
+
);
|
|
243
|
+
},
|
|
333
244
|
|
|
334
|
-
/**
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
+
);
|
|
267
|
+
}
|
|
268
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
269
|
+
'/touch/scroll',
|
|
270
|
+
'POST',
|
|
271
|
+
{
|
|
272
|
+
origin: toOrigin(elementId || element),
|
|
273
|
+
params: {strategy, selector, maxSwipes},
|
|
274
|
+
}
|
|
275
|
+
);
|
|
276
|
+
},
|
|
352
277
|
};
|
|
353
278
|
|
|
354
|
-
|
|
355
|
-
* @typedef {Object} ScrollOpts
|
|
356
|
-
* @property {?string} elementId The identifier of an element. It is required this element
|
|
357
|
-
* is a valid scrollable container and it was located by `-android uiautomator`
|
|
358
|
-
* strategy. If this property is not provided then the first currently available scrollable view
|
|
359
|
-
* is selected for the interaction.
|
|
360
|
-
* @property {!string} strategy The following strategies are supported:
|
|
361
|
-
* - `accessibility id` (UiSelector().description)
|
|
362
|
-
* - `class name` (UiSelector().className)
|
|
363
|
-
* - `-android uiautomator` (UiSelector)
|
|
364
|
-
* @property {!string} selector The corresponding lookup value for the given
|
|
365
|
-
* strategy.
|
|
366
|
-
* @property {?number} maxSwipes The maximum number of swipes to perform
|
|
367
|
-
* on the target scrollable view in order to reach the destination element.
|
|
368
|
-
* In case this value is unset then it would be retrieved from the scrollable
|
|
369
|
-
* element itself (vua `getMaxSearchSwipes()` property).
|
|
370
|
-
*/
|
|
279
|
+
mixin(GesturesMixin);
|
|
371
280
|
|
|
372
281
|
/**
|
|
373
|
-
*
|
|
374
|
-
* by `strategy` and `selector` becomes visible. This function returns immediately if the
|
|
375
|
-
* destination element is already visible in the view port. Otherwise it would scroll
|
|
376
|
-
* to the very beginning of the scrollable control and tries to reach the destination element
|
|
377
|
-
* by scrolling its parent to the end step by step. The scroll direction (vertical or horizontal)
|
|
378
|
-
* is detected automatically.
|
|
379
|
-
*
|
|
380
|
-
* @param {ScrollOpts} opts
|
|
381
|
-
* @throws {Error} if the scrolling operation cannot be performed
|
|
282
|
+
* @typedef {import('../uiautomator2').UiAutomator2Server} UiAutomator2Server
|
|
382
283
|
*/
|
|
383
|
-
commands.mobileScroll = async function (opts = {}) {
|
|
384
|
-
const {
|
|
385
|
-
element, elementId, // `element` is deprecated, use `elementId` instead
|
|
386
|
-
strategy, selector, maxSwipes
|
|
387
|
-
} = opts;
|
|
388
|
-
if (!strategy || !selector) {
|
|
389
|
-
throw new errors.InvalidArgumentError(`Both strategy and selector arguments must be provided`);
|
|
390
|
-
}
|
|
391
|
-
return await this.uiautomator2.jwproxy.command('/touch/scroll', 'POST', {
|
|
392
|
-
origin: toOrigin(elementId || element),
|
|
393
|
-
params: {strategy, selector, maxSwipes},
|
|
394
|
-
});
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
export default commands;
|