appium-uiautomator2-driver 2.29.11 → 2.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 -15
- 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 -62
- 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 -26
- 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 -57
- 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 -16
- 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 -159
- 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 -25
- 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 +209 -215
- 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 -193
- 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 -22
- package/build/lib/commands/index.js.map +1 -1
- package/build/lib/commands/mixins.d.ts +87 -0
- package/build/lib/commands/mixins.d.ts.map +1 -0
- package/build/lib/commands/mixins.js +26 -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 -62
- 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 -38
- 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 -35
- package/build/lib/commands/viewport.js.map +1 -1
- package/build/lib/constraints.d.ts +325 -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 -175
- package/build/lib/css-converter.js.map +1 -1
- package/build/lib/driver.d.ts +904 -0
- package/build/lib/driver.d.ts.map +1 -0
- package/build/lib/driver.js +726 -485
- 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 +7 -9
- 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 -29
- 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 -10
- 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 -17
- package/build/lib/method-map.js.map +1 -1
- package/build/lib/types.d.ts +44 -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 +340 -299
- 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 +262 -336
- package/lib/commands/gestures.js +252 -366
- package/lib/commands/index.js +11 -31
- package/lib/commands/mixins.ts +169 -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} +374 -239
- package/lib/execute-method-map.ts +573 -0
- package/lib/method-map.ts +11 -0
- package/lib/types.ts +57 -0
- package/lib/uiautomator2.js +21 -2
- package/lib/utils.js +2 -2
- package/npm-shrinkwrap.json +395 -528
- package/package.json +96 -70
- package/build/lib/desired-caps.js +0 -71
- 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/element.js
CHANGED
|
@@ -1,144 +1,241 @@
|
|
|
1
|
-
|
|
2
|
-
import { util } from 'appium/support';
|
|
3
|
-
import { PROTOCOLS, W3C_ELEMENT_KEY } from 'appium/driver';
|
|
4
|
-
import { requireArgs } from '../utils';
|
|
1
|
+
// @ts-check
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
import B from 'bluebird';
|
|
4
|
+
import _ from 'lodash';
|
|
5
|
+
import {util} from 'appium/support';
|
|
6
|
+
import {PROTOCOLS, W3C_ELEMENT_KEY} from 'appium/driver';
|
|
7
|
+
import {requireArgs} from '../utils';
|
|
8
|
+
import {mixin} from './mixins';
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @param {any} s
|
|
12
|
+
* @returns {boolean}
|
|
13
|
+
*/
|
|
14
|
+
function toBool(s) {
|
|
15
|
+
return _.isString(s) ? s.toLowerCase() === 'true' : !!s;
|
|
10
16
|
}
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @type {import('./mixins').UIA2ElementMixin}
|
|
20
|
+
* @satisfies {import('@appium/types').ExternalDriver}
|
|
21
|
+
*/
|
|
22
|
+
const ElementMixin = {
|
|
23
|
+
async active() {
|
|
24
|
+
return /** @type {import('@appium/types').Element} */ (
|
|
25
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
26
|
+
'/element/active',
|
|
27
|
+
'GET'
|
|
28
|
+
)
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
async getAttribute(attribute, elementId) {
|
|
32
|
+
return String(
|
|
33
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
34
|
+
`/element/${elementId}/attribute/${attribute}`,
|
|
35
|
+
'GET',
|
|
36
|
+
{}
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
},
|
|
40
|
+
async elementDisplayed(elementId) {
|
|
41
|
+
return toBool(await this.getAttribute('displayed', elementId));
|
|
42
|
+
},
|
|
43
|
+
async elementEnabled(elementId) {
|
|
44
|
+
return toBool(await this.getAttribute('enabled', elementId));
|
|
45
|
+
},
|
|
46
|
+
async elementSelected(elementId) {
|
|
47
|
+
return toBool(await this.getAttribute('selected', elementId));
|
|
48
|
+
},
|
|
49
|
+
async getName(elementId) {
|
|
50
|
+
return /** @type {string} */ (
|
|
51
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
52
|
+
`/element/${elementId}/name`,
|
|
53
|
+
'GET',
|
|
54
|
+
{}
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
async getLocation(elementId) {
|
|
59
|
+
return /** @type {import('@appium/types').Position} */ (
|
|
60
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
61
|
+
`/element/${elementId}/location`,
|
|
62
|
+
'GET',
|
|
63
|
+
{}
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
},
|
|
67
|
+
async getSize(elementId) {
|
|
68
|
+
return /** @type {import('@appium/types').Size} */ (
|
|
69
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
70
|
+
`/element/${elementId}/size`,
|
|
71
|
+
'GET',
|
|
72
|
+
{}
|
|
73
|
+
)
|
|
74
|
+
);
|
|
75
|
+
},
|
|
76
|
+
async touchLongClick(element, x, y, duration) {
|
|
77
|
+
let params = {element, x, y, duration};
|
|
78
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
79
|
+
`/touch/longclick`,
|
|
80
|
+
'POST',
|
|
81
|
+
{params}
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
async touchDown(element, x, y) {
|
|
85
|
+
let params = {element, x, y};
|
|
86
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
87
|
+
`/touch/down`,
|
|
88
|
+
'POST',
|
|
89
|
+
{params}
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
async touchUp(element, x, y) {
|
|
93
|
+
let params = {element, x, y};
|
|
94
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
95
|
+
`/touch/up`,
|
|
96
|
+
'POST',
|
|
97
|
+
{params}
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
async touchMove(element, x, y) {
|
|
101
|
+
let params = {element, x, y};
|
|
102
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
103
|
+
`/touch/move`,
|
|
104
|
+
'POST',
|
|
105
|
+
{params}
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
async doSetElementValue(params) {
|
|
109
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
110
|
+
`/element/${params.elementId}/value`,
|
|
111
|
+
'POST',
|
|
112
|
+
params
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
async setValueImmediate(keys, elementId) {
|
|
116
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
117
|
+
`/element/${elementId}/value`,
|
|
118
|
+
'POST',
|
|
119
|
+
{
|
|
120
|
+
elementId,
|
|
121
|
+
text: _.isArray(keys) ? keys.join('') : keys,
|
|
122
|
+
replace: false,
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
},
|
|
126
|
+
async getText(elementId) {
|
|
127
|
+
return String(
|
|
128
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
129
|
+
`/element/${elementId}/text`,
|
|
130
|
+
'GET',
|
|
131
|
+
{}
|
|
132
|
+
)
|
|
133
|
+
);
|
|
134
|
+
},
|
|
135
|
+
async click(element) {
|
|
136
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
137
|
+
`/element/${element}/click`,
|
|
138
|
+
'POST',
|
|
139
|
+
{element}
|
|
140
|
+
);
|
|
141
|
+
},
|
|
142
|
+
async getElementScreenshot(element) {
|
|
143
|
+
return String(
|
|
144
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
145
|
+
`/element/${element}/screenshot`,
|
|
146
|
+
'GET',
|
|
147
|
+
{}
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
async tap(elementId = null, x = null, y = null, count = 1) {
|
|
153
|
+
const areCoordinatesDefined = util.hasValue(x) && util.hasValue(y);
|
|
154
|
+
if (!util.hasValue(elementId) && !areCoordinatesDefined) {
|
|
155
|
+
throw new Error(`Either element id to tap or both absolute coordinates should be defined`);
|
|
104
156
|
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
157
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
158
|
+
for (let i = 0; i < count; i++) {
|
|
159
|
+
if (util.hasValue(elementId) && !areCoordinatesDefined) {
|
|
160
|
+
// we are either tapping on the default location of the element
|
|
161
|
+
// or an offset from the top left corner
|
|
162
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
163
|
+
`/element/${elementId}/click`,
|
|
164
|
+
'POST'
|
|
165
|
+
);
|
|
166
|
+
} else {
|
|
167
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
168
|
+
`/appium/tap`,
|
|
169
|
+
'POST',
|
|
170
|
+
{
|
|
171
|
+
x,
|
|
172
|
+
y,
|
|
173
|
+
[W3C_ELEMENT_KEY]: elementId,
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
}
|
|
119
177
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
async clear(elementId) {
|
|
181
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
182
|
+
`/element/${elementId}/clear`,
|
|
183
|
+
'POST',
|
|
184
|
+
{
|
|
185
|
+
elementId,
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
async getElementRect(elementId) {
|
|
191
|
+
const chromedriver = /** @type {import('appium-chromedriver').default} */ (this.chromedriver);
|
|
192
|
+
if (this.isWebContext()) {
|
|
193
|
+
this.log.debug(
|
|
194
|
+
`Detected downstream chromedriver protocol: ${chromedriver.jwproxy.downstreamProtocol}`
|
|
195
|
+
);
|
|
196
|
+
if (chromedriver.jwproxy.downstreamProtocol === PROTOCOLS.MJSONWP) {
|
|
197
|
+
const [{x, y}, {width, height}] =
|
|
198
|
+
/** @type {[import('@appium/types').Position, import('@appium/types').Size]} */ (
|
|
199
|
+
await B.all([
|
|
200
|
+
chromedriver.jwproxy.command(`/element/${elementId}/location`, 'GET'),
|
|
201
|
+
chromedriver.jwproxy.command(`/element/${elementId}/size`, 'GET'),
|
|
202
|
+
])
|
|
203
|
+
);
|
|
204
|
+
return {x, y, width, height};
|
|
205
|
+
}
|
|
206
|
+
return /** @type {import('@appium/types').Rect} */ (
|
|
207
|
+
await chromedriver.jwproxy.command(`/element/${elementId}/rect`, 'GET')
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return /** @type {import('@appium/types').Rect} */ (
|
|
211
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
212
|
+
`/element/${elementId}/rect`,
|
|
213
|
+
'GET'
|
|
214
|
+
)
|
|
215
|
+
);
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Sends text to the given element by replacing its previous content
|
|
220
|
+
*
|
|
221
|
+
* @param {import('./types').ReplaceValueOptions} opts
|
|
222
|
+
* @throws {Error} If there was a faulre while setting the text
|
|
223
|
+
*/
|
|
224
|
+
async mobileReplaceElementValue(opts) {
|
|
225
|
+
const {elementId, text} = requireArgs(['elementId', 'text'], opts);
|
|
226
|
+
await /** @type {UiAutomator2Server} */ (this.uiautomator2).jwproxy.command(
|
|
227
|
+
`/element/${elementId}/value`,
|
|
228
|
+
'POST',
|
|
229
|
+
{
|
|
230
|
+
text,
|
|
231
|
+
replace: true,
|
|
232
|
+
}
|
|
233
|
+
);
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
mixin(ElementMixin);
|
|
130
238
|
|
|
131
239
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* @param {ReplaceValueOptions} opts
|
|
135
|
-
* @throws {Error} If there was a faulre while setting the text
|
|
240
|
+
* @typedef {import('../uiautomator2').UiAutomator2Server} UiAutomator2Server
|
|
136
241
|
*/
|
|
137
|
-
commands.mobileReplaceElementValue = async function mobileReplaceElementValue (opts = {}) {
|
|
138
|
-
const {elementId, text} = requireArgs(['elementId', 'text'], opts);
|
|
139
|
-
return await this.uiautomator2.jwproxy.command(`/element/${elementId}/value`, 'POST', {text, replace: true});
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
Object.assign(extensions, commands, helpers);
|
|
143
|
-
export { commands, helpers };
|
|
144
|
-
export default extensions;
|
package/lib/commands/find.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import CssConverter from '../css-converter';
|
|
4
|
+
import {mixin} from './mixins';
|
|
4
5
|
|
|
5
6
|
// we override the xpath search for this first-visible-child selector, which
|
|
6
7
|
// looks like /*[@firstVisible="true"]
|
|
@@ -10,25 +11,43 @@ const MAGIC_SCROLLABLE_SEL = /\/\/\*\[@scrollable ?= ?('|")true\1\]/;
|
|
|
10
11
|
const MAGIC_SCROLLABLE_BY = 'new UiSelector().scrollable(true)';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* @type {import('./mixins').UIA2FindMixin}
|
|
15
|
+
* @satisfies {import('@appium/types').ExternalDriver}
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
const FindMixin = {
|
|
18
|
+
/**
|
|
19
|
+
* @privateRemarks Overriding helpers.doFindElementOrEls functionality of appium-android-driver,
|
|
20
|
+
* this.element initialized in find.js of appium-android-drive.
|
|
21
|
+
*/
|
|
22
|
+
async doFindElementOrEls(params) {
|
|
23
|
+
const uiautomator2 = /** @type {import('../uiautomator2').UiAutomator2Server} */ (
|
|
24
|
+
this.uiautomator2
|
|
25
|
+
);
|
|
26
|
+
if (params.strategy === 'xpath' && MAGIC_FIRST_VIS_CHILD_SEL.test(params.selector)) {
|
|
27
|
+
let elementId = params.context;
|
|
28
|
+
return /** @type {Element} */ (
|
|
29
|
+
await uiautomator2.jwproxy.command(`/appium/element/${elementId}/first_visible`, 'GET', {})
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (params.strategy === 'xpath' && MAGIC_SCROLLABLE_SEL.test(params.selector)) {
|
|
33
|
+
params.strategy = '-android uiautomator';
|
|
34
|
+
params.selector = MAGIC_SCROLLABLE_BY;
|
|
35
|
+
}
|
|
36
|
+
if (params.strategy === 'css selector') {
|
|
37
|
+
params.strategy = '-android uiautomator';
|
|
38
|
+
params.selector = new CssConverter(
|
|
39
|
+
params.selector,
|
|
40
|
+
this.opts.appPackage
|
|
41
|
+
).toUiAutomatorSelector();
|
|
42
|
+
}
|
|
43
|
+
return /** @type {Element|Element[]} */ (
|
|
44
|
+
await uiautomator2.jwproxy.command(`/element${params.multiple ? 's' : ''}`, 'POST', params)
|
|
45
|
+
);
|
|
46
|
+
},
|
|
31
47
|
};
|
|
32
48
|
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
mixin(FindMixin);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {import('@appium/types').Element} Element
|
|
53
|
+
*/
|