appium-android-driver 5.14.7 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/build/lib/commands/actions.d.ts +6 -224
- package/build/lib/commands/actions.d.ts.map +1 -1
- package/build/lib/commands/actions.js +306 -405
- package/build/lib/commands/actions.js.map +1 -1
- package/build/lib/commands/alert.d.ts +7 -9
- package/build/lib/commands/alert.d.ts.map +1 -1
- package/build/lib/commands/alert.js +24 -18
- package/build/lib/commands/alert.js.map +1 -1
- package/build/lib/commands/app-management.d.ts +7 -313
- package/build/lib/commands/app-management.d.ts.map +1 -1
- package/build/lib/commands/app-management.js +135 -293
- package/build/lib/commands/app-management.js.map +1 -1
- package/build/lib/commands/context.d.ts +8 -92
- package/build/lib/commands/context.d.ts.map +1 -1
- package/build/lib/commands/context.js +381 -439
- package/build/lib/commands/context.js.map +1 -1
- package/build/lib/commands/element.d.ts +8 -35
- package/build/lib/commands/element.d.ts.map +1 -1
- package/build/lib/commands/element.js +153 -136
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/emu-console.d.ts +6 -48
- package/build/lib/commands/emu-console.d.ts.map +1 -1
- package/build/lib/commands/emu-console.js +19 -34
- package/build/lib/commands/emu-console.js.map +1 -1
- package/build/lib/commands/execute.d.ts +6 -5
- package/build/lib/commands/execute.d.ts.map +1 -1
- package/build/lib/commands/execute.js +77 -66
- package/build/lib/commands/execute.js.map +1 -1
- package/build/lib/commands/file-actions.d.ts +7 -128
- package/build/lib/commands/file-actions.d.ts.map +1 -1
- package/build/lib/commands/file-actions.js +183 -219
- package/build/lib/commands/file-actions.js.map +1 -1
- package/build/lib/commands/find.d.ts +8 -12
- package/build/lib/commands/find.d.ts.map +1 -1
- package/build/lib/commands/find.js +19 -23
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/general.d.ts +9 -132
- package/build/lib/commands/general.d.ts.map +1 -1
- package/build/lib/commands/general.js +281 -312
- package/build/lib/commands/general.js.map +1 -1
- package/build/lib/commands/ime.d.ts +7 -10
- package/build/lib/commands/ime.d.ts.map +1 -1
- package/build/lib/commands/ime.js +47 -35
- package/build/lib/commands/ime.js.map +1 -1
- package/build/lib/commands/index.d.ts +27 -2
- package/build/lib/commands/index.d.ts.map +1 -1
- package/build/lib/commands/index.js +41 -19
- package/build/lib/commands/index.js.map +1 -1
- package/build/lib/commands/intent.d.ts +7 -417
- package/build/lib/commands/intent.d.ts.map +1 -1
- package/build/lib/commands/intent.js +104 -216
- package/build/lib/commands/intent.js.map +1 -1
- package/build/lib/commands/keyboard.d.ts +6 -5
- package/build/lib/commands/keyboard.d.ts.map +1 -1
- package/build/lib/commands/keyboard.js +16 -8
- package/build/lib/commands/keyboard.js.map +1 -1
- package/build/lib/commands/log.d.ts +7 -44
- package/build/lib/commands/log.d.ts.map +1 -1
- package/build/lib/commands/log.js +146 -108
- package/build/lib/commands/log.js.map +1 -1
- package/build/lib/commands/media-projection.d.ts +7 -143
- package/build/lib/commands/media-projection.d.ts.map +1 -1
- package/build/lib/commands/media-projection.js +113 -140
- package/build/lib/commands/media-projection.js.map +1 -1
- package/build/lib/commands/mixins.d.ts +740 -0
- package/build/lib/commands/mixins.d.ts.map +1 -0
- package/build/lib/commands/mixins.js +19 -0
- package/build/lib/commands/mixins.js.map +1 -0
- package/build/lib/commands/network.d.ts +7 -138
- package/build/lib/commands/network.d.ts.map +1 -1
- package/build/lib/commands/network.js +212 -254
- package/build/lib/commands/network.js.map +1 -1
- package/build/lib/commands/performance.d.ts +24 -70
- package/build/lib/commands/performance.d.ts.map +1 -1
- package/build/lib/commands/performance.js +144 -100
- package/build/lib/commands/performance.js.map +1 -1
- package/build/lib/commands/permissions.d.ts +8 -92
- package/build/lib/commands/permissions.d.ts.map +1 -1
- package/build/lib/commands/permissions.js +75 -87
- package/build/lib/commands/permissions.js.map +1 -1
- package/build/lib/commands/recordscreen.d.ts +7 -193
- package/build/lib/commands/recordscreen.d.ts.map +1 -1
- package/build/lib/commands/recordscreen.js +151 -182
- package/build/lib/commands/recordscreen.js.map +1 -1
- package/build/lib/commands/shell.d.ts +7 -7
- package/build/lib/commands/shell.d.ts.map +1 -1
- package/build/lib/commands/shell.js +40 -33
- package/build/lib/commands/shell.js.map +1 -1
- package/build/lib/commands/streamscreen.d.ts +9 -103
- package/build/lib/commands/streamscreen.d.ts.map +1 -1
- package/build/lib/commands/streamscreen.js +261 -218
- package/build/lib/commands/streamscreen.js.map +1 -1
- package/build/lib/commands/system-bars.d.ts +22 -90
- package/build/lib/commands/system-bars.d.ts.map +1 -1
- package/build/lib/commands/system-bars.js +76 -74
- package/build/lib/commands/system-bars.js.map +1 -1
- package/build/lib/commands/touch.d.ts +10 -29
- package/build/lib/commands/touch.d.ts.map +1 -1
- package/build/lib/commands/touch.js +301 -285
- package/build/lib/commands/touch.js.map +1 -1
- package/build/lib/commands/types.d.ts +978 -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/constraints.d.ts +291 -0
- package/build/lib/constraints.d.ts.map +1 -0
- package/build/lib/{desired-caps.js → constraints.js} +103 -102
- package/build/lib/constraints.js.map +1 -0
- package/build/lib/driver.d.ts +68 -37
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +123 -80
- package/build/lib/driver.js.map +1 -1
- package/build/lib/helpers/android.d.ts +164 -0
- package/build/lib/helpers/android.d.ts.map +1 -0
- package/build/lib/helpers/android.js +819 -0
- package/build/lib/helpers/android.js.map +1 -0
- package/build/lib/helpers/index.d.ts +7 -0
- package/build/lib/helpers/index.d.ts.map +1 -0
- package/build/lib/helpers/index.js +29 -0
- package/build/lib/helpers/index.js.map +1 -0
- package/build/lib/helpers/types.d.ts +121 -0
- package/build/lib/helpers/types.d.ts.map +1 -0
- package/build/lib/helpers/types.js +3 -0
- package/build/lib/helpers/types.js.map +1 -0
- package/build/lib/helpers/unlock.d.ts +32 -0
- package/build/lib/helpers/unlock.d.ts.map +1 -0
- package/build/lib/helpers/unlock.js +273 -0
- package/build/lib/helpers/unlock.js.map +1 -0
- package/build/lib/helpers/webview.d.ts +74 -0
- package/build/lib/helpers/webview.d.ts.map +1 -0
- package/build/lib/helpers/webview.js +421 -0
- package/build/lib/helpers/webview.js.map +1 -0
- package/build/lib/index.d.ts +9 -0
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +37 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/method-map.d.ts +0 -8
- package/build/lib/method-map.d.ts.map +1 -1
- package/build/lib/method-map.js +63 -74
- package/build/lib/method-map.js.map +1 -1
- package/build/lib/stubs.d.ts +0 -1
- package/build/lib/stubs.d.ts.map +1 -1
- package/build/lib/stubs.js +1 -0
- package/build/lib/stubs.js.map +1 -1
- package/build/lib/utils.d.ts +1 -1
- package/build/lib/utils.d.ts.map +1 -1
- package/lib/commands/actions.js +351 -464
- package/lib/commands/alert.js +27 -17
- package/lib/commands/app-management.js +156 -314
- package/lib/commands/context.js +457 -441
- package/lib/commands/element.js +201 -157
- package/lib/commands/emu-console.js +25 -45
- package/lib/commands/execute.js +106 -90
- package/lib/commands/file-actions.js +222 -240
- package/lib/commands/find.ts +103 -0
- package/lib/commands/general.js +327 -339
- package/lib/commands/ime.js +50 -34
- package/lib/commands/{index.js → index.ts} +20 -24
- package/lib/commands/intent.js +108 -249
- package/lib/commands/keyboard.js +20 -8
- package/lib/commands/log.js +172 -116
- package/lib/commands/media-projection.js +134 -161
- package/lib/commands/mixins.ts +966 -0
- package/lib/commands/network.js +252 -281
- package/lib/commands/performance.js +203 -132
- package/lib/commands/permissions.js +108 -109
- package/lib/commands/recordscreen.js +212 -209
- package/lib/commands/shell.js +51 -40
- package/lib/commands/streamscreen.js +355 -289
- package/lib/commands/system-bars.js +92 -83
- package/lib/commands/touch.js +357 -294
- package/lib/commands/types.ts +1097 -0
- package/lib/{desired-caps.js → constraints.ts} +106 -103
- package/lib/{driver.js → driver.ts} +278 -132
- package/lib/helpers/android.ts +1143 -0
- package/lib/helpers/index.ts +6 -0
- package/lib/helpers/types.ts +134 -0
- package/lib/helpers/unlock.ts +329 -0
- package/lib/helpers/webview.ts +582 -0
- package/lib/index.ts +18 -0
- package/lib/method-map.js +87 -98
- package/lib/stubs.ts +0 -1
- package/package.json +26 -19
- package/build/index.js +0 -51
- package/build/lib/android-helpers.d.ts +0 -136
- package/build/lib/android-helpers.d.ts.map +0 -1
- package/build/lib/android-helpers.js +0 -855
- package/build/lib/android-helpers.js.map +0 -1
- package/build/lib/commands/coverage.d.ts +0 -5
- package/build/lib/commands/coverage.d.ts.map +0 -1
- package/build/lib/commands/coverage.js +0 -19
- package/build/lib/commands/coverage.js.map +0 -1
- package/build/lib/desired-caps.d.ts +0 -353
- package/build/lib/desired-caps.d.ts.map +0 -1
- package/build/lib/desired-caps.js.map +0 -1
- package/build/lib/unlock-helpers.d.ts +0 -38
- package/build/lib/unlock-helpers.d.ts.map +0 -1
- package/build/lib/unlock-helpers.js +0 -266
- package/build/lib/unlock-helpers.js.map +0 -1
- package/build/lib/webview-helpers.d.ts +0 -224
- package/build/lib/webview-helpers.d.ts.map +0 -1
- package/build/lib/webview-helpers.js +0 -528
- package/build/lib/webview-helpers.js.map +0 -1
- package/index.js +0 -24
- package/lib/android-helpers.js +0 -983
- package/lib/commands/coverage.js +0 -18
- package/lib/commands/find.js +0 -82
- package/lib/unlock-helpers.js +0 -278
- package/lib/webview-helpers.js +0 -602
|
@@ -3,331 +3,300 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const android_helpers_1 = __importDefault(require("../android-helpers"));
|
|
6
|
+
// @ts-check
|
|
9
7
|
const support_1 = require("@appium/support");
|
|
10
|
-
const moment_1 = __importDefault(require("moment"));
|
|
11
8
|
const asyncbox_1 = require("asyncbox");
|
|
12
|
-
const
|
|
9
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
10
|
+
const moment_1 = __importDefault(require("moment"));
|
|
11
|
+
const android_1 = __importDefault(require("../helpers/android"));
|
|
12
|
+
const utils_1 = require("../utils");
|
|
13
|
+
const mixins_1 = require("./mixins");
|
|
13
14
|
const MOMENT_FORMAT_ISO8601 = 'YYYY-MM-DDTHH:mm:ssZ';
|
|
14
|
-
let commands = {}, helpers = {}, extensions = {};
|
|
15
|
-
exports.commands = commands;
|
|
16
|
-
exports.helpers = helpers;
|
|
17
|
-
commands.keys = async function keys(keys) {
|
|
18
|
-
// Protocol sends an array; rethink approach
|
|
19
|
-
keys = lodash_1.default.isArray(keys) ? keys.join('') : keys;
|
|
20
|
-
let params = {
|
|
21
|
-
text: keys,
|
|
22
|
-
replace: false
|
|
23
|
-
};
|
|
24
|
-
if (this.opts.unicodeKeyboard) {
|
|
25
|
-
params.unicodeKeyboard = true;
|
|
26
|
-
}
|
|
27
|
-
await this.doSendKeys(params);
|
|
28
|
-
};
|
|
29
|
-
commands.doSendKeys = async function doSendKeys(params) {
|
|
30
|
-
return await this.bootstrap.sendAction('setText', params);
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Retrieves the current device's timestamp.
|
|
34
|
-
*
|
|
35
|
-
* @param {string} format - The set of format specifiers. Read
|
|
36
|
-
* https://momentjs.com/docs/ to get the full list of supported
|
|
37
|
-
* datetime format specifiers. The default format is
|
|
38
|
-
* `YYYY-MM-DDTHH:mm:ssZ`, which complies to ISO-8601
|
|
39
|
-
* @return {string} Formatted datetime string or the raw command output if formatting fails
|
|
40
|
-
*/
|
|
41
|
-
commands.getDeviceTime = async function getDeviceTime(format = MOMENT_FORMAT_ISO8601) {
|
|
42
|
-
this.log.debug('Attempting to capture android device date and time. ' +
|
|
43
|
-
`The format specifier is '${format}'`);
|
|
44
|
-
const deviceTimestamp = (await this.adb.shell(['date', '+%Y-%m-%dT%T%z'])).trim();
|
|
45
|
-
this.log.debug(`Got device timestamp: ${deviceTimestamp}`);
|
|
46
|
-
const parsedTimestamp = moment_1.default.utc(deviceTimestamp, 'YYYY-MM-DDTHH:mm:ssZZ');
|
|
47
|
-
if (!parsedTimestamp.isValid()) {
|
|
48
|
-
this.log.warn('Cannot parse the returned timestamp. Returning as is');
|
|
49
|
-
return deviceTimestamp;
|
|
50
|
-
}
|
|
51
|
-
return parsedTimestamp.utcOffset(parsedTimestamp._tzm || 0).format(format);
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* @typedef {Object} DeviceTimeOptions
|
|
55
|
-
* @property {string} format [YYYY-MM-DDTHH:mm:ssZ] - See getDeviceTime#format
|
|
56
|
-
*/
|
|
57
15
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @param {DeviceTimeOptions} opts
|
|
61
|
-
* @return {string} Formatted datetime string or the raw command output if formatting fails
|
|
16
|
+
* @type {import('./mixins').GeneralMixin & ThisType<import('../driver').AndroidDriver>}
|
|
17
|
+
* @satisfies {import('@appium/types').ExternalDriver}
|
|
62
18
|
*/
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
19
|
+
const GeneralMixin = {
|
|
20
|
+
_cachedActivityArgs: {},
|
|
21
|
+
async keys(keys) {
|
|
22
|
+
// Protocol sends an array; rethink approach
|
|
23
|
+
keys = lodash_1.default.isArray(keys) ? keys.join('') : keys;
|
|
24
|
+
/**
|
|
25
|
+
* @type {import('./types').SendKeysOpts}
|
|
26
|
+
*/
|
|
27
|
+
const params = {
|
|
28
|
+
text: keys,
|
|
29
|
+
replace: false,
|
|
30
|
+
};
|
|
31
|
+
if (this.opts.unicodeKeyboard) {
|
|
32
|
+
params.unicodeKeyboard = true;
|
|
33
|
+
}
|
|
34
|
+
await this.doSendKeys(params);
|
|
35
|
+
},
|
|
36
|
+
async doSendKeys(params) {
|
|
37
|
+
return await /** @type {AndroidBootstrap} */ (this.bootstrap).sendAction('setText', params);
|
|
38
|
+
},
|
|
39
|
+
async getDeviceTime(format = MOMENT_FORMAT_ISO8601) {
|
|
40
|
+
this.log.debug('Attempting to capture android device date and time. ' + `The format specifier is '${format}'`);
|
|
41
|
+
const deviceTimestamp = (await /** @type {ADB} */ (this.adb).shell(['date', '+%Y-%m-%dT%T%z'])).trim();
|
|
42
|
+
this.log.debug(`Got device timestamp: ${deviceTimestamp}`);
|
|
43
|
+
const parsedTimestamp = moment_1.default.utc(deviceTimestamp, 'YYYY-MM-DDTHH:mm:ssZZ');
|
|
44
|
+
if (!parsedTimestamp.isValid()) {
|
|
45
|
+
this.log.warn('Cannot parse the returned timestamp. Returning as is');
|
|
46
|
+
return deviceTimestamp;
|
|
47
|
+
}
|
|
48
|
+
// @ts-expect-error private API
|
|
49
|
+
return parsedTimestamp.utcOffset(parsedTimestamp._tzm || 0).format(format);
|
|
50
|
+
},
|
|
51
|
+
async mobileGetDeviceTime(opts = {}) {
|
|
52
|
+
return await this.getDeviceTime(opts.format);
|
|
53
|
+
},
|
|
54
|
+
async getPageSource() {
|
|
55
|
+
return await /** @type {AndroidBootstrap} */ (this.bootstrap).sendAction('source');
|
|
56
|
+
},
|
|
57
|
+
async back() {
|
|
58
|
+
return await /** @type {AndroidBootstrap} */ (this.bootstrap).sendAction('pressBack');
|
|
59
|
+
},
|
|
60
|
+
async openSettingsActivity(setting) {
|
|
61
|
+
const adb = /** @type {ADB} */ (this.adb);
|
|
62
|
+
let { appPackage, appActivity } = await adb.getFocusedPackageAndActivity();
|
|
63
|
+
await adb.shell(['am', 'start', '-a', `android.settings.${setting}`]);
|
|
64
|
+
await adb.waitForNotActivity(/** @type {string} */ (appPackage), appActivity, 5000);
|
|
65
|
+
},
|
|
66
|
+
async getWindowSize() {
|
|
67
|
+
return await /** @type {AndroidBootstrap} */ (this.bootstrap).sendAction('getDeviceSize');
|
|
68
|
+
},
|
|
69
|
+
// For W3C
|
|
70
|
+
async getWindowRect() {
|
|
71
|
+
const { width, height } = await this.getWindowSize();
|
|
72
|
+
return {
|
|
73
|
+
width,
|
|
74
|
+
height,
|
|
75
|
+
x: 0,
|
|
76
|
+
y: 0,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
async getCurrentActivity() {
|
|
80
|
+
return (await /** @type {ADB} */ (this.adb).getFocusedPackageAndActivity()).appActivity;
|
|
81
|
+
},
|
|
82
|
+
async getCurrentPackage() {
|
|
83
|
+
return (await /** @type {ADB} */ (this.adb).getFocusedPackageAndActivity()).appPackage;
|
|
84
|
+
},
|
|
85
|
+
async background(seconds) {
|
|
86
|
+
const adb = /** @type {ADB} */ (this.adb);
|
|
87
|
+
if (seconds < 0) {
|
|
88
|
+
// if user passes in a negative seconds value, interpret that as the instruction
|
|
89
|
+
// to not bring the app back at all
|
|
90
|
+
await adb.goToHome();
|
|
126
91
|
return true;
|
|
127
92
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
93
|
+
let { appPackage, appActivity } = await adb.getFocusedPackageAndActivity();
|
|
94
|
+
await adb.goToHome();
|
|
95
|
+
// people can wait for a long time, so to be safe let's use the longSleep function and log
|
|
96
|
+
// progress periodically.
|
|
97
|
+
const sleepMs = seconds * 1000;
|
|
98
|
+
const thresholdMs = 30 * 1000; // use the spin-wait for anything over this threshold
|
|
99
|
+
// for our spin interval, use 1% of the total wait time, but nothing bigger than 30s
|
|
100
|
+
const intervalMs = lodash_1.default.min([30 * 1000, parseInt(String(sleepMs / 100), 10)]);
|
|
101
|
+
/**
|
|
102
|
+
*
|
|
103
|
+
* @param {{elapsedMs: number, progress: number}} param0
|
|
104
|
+
*/
|
|
105
|
+
const progressCb = ({ elapsedMs, progress }) => {
|
|
106
|
+
const waitSecs = (elapsedMs / 1000).toFixed(0);
|
|
107
|
+
const progressPct = (progress * 100).toFixed(2);
|
|
108
|
+
this.log.debug(`Waited ${waitSecs}s so far (${progressPct}%)`);
|
|
109
|
+
};
|
|
110
|
+
await (0, asyncbox_1.longSleep)(sleepMs, { thresholdMs, intervalMs, progressCb });
|
|
111
|
+
/** @type {import('appium-adb').StartAppOptions} */
|
|
112
|
+
let args;
|
|
113
|
+
if (this._cachedActivityArgs && this._cachedActivityArgs[`${appPackage}/${appActivity}`]) {
|
|
114
|
+
// the activity was started with `startActivity`, so use those args to restart
|
|
115
|
+
args = this._cachedActivityArgs[`${appPackage}/${appActivity}`];
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
try {
|
|
119
|
+
this.log.debug(`Activating app '${appPackage}' in order to restore it`);
|
|
120
|
+
await this.activateApp(/** @type {string} */ (appPackage));
|
|
121
|
+
return true;
|
|
144
122
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
123
|
+
catch (ign) { }
|
|
124
|
+
args =
|
|
125
|
+
(appPackage === this.opts.appPackage && appActivity === this.opts.appActivity) ||
|
|
126
|
+
(appPackage === this.opts.appWaitPackage &&
|
|
127
|
+
(this.opts.appWaitActivity || '').split(',').includes(String(appActivity)))
|
|
128
|
+
? {
|
|
129
|
+
// the activity is the original session activity, so use the original args
|
|
130
|
+
pkg: /** @type {string} */ (this.opts.appPackage),
|
|
131
|
+
activity: this.opts.appActivity,
|
|
132
|
+
action: this.opts.intentAction,
|
|
133
|
+
category: this.opts.intentCategory,
|
|
134
|
+
flags: this.opts.intentFlags,
|
|
135
|
+
waitPkg: this.opts.appWaitPackage,
|
|
136
|
+
waitActivity: this.opts.appWaitActivity,
|
|
137
|
+
waitForLaunch: this.opts.appWaitForLaunch,
|
|
138
|
+
waitDuration: this.opts.appWaitDuration,
|
|
139
|
+
optionalIntentArguments: this.opts.optionalIntentArguments,
|
|
140
|
+
stopApp: false,
|
|
141
|
+
user: this.opts.userProfile,
|
|
142
|
+
}
|
|
143
|
+
: {
|
|
144
|
+
// the activity was started some other way, so use defaults
|
|
145
|
+
pkg: /** @type {string} */ (appPackage),
|
|
146
|
+
activity: appActivity,
|
|
147
|
+
waitPkg: appPackage,
|
|
148
|
+
waitActivity: appActivity,
|
|
149
|
+
stopApp: false,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
args = /** @type {import('appium-adb').StartAppOptions} */ (lodash_1.default.pickBy(args, (value) => !lodash_1.default.isUndefined(value)));
|
|
153
|
+
this.log.debug(`Bringing application back to foreground with arguments: ${JSON.stringify(args)}`);
|
|
154
|
+
return await adb.startApp(args);
|
|
155
|
+
},
|
|
156
|
+
async getStrings(language) {
|
|
157
|
+
const adb = /** @type {ADB} */ (this.adb);
|
|
158
|
+
if (!language) {
|
|
159
|
+
language = await adb.getDeviceLanguage();
|
|
160
|
+
this.log.info(`No language specified, returning strings for: ${language}`);
|
|
161
|
+
}
|
|
162
|
+
// Clients require the resulting mapping to have both keys
|
|
163
|
+
// and values of type string
|
|
164
|
+
/** @param {StringRecord} mapping */
|
|
165
|
+
const preprocessStringsMap = (mapping) => {
|
|
166
|
+
/** @type {StringRecord} */
|
|
167
|
+
const result = {};
|
|
168
|
+
for (const [key, value] of lodash_1.default.toPairs(mapping)) {
|
|
169
|
+
result[key] = lodash_1.default.isString(value) ? value : JSON.stringify(value);
|
|
170
|
+
}
|
|
171
|
+
return result;
|
|
172
|
+
};
|
|
173
|
+
if (this.apkStrings[language]) {
|
|
174
|
+
// Return cached strings
|
|
175
|
+
return preprocessStringsMap(this.apkStrings[language]);
|
|
176
|
+
}
|
|
177
|
+
this.apkStrings[language] = await android_1.default.pushStrings(language, adb, this.opts);
|
|
178
|
+
if (this.bootstrap) {
|
|
179
|
+
// TODO: This is mutating the current language, but it's how appium currently works
|
|
180
|
+
await this.bootstrap.sendAction('updateStrings');
|
|
168
181
|
}
|
|
169
|
-
return result;
|
|
170
|
-
};
|
|
171
|
-
if (this.apkStrings[language]) {
|
|
172
|
-
// Return cached strings
|
|
173
182
|
return preprocessStringsMap(this.apkStrings[language]);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
};
|
|
186
|
-
commands.startActivity = async function startActivity(appPackage, appActivity, appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags, optionalIntentArguments, dontStopAppOnReset) {
|
|
187
|
-
this.log.debug(`Starting package '${appPackage}' and activity '${appActivity}'`);
|
|
188
|
-
// dontStopAppOnReset is both an argument here, and a desired capability
|
|
189
|
-
// if the argument is set, use it, otherwise use the cap
|
|
190
|
-
if (!support_1.util.hasValue(dontStopAppOnReset)) {
|
|
191
|
-
dontStopAppOnReset = !!this.opts.dontStopAppOnReset;
|
|
192
|
-
}
|
|
193
|
-
let args = {
|
|
194
|
-
pkg: appPackage,
|
|
195
|
-
activity: appActivity,
|
|
196
|
-
waitPkg: appWaitPackage || appPackage,
|
|
197
|
-
waitActivity: appWaitActivity || appActivity,
|
|
198
|
-
action: intentAction,
|
|
199
|
-
category: intentCategory,
|
|
200
|
-
flags: intentFlags,
|
|
201
|
-
optionalIntentArguments,
|
|
202
|
-
stopApp: !dontStopAppOnReset
|
|
203
|
-
};
|
|
204
|
-
this._cachedActivityArgs = this._cachedActivityArgs || {};
|
|
205
|
-
this._cachedActivityArgs[`${args.waitPkg}/${args.waitActivity}`] = args;
|
|
206
|
-
await this.adb.startApp(args);
|
|
207
|
-
};
|
|
208
|
-
commands.reset = async function reset() {
|
|
209
|
-
await android_helpers_1.default.resetApp(this.adb, Object.assign({}, this.opts, { fastReset: true }));
|
|
210
|
-
// reset context since we don't know what kind on context we will end up after app launch.
|
|
211
|
-
await this.setContext();
|
|
212
|
-
return await this.isChromeSession ? this.startChromeSession() : this.startAUT();
|
|
213
|
-
};
|
|
214
|
-
commands.startAUT = async function startAUT() {
|
|
215
|
-
await this.adb.startApp({
|
|
216
|
-
pkg: this.opts.appPackage,
|
|
217
|
-
activity: this.opts.appActivity,
|
|
218
|
-
action: this.opts.intentAction,
|
|
219
|
-
category: this.opts.intentCategory,
|
|
220
|
-
flags: this.opts.intentFlags,
|
|
221
|
-
waitPkg: this.opts.appWaitPackage,
|
|
222
|
-
waitActivity: this.opts.appWaitActivity,
|
|
223
|
-
waitForLaunch: this.opts.appWaitForLaunch,
|
|
224
|
-
waitDuration: this.opts.appWaitDuration,
|
|
225
|
-
optionalIntentArguments: this.opts.optionalIntentArguments,
|
|
226
|
-
stopApp: !this.opts.dontStopAppOnReset,
|
|
227
|
-
user: this.opts.userProfile,
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
// we override setUrl to take an android URI which can be used for deep-linking
|
|
231
|
-
// inside an app, similar to starting an intent
|
|
232
|
-
commands.setUrl = async function setUrl(uri) {
|
|
233
|
-
await this.adb.startUri(uri, this.opts.appPackage);
|
|
234
|
-
};
|
|
235
|
-
// closing app using force stop
|
|
236
|
-
commands.closeApp = async function closeApp() {
|
|
237
|
-
await this.adb.forceStop(this.opts.appPackage);
|
|
238
|
-
// reset context since we don't know what kind on context we will end up after app launch.
|
|
239
|
-
await this.setContext();
|
|
240
|
-
};
|
|
241
|
-
commands.getDisplayDensity = async function getDisplayDensity() {
|
|
242
|
-
// first try the property for devices
|
|
243
|
-
let out = await this.adb.shell(['getprop', 'ro.sf.lcd_density']);
|
|
244
|
-
if (out) {
|
|
245
|
-
let val = parseInt(out, 10);
|
|
246
|
-
// if the value is NaN, try getting the emulator property
|
|
247
|
-
if (!isNaN(val)) {
|
|
248
|
-
return val;
|
|
183
|
+
},
|
|
184
|
+
async launchApp() {
|
|
185
|
+
await this.initAUT();
|
|
186
|
+
await this.startAUT();
|
|
187
|
+
},
|
|
188
|
+
async startActivity(appPackage, appActivity, appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags, optionalIntentArguments, dontStopAppOnReset) {
|
|
189
|
+
this.log.debug(`Starting package '${appPackage}' and activity '${appActivity}'`);
|
|
190
|
+
// dontStopAppOnReset is both an argument here, and a desired capability
|
|
191
|
+
// if the argument is set, use it, otherwise use the cap
|
|
192
|
+
if (!support_1.util.hasValue(dontStopAppOnReset)) {
|
|
193
|
+
dontStopAppOnReset = !!this.opts.dontStopAppOnReset;
|
|
249
194
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
195
|
+
/** @type {import('appium-adb').StartAppOptions} */
|
|
196
|
+
let args = {
|
|
197
|
+
pkg: appPackage,
|
|
198
|
+
activity: appActivity,
|
|
199
|
+
waitPkg: appWaitPackage || appPackage,
|
|
200
|
+
waitActivity: appWaitActivity || appActivity,
|
|
201
|
+
action: intentAction,
|
|
202
|
+
category: intentCategory,
|
|
203
|
+
flags: intentFlags,
|
|
204
|
+
optionalIntentArguments,
|
|
205
|
+
stopApp: !dontStopAppOnReset,
|
|
206
|
+
};
|
|
207
|
+
this._cachedActivityArgs = this._cachedActivityArgs || {};
|
|
208
|
+
this._cachedActivityArgs[`${args.waitPkg}/${args.waitActivity}`] = args;
|
|
209
|
+
await /** @type {ADB} */ (this.adb).startApp(args);
|
|
210
|
+
},
|
|
211
|
+
async reset() {
|
|
212
|
+
await android_1.default.resetApp(
|
|
213
|
+
/** @type {ADB} */ (this.adb), Object.assign({}, this.opts, { fastReset: true }));
|
|
214
|
+
// reset context since we don't know what kind on context we will end up after app launch.
|
|
215
|
+
await this.setContext();
|
|
216
|
+
return this.isChromeSession ? this.startChromeSession() : this.startAUT();
|
|
217
|
+
},
|
|
218
|
+
async startAUT() {
|
|
219
|
+
await /** @type {ADB} */ (this.adb).startApp({
|
|
220
|
+
pkg: /** @type {string} */ (this.opts.appPackage),
|
|
221
|
+
activity: this.opts.appActivity,
|
|
222
|
+
action: this.opts.intentAction,
|
|
223
|
+
category: this.opts.intentCategory,
|
|
224
|
+
flags: this.opts.intentFlags,
|
|
225
|
+
waitPkg: this.opts.appWaitPackage,
|
|
226
|
+
waitActivity: this.opts.appWaitActivity,
|
|
227
|
+
waitForLaunch: this.opts.appWaitForLaunch,
|
|
228
|
+
waitDuration: this.opts.appWaitDuration,
|
|
229
|
+
optionalIntentArguments: this.opts.optionalIntentArguments,
|
|
230
|
+
stopApp: !this.opts.dontStopAppOnReset,
|
|
231
|
+
user: this.opts.userProfile,
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
// we override setUrl to take an android URI which can be used for deep-linking
|
|
235
|
+
// inside an app, similar to starting an intent
|
|
236
|
+
async setUrl(uri) {
|
|
237
|
+
await /** @type {ADB} */ (this.adb).startUri(uri, /** @type {string} */ (this.opts.appPackage));
|
|
238
|
+
},
|
|
239
|
+
// closing app using force stop
|
|
240
|
+
async closeApp() {
|
|
241
|
+
await /** @type {ADB} */ (this.adb).forceStop(/** @type {string} */ (this.opts.appPackage));
|
|
242
|
+
// reset context since we don't know what kind on context we will end up after app launch.
|
|
243
|
+
await this.setContext();
|
|
244
|
+
},
|
|
245
|
+
async getDisplayDensity() {
|
|
246
|
+
// first try the property for devices
|
|
247
|
+
let out = await /** @type {ADB} */ (this.adb).shell(['getprop', 'ro.sf.lcd_density']);
|
|
248
|
+
if (out) {
|
|
249
|
+
let val = parseInt(out, 10);
|
|
250
|
+
// if the value is NaN, try getting the emulator property
|
|
251
|
+
if (!isNaN(val)) {
|
|
252
|
+
return val;
|
|
253
|
+
}
|
|
254
|
+
this.log.debug(`Parsed density value was NaN: "${out}"`);
|
|
258
255
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
256
|
+
// fallback to trying property for emulators
|
|
257
|
+
out = await /** @type {ADB} */ (this.adb).shell(['getprop', 'qemu.sf.lcd_density']);
|
|
258
|
+
if (out) {
|
|
259
|
+
let val = parseInt(out, 10);
|
|
260
|
+
if (!isNaN(val)) {
|
|
261
|
+
return val;
|
|
262
|
+
}
|
|
263
|
+
this.log.debug(`Parsed density value was NaN: "${out}"`);
|
|
264
|
+
}
|
|
265
|
+
// couldn't get anything, so error out
|
|
266
|
+
this.log.errorAndThrow('Failed to get display density property.');
|
|
267
|
+
throw new Error(); // unreachable
|
|
268
|
+
},
|
|
269
|
+
async mobilePerformEditorAction(opts) {
|
|
270
|
+
const { action } = (0, utils_1.requireArgs)('action', opts);
|
|
271
|
+
await /** @type {ADB} */ (this.adb).performEditorAction(action);
|
|
272
|
+
},
|
|
273
|
+
async mobileGetNotifications() {
|
|
274
|
+
return await /** @type {ADB} */ (this.adb).getNotifications();
|
|
275
|
+
},
|
|
276
|
+
async mobileListSms(opts) {
|
|
277
|
+
return await /** @type {ADB} */ (this.adb).getSmsList(opts);
|
|
278
|
+
},
|
|
279
|
+
async mobileUnlock(opts = {}) {
|
|
280
|
+
const { key, type, strategy, timeoutMs } = opts;
|
|
281
|
+
if (!key && !type) {
|
|
282
|
+
await this.unlock();
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
// @ts-expect-error XXX: these caps should be defined in the constraints!!
|
|
286
|
+
await android_1.default.unlock(this, /** @type {ADB} */ (this.adb), {
|
|
287
|
+
unlockKey: key,
|
|
288
|
+
unlockType: type,
|
|
289
|
+
unlockStrategy: strategy,
|
|
290
|
+
unlockSuccessTimeout: timeoutMs,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
294
|
};
|
|
295
|
+
(0, mixins_1.mixin)(GeneralMixin);
|
|
296
|
+
exports.default = GeneralMixin;
|
|
295
297
|
/**
|
|
296
|
-
* @typedef {
|
|
297
|
-
* @
|
|
298
|
-
*
|
|
299
|
-
* a biometric finger id.
|
|
300
|
-
* If not provided then the corresponding value from session capabilities is used.
|
|
301
|
-
* @property {string?} type The unlock type. The following unlock types
|
|
302
|
-
* are supported: `pin`, `pinWithKeyEvent`, `password`, `pattern` and `fingerprint`.
|
|
303
|
-
* If not provided then the corresponding value from session capabilities is used.
|
|
304
|
-
* @property {string?} strategy Either 'locksettings' (default) or 'uiautomator'.
|
|
305
|
-
* Setting it to 'uiautomator' will enforce the driver to avoid using special
|
|
306
|
-
* ADB shortcuts in order to speed up the unlock procedure.
|
|
307
|
-
* @property {number?} timeoutMs [2000] The maximum time in milliseconds
|
|
308
|
-
* to wait until the screen gets unlocked
|
|
309
|
-
*/
|
|
310
|
-
/**
|
|
311
|
-
* Unlocks the device if it is locked. Noop if the device's screen is not locked.
|
|
312
|
-
*
|
|
313
|
-
* @param {UnlockOptions} opts
|
|
314
|
-
* @throws {Error} if unlock operation fails or the provided
|
|
315
|
-
* arguments are not valid
|
|
298
|
+
* @typedef {import('../bootstrap').AndroidBootstrap} AndroidBootstrap
|
|
299
|
+
* @typedef {import('appium-adb').ADB} ADB
|
|
300
|
+
* @typedef {import('@appium/types').StringRecord} StringRecord
|
|
316
301
|
*/
|
|
317
|
-
commands.mobileUnlock = async function mobileUnlock(opts = {}) {
|
|
318
|
-
const { key, type, strategy, timeoutMs } = opts;
|
|
319
|
-
if (!key && !type) {
|
|
320
|
-
await this.unlock();
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
await android_helpers_1.default.unlock(this, this.adb, {
|
|
324
|
-
unlockKey: key,
|
|
325
|
-
unlockType: type,
|
|
326
|
-
unlockStrategy: strategy,
|
|
327
|
-
unlockSuccessTimeout: timeoutMs,
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
Object.assign(extensions, commands, helpers);
|
|
332
|
-
exports.default = extensions;
|
|
333
302
|
//# sourceMappingURL=general.js.map
|