appium-uiautomator2-driver 6.7.5 → 6.7.7
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 +12 -0
- package/build/lib/commands/actions.d.ts +26 -29
- package/build/lib/commands/actions.d.ts.map +1 -1
- package/build/lib/commands/actions.js +19 -27
- package/build/lib/commands/actions.js.map +1 -1
- package/build/lib/commands/alert.d.ts +14 -22
- package/build/lib/commands/alert.d.ts.map +1 -1
- package/build/lib/commands/alert.js +8 -19
- package/build/lib/commands/alert.js.map +1 -1
- package/build/lib/commands/app-management.d.ts +7 -10
- package/build/lib/commands/app-management.d.ts.map +1 -1
- package/build/lib/commands/app-management.js +4 -14
- package/build/lib/commands/app-management.js.map +1 -1
- package/build/lib/commands/battery.d.ts +4 -5
- package/build/lib/commands/battery.d.ts.map +1 -1
- package/build/lib/commands/battery.js +4 -9
- package/build/lib/commands/battery.js.map +1 -1
- package/build/lib/commands/clipboard.d.ts +9 -13
- package/build/lib/commands/clipboard.d.ts.map +1 -1
- package/build/lib/commands/clipboard.js +7 -14
- package/build/lib/commands/clipboard.js.map +1 -1
- package/build/lib/commands/element.d.ts +64 -69
- package/build/lib/commands/element.d.ts.map +1 -1
- package/build/lib/commands/element.js +64 -84
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/find.d.ts +13 -9
- package/build/lib/commands/find.d.ts.map +1 -1
- package/build/lib/commands/find.js +4 -16
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/gestures.d.ts +87 -189
- package/build/lib/commands/gestures.d.ts.map +1 -1
- package/build/lib/commands/gestures.js +77 -204
- package/build/lib/commands/gestures.js.map +1 -1
- package/build/lib/commands/keyboard.d.ts +30 -41
- package/build/lib/commands/keyboard.d.ts.map +1 -1
- package/build/lib/commands/keyboard.js +22 -37
- package/build/lib/commands/keyboard.js.map +1 -1
- package/build/lib/commands/misc.d.ts +19 -35
- package/build/lib/commands/misc.d.ts.map +1 -1
- package/build/lib/commands/misc.js +15 -30
- package/build/lib/commands/misc.js.map +1 -1
- package/build/lib/commands/navigation.d.ts +11 -16
- package/build/lib/commands/navigation.d.ts.map +1 -1
- package/build/lib/commands/navigation.js +9 -17
- package/build/lib/commands/navigation.js.map +1 -1
- package/build/lib/commands/viewport.d.ts +23 -22
- package/build/lib/commands/viewport.d.ts.map +1 -1
- package/build/lib/commands/viewport.js +17 -24
- package/build/lib/commands/viewport.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/actions.ts +95 -0
- package/lib/commands/alert.ts +46 -0
- package/lib/commands/app-management.ts +25 -0
- package/lib/commands/battery.ts +19 -0
- package/lib/commands/clipboard.ts +29 -0
- package/lib/commands/element.ts +180 -0
- package/lib/commands/find.ts +48 -0
- package/lib/commands/gestures.ts +297 -0
- package/lib/commands/keyboard.ts +102 -0
- package/lib/commands/misc.ts +67 -0
- package/lib/commands/navigation.ts +32 -0
- package/lib/commands/viewport.ts +78 -0
- package/npm-shrinkwrap.json +16 -46
- package/package.json +1 -1
- package/lib/commands/actions.js +0 -107
- package/lib/commands/alert.js +0 -63
- package/lib/commands/app-management.js +0 -32
- package/lib/commands/battery.js +0 -23
- package/lib/commands/clipboard.js +0 -37
- package/lib/commands/element.js +0 -261
- package/lib/commands/find.js +0 -47
- package/lib/commands/gestures.js +0 -446
- package/lib/commands/keyboard.js +0 -108
- package/lib/commands/misc.js +0 -109
- package/lib/commands/navigation.js +0 -33
- package/lib/commands/viewport.js +0 -100
package/package.json
CHANGED
package/lib/commands/actions.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-scheduleaction
|
|
3
|
-
* @this {AndroidUiautomator2Driver}
|
|
4
|
-
* @param {string} name
|
|
5
|
-
* @param {import('@appium/types').StringRecord[]} steps
|
|
6
|
-
* @param {number} [maxPass]
|
|
7
|
-
* @param {number} [maxFail]
|
|
8
|
-
* @param {number} [times]
|
|
9
|
-
* @param {number} [intervalMs]
|
|
10
|
-
* @param {number} [maxHistoryItems]
|
|
11
|
-
* @returns {Promise<any>}
|
|
12
|
-
*/
|
|
13
|
-
export async function mobileScheduleAction(
|
|
14
|
-
name,
|
|
15
|
-
steps,
|
|
16
|
-
maxPass,
|
|
17
|
-
maxFail,
|
|
18
|
-
times,
|
|
19
|
-
intervalMs,
|
|
20
|
-
maxHistoryItems,
|
|
21
|
-
) {
|
|
22
|
-
return await this.uiautomator2.jwproxy.command(
|
|
23
|
-
'/appium/schedule_action',
|
|
24
|
-
'POST',
|
|
25
|
-
{
|
|
26
|
-
name,
|
|
27
|
-
steps,
|
|
28
|
-
maxFail,
|
|
29
|
-
maxPass,
|
|
30
|
-
times,
|
|
31
|
-
intervalMs,
|
|
32
|
-
maxHistoryItems,
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-getactionhistory
|
|
39
|
-
* @this {AndroidUiautomator2Driver}
|
|
40
|
-
* @param {string} name
|
|
41
|
-
* @returns {Promise<import('./types').ActionResult>}
|
|
42
|
-
*/
|
|
43
|
-
export async function mobileGetActionHistory(name) {
|
|
44
|
-
return /** @type {import('./types').ActionResult} */ (
|
|
45
|
-
await this.uiautomator2.jwproxy.command(
|
|
46
|
-
'/appium/action_history',
|
|
47
|
-
'POST',
|
|
48
|
-
{name}
|
|
49
|
-
)
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @this {AndroidUiautomator2Driver}
|
|
55
|
-
* @see https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/scheduled-actions.md#mobile-unscheduleaction
|
|
56
|
-
* @param {string} name
|
|
57
|
-
* @returns {Promise<any>}
|
|
58
|
-
*/
|
|
59
|
-
export async function mobileUnscheduleAction(name) {
|
|
60
|
-
return await this.uiautomator2.jwproxy.command(
|
|
61
|
-
'/appium/unschedule_action',
|
|
62
|
-
'POST',
|
|
63
|
-
{name}
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @this {AndroidUiautomator2Driver}
|
|
69
|
-
* @param {import('@appium/types').StringRecord[]} actions
|
|
70
|
-
* @returns {Promise<void>}
|
|
71
|
-
*/
|
|
72
|
-
export async function performActions(actions) {
|
|
73
|
-
// This is mandatory, since Selenium API uses MOUSE as the default pointer type
|
|
74
|
-
const preprocessedActions = actions.map((action) =>
|
|
75
|
-
Object.assign(
|
|
76
|
-
{},
|
|
77
|
-
action,
|
|
78
|
-
action.type === 'pointer'
|
|
79
|
-
? {
|
|
80
|
-
parameters: {
|
|
81
|
-
pointerType: 'touch',
|
|
82
|
-
},
|
|
83
|
-
}
|
|
84
|
-
: {}
|
|
85
|
-
)
|
|
86
|
-
);
|
|
87
|
-
this.log.debug(`Preprocessed actions: ${JSON.stringify(preprocessedActions, null, ' ')}`);
|
|
88
|
-
await this.uiautomator2.jwproxy.command(
|
|
89
|
-
'/actions',
|
|
90
|
-
'POST',
|
|
91
|
-
{
|
|
92
|
-
actions: preprocessedActions,
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @this {AndroidUiautomator2Driver}
|
|
99
|
-
* @returns {Promise<void>}
|
|
100
|
-
*/
|
|
101
|
-
export async function releaseActions() {
|
|
102
|
-
this.log.info('On this platform, releaseActions is a no-op');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
|
|
107
|
-
*/
|
package/lib/commands/alert.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @this {AndroidUiautomator2Driver}
|
|
3
|
-
* @returns {Promise<string>}
|
|
4
|
-
*/
|
|
5
|
-
export async function getAlertText() {
|
|
6
|
-
return String(
|
|
7
|
-
await this.uiautomator2.jwproxy.command(
|
|
8
|
-
'/alert/text',
|
|
9
|
-
'GET',
|
|
10
|
-
{}
|
|
11
|
-
)
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @this {AndroidUiautomator2Driver}
|
|
17
|
-
* @param {string} [buttonLabel] The name of the button to click in order to accept the alert.
|
|
18
|
-
* If the name is not provided
|
|
19
|
-
* then the script will try to detect the button automatically.
|
|
20
|
-
* @returns {Promise<void>}
|
|
21
|
-
*/
|
|
22
|
-
export async function mobileAcceptAlert(buttonLabel) {
|
|
23
|
-
await this.uiautomator2.jwproxy.command(
|
|
24
|
-
'/alert/accept',
|
|
25
|
-
'POST',
|
|
26
|
-
{buttonLabel}
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @this {AndroidUiautomator2Driver}
|
|
32
|
-
* @returns {Promise<void>}
|
|
33
|
-
*/
|
|
34
|
-
export async function postAcceptAlert() {
|
|
35
|
-
await this.mobileAcceptAlert();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @this {AndroidUiautomator2Driver}
|
|
40
|
-
* @param {string} [buttonLabel] The name of the button to click in order to dismiss the alert.
|
|
41
|
-
* If the name is not provided
|
|
42
|
-
* then the script will try to detect the button automatically.
|
|
43
|
-
* @returns {Promise<void>}
|
|
44
|
-
*/
|
|
45
|
-
export async function mobileDismissAlert(buttonLabel) {
|
|
46
|
-
await this.uiautomator2.jwproxy.command(
|
|
47
|
-
'/alert/dismiss',
|
|
48
|
-
'POST',
|
|
49
|
-
{buttonLabel}
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @this {AndroidUiautomator2Driver}
|
|
55
|
-
* @returns {Promise<void>}
|
|
56
|
-
*/
|
|
57
|
-
export async function postDismissAlert() {
|
|
58
|
-
await this.mobileDismissAlert();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
|
|
63
|
-
*/
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import B from 'bluebird';
|
|
3
|
-
import {errors} from 'appium/driver';
|
|
4
|
-
import {APK_EXTENSION} from '../extensions';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Install multiple APKs with `install-multiple` option.
|
|
8
|
-
* @this {AndroidUiautomator2Driver}
|
|
9
|
-
* @param {string[]} apks The list of APKs to install. Each APK should be a path to a apk
|
|
10
|
-
* or downloadable URL as HTTP/HTTPS.
|
|
11
|
-
* @param {import('./types').InstallOptions} [options] Installation options.
|
|
12
|
-
* @throws {Error} if an error occured while installing the given APKs.
|
|
13
|
-
* @returns {Promise<void>}
|
|
14
|
-
*/
|
|
15
|
-
export async function mobileInstallMultipleApks(apks, options) {
|
|
16
|
-
if (!_.isArray(apks) || _.isEmpty(apks)) {
|
|
17
|
-
throw new errors.InvalidArgumentError('No apks are given to install');
|
|
18
|
-
}
|
|
19
|
-
const configuredApks = await B.all(
|
|
20
|
-
apks.map((app) => this.helpers.configureApp(app, [APK_EXTENSION]))
|
|
21
|
-
);
|
|
22
|
-
await this.adb.installMultipleApks(configuredApks, options);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @template [T=any]
|
|
31
|
-
* @typedef {import('@appium/types').StringRecord<T>} StringRecord
|
|
32
|
-
*/
|
package/lib/commands/battery.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Reads the battery information from the device under test.
|
|
4
|
-
* @this {AndroidUiautomator2Driver}
|
|
5
|
-
* @returns {Promise<import('./types').BatteryInfo>} The actual battery info
|
|
6
|
-
*/
|
|
7
|
-
export async function mobileGetBatteryInfo() {
|
|
8
|
-
const result = /** @type {import('./types').MapKey<BatteryInfo, 'state', 'status'>} */ (
|
|
9
|
-
await /** @type {import('../uiautomator2').UiAutomator2Server} */ (
|
|
10
|
-
this.uiautomator2
|
|
11
|
-
).jwproxy.command('/appium/device/battery_info', 'GET', {})
|
|
12
|
-
);
|
|
13
|
-
const batteryInfo = /** @type {any} */ (result);
|
|
14
|
-
// Give it the same name as in iOS
|
|
15
|
-
batteryInfo.state = result.status;
|
|
16
|
-
delete batteryInfo.status;
|
|
17
|
-
return /** @type {BatteryInfo} */ (batteryInfo);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @typedef {import('./types').BatteryInfo} BatteryInfo
|
|
22
|
-
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
|
|
23
|
-
*/
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @this {AndroidUiautomator2Driver}
|
|
3
|
-
* @returns {Promise<string>} Base64-encoded content of the clipboard
|
|
4
|
-
* or an empty string if the clipboard is empty.
|
|
5
|
-
*/
|
|
6
|
-
export async function getClipboard() {
|
|
7
|
-
return String(
|
|
8
|
-
(await this.adb.getApiLevel()) < 29
|
|
9
|
-
? await this.uiautomator2.jwproxy.command(
|
|
10
|
-
'/appium/device/get_clipboard',
|
|
11
|
-
'POST',
|
|
12
|
-
{}
|
|
13
|
-
)
|
|
14
|
-
: await this.settingsApp.getClipboard()
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @this {AndroidUiautomator2Driver}
|
|
20
|
-
* @param {string} content Base64-encoded clipboard payload
|
|
21
|
-
* @param {'plaintext'} [contentType='plaintext'] Only a single
|
|
22
|
-
* content type is supported, which is 'plaintext'
|
|
23
|
-
* @param {string} [label] Optinal label to identify the current
|
|
24
|
-
* clipboard payload
|
|
25
|
-
* @returns {Promise<void>}
|
|
26
|
-
*/
|
|
27
|
-
export async function setClipboard(content, contentType, label) {
|
|
28
|
-
await this.uiautomator2.jwproxy.command(
|
|
29
|
-
'/appium/device/set_clipboard',
|
|
30
|
-
'POST',
|
|
31
|
-
{content, contentType, label}
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
|
|
37
|
-
*/
|
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/find.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {CssConverter} from '../css-converter';
|
|
2
|
-
|
|
3
|
-
// we override the xpath search for this first-visible-child selector, which
|
|
4
|
-
// looks like /*[@firstVisible="true"]
|
|
5
|
-
const MAGIC_FIRST_VIS_CHILD_SEL = /\/\*\[@firstVisible ?= ?('|")true\1\]/;
|
|
6
|
-
|
|
7
|
-
const MAGIC_SCROLLABLE_SEL = /\/\/\*\[@scrollable ?= ?('|")true\1\]/;
|
|
8
|
-
const MAGIC_SCROLLABLE_BY = 'new UiSelector().scrollable(true)';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @privateRemarks Overriding helpers.doFindElementOrEls functionality of appium-android-driver,
|
|
12
|
-
* this.element initialized in find.js of appium-android-drive.
|
|
13
|
-
*
|
|
14
|
-
* @this {AndroidUiautomator2Driver}
|
|
15
|
-
* @param {import('appium-android-driver').FindElementOpts} params
|
|
16
|
-
* @returns {Promise<Element | Element[]>}
|
|
17
|
-
*/
|
|
18
|
-
export async function doFindElementOrEls(params) {
|
|
19
|
-
const uiautomator2 = /** @type {import('../uiautomator2').UiAutomator2Server} */ (
|
|
20
|
-
this.uiautomator2
|
|
21
|
-
);
|
|
22
|
-
if (params.strategy === 'xpath' && MAGIC_FIRST_VIS_CHILD_SEL.test(params.selector)) {
|
|
23
|
-
let elementId = params.context;
|
|
24
|
-
return /** @type {Element} */ (
|
|
25
|
-
await uiautomator2.jwproxy.command(`/appium/element/${elementId}/first_visible`, 'GET', {})
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
if (params.strategy === 'xpath' && MAGIC_SCROLLABLE_SEL.test(params.selector)) {
|
|
29
|
-
params.strategy = '-android uiautomator';
|
|
30
|
-
params.selector = MAGIC_SCROLLABLE_BY;
|
|
31
|
-
}
|
|
32
|
-
if (params.strategy === 'css selector') {
|
|
33
|
-
params.strategy = '-android uiautomator';
|
|
34
|
-
params.selector = new CssConverter(
|
|
35
|
-
params.selector,
|
|
36
|
-
this.opts.appPackage
|
|
37
|
-
).toUiAutomatorSelector();
|
|
38
|
-
}
|
|
39
|
-
return /** @type {Element|Element[]} */ (
|
|
40
|
-
await uiautomator2.jwproxy.command(`/element${params.multiple ? 's' : ''}`, 'POST', params)
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @typedef {import('@appium/types').Element} Element
|
|
46
|
-
* @typedef {import('../driver').AndroidUiautomator2Driver} AndroidUiautomator2Driver
|
|
47
|
-
*/
|