appium-android-driver 7.8.3 → 8.0.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 +25 -0
- package/build/lib/commands/app-management.d.ts +129 -5
- package/build/lib/commands/app-management.d.ts.map +1 -1
- package/build/lib/commands/app-management.js +433 -128
- package/build/lib/commands/app-management.js.map +1 -1
- package/build/lib/commands/appearance.d.ts +17 -4
- package/build/lib/commands/appearance.d.ts.map +1 -1
- package/build/lib/commands/appearance.js +32 -33
- package/build/lib/commands/appearance.js.map +1 -1
- package/build/lib/commands/context/cache.d.ts +19 -0
- package/build/lib/commands/context/cache.d.ts.map +1 -0
- package/build/lib/commands/context/cache.js +32 -0
- package/build/lib/commands/context/cache.js.map +1 -0
- package/build/lib/commands/context/exports.d.ts +141 -0
- package/build/lib/commands/context/exports.d.ts.map +1 -0
- package/build/lib/commands/context/exports.js +351 -0
- package/build/lib/commands/context/exports.js.map +1 -0
- package/build/lib/commands/context/helpers.d.ts +98 -0
- package/build/lib/commands/context/helpers.d.ts.map +1 -0
- package/build/lib/commands/context/helpers.js +715 -0
- package/build/lib/commands/context/helpers.js.map +1 -0
- package/build/lib/commands/device/common.d.ts +23 -0
- package/build/lib/commands/device/common.d.ts.map +1 -0
- package/build/lib/commands/device/common.js +230 -0
- package/build/lib/commands/device/common.js.map +1 -0
- package/build/lib/commands/device/emulator-actions.d.ts +114 -0
- package/build/lib/commands/device/emulator-actions.d.ts.map +1 -0
- package/build/lib/commands/device/emulator-actions.js +197 -0
- package/build/lib/commands/device/emulator-actions.js.map +1 -0
- package/build/lib/commands/device/emulator-console.d.ts +7 -0
- package/build/lib/commands/device/emulator-console.d.ts.map +1 -0
- package/build/lib/commands/device/emulator-console.js +24 -0
- package/build/lib/commands/device/emulator-console.js.map +1 -0
- package/build/lib/commands/device/utils.d.ts +50 -0
- package/build/lib/commands/device/utils.d.ts.map +1 -0
- package/build/lib/commands/device/utils.js +238 -0
- package/build/lib/commands/device/utils.js.map +1 -0
- package/build/lib/commands/deviceidle.d.ts +8 -5
- package/build/lib/commands/deviceidle.d.ts.map +1 -1
- package/build/lib/commands/deviceidle.js +31 -37
- package/build/lib/commands/deviceidle.js.map +1 -1
- package/build/lib/commands/element.d.ts +99 -5
- package/build/lib/commands/element.d.ts.map +1 -1
- package/build/lib/commands/element.js +152 -116
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/execute.d.ts +12 -4
- package/build/lib/commands/execute.d.ts.map +1 -1
- package/build/lib/commands/execute.js +83 -78
- package/build/lib/commands/execute.js.map +1 -1
- package/build/lib/commands/file-actions.d.ts +42 -5
- package/build/lib/commands/file-actions.d.ts.map +1 -1
- package/build/lib/commands/file-actions.js +230 -194
- package/build/lib/commands/file-actions.js.map +1 -1
- package/build/lib/commands/find.d.ts +5 -4
- package/build/lib/commands/find.d.ts.map +1 -1
- package/build/lib/commands/find.js +7 -10
- package/build/lib/commands/find.js.map +1 -1
- package/build/lib/commands/geolocation.d.ts +45 -0
- package/build/lib/commands/geolocation.d.ts.map +1 -0
- package/build/lib/commands/geolocation.js +182 -0
- package/build/lib/commands/geolocation.js.map +1 -0
- package/build/lib/commands/ime.d.ts +25 -5
- package/build/lib/commands/ime.d.ts.map +1 -1
- package/build/lib/commands/ime.js +59 -42
- package/build/lib/commands/ime.js.map +1 -1
- package/build/lib/commands/intent.d.ts +56 -5
- package/build/lib/commands/intent.d.ts.map +1 -1
- package/build/lib/commands/intent.js +135 -83
- package/build/lib/commands/intent.js.map +1 -1
- package/build/lib/commands/keyboard.d.ts +58 -4
- package/build/lib/commands/keyboard.d.ts.map +1 -1
- package/build/lib/commands/keyboard.js +119 -17
- package/build/lib/commands/keyboard.js.map +1 -1
- package/build/lib/commands/lock/exports.d.ts +301 -0
- package/build/lib/commands/lock/exports.d.ts.map +1 -0
- package/build/lib/commands/lock/exports.js +121 -0
- package/build/lib/commands/lock/exports.js.map +1 -0
- package/build/lib/commands/lock/helpers.d.ts +349 -0
- package/build/lib/commands/lock/helpers.d.ts.map +1 -0
- package/build/lib/commands/lock/helpers.js +375 -0
- package/build/lib/commands/lock/helpers.js.map +1 -0
- package/build/lib/commands/log.d.ts +59 -5
- package/build/lib/commands/log.d.ts.map +1 -1
- package/build/lib/commands/log.js +150 -140
- package/build/lib/commands/log.js.map +1 -1
- package/build/lib/commands/media-projection.d.ts +16 -5
- package/build/lib/commands/media-projection.d.ts.map +1 -1
- package/build/lib/commands/media-projection.js +69 -58
- package/build/lib/commands/media-projection.js.map +1 -1
- package/build/lib/commands/memory.d.ts +9 -5
- package/build/lib/commands/memory.d.ts.map +1 -1
- package/build/lib/commands/memory.js +19 -24
- package/build/lib/commands/memory.js.map +1 -1
- package/build/lib/commands/misc.d.ts +42 -0
- package/build/lib/commands/misc.d.ts.map +1 -0
- package/build/lib/commands/misc.js +100 -0
- package/build/lib/commands/misc.js.map +1 -0
- package/build/lib/commands/network.d.ts +61 -5
- package/build/lib/commands/network.d.ts.map +1 -1
- package/build/lib/commands/network.js +196 -189
- package/build/lib/commands/network.js.map +1 -1
- package/build/lib/commands/performance.d.ts +67 -27
- package/build/lib/commands/performance.d.ts.map +1 -1
- package/build/lib/commands/performance.js +105 -80
- package/build/lib/commands/performance.js.map +1 -1
- package/build/lib/commands/permissions.d.ts +12 -6
- package/build/lib/commands/permissions.d.ts.map +1 -1
- package/build/lib/commands/permissions.js +65 -62
- package/build/lib/commands/permissions.js.map +1 -1
- package/build/lib/commands/recordscreen.d.ts +44 -5
- package/build/lib/commands/recordscreen.d.ts.map +1 -1
- package/build/lib/commands/recordscreen.js +131 -126
- package/build/lib/commands/recordscreen.js.map +1 -1
- package/build/lib/commands/resources.d.ts +16 -0
- package/build/lib/commands/resources.d.ts.map +1 -0
- package/build/lib/commands/resources.js +91 -0
- package/build/lib/commands/resources.js.map +1 -0
- package/build/lib/commands/shell.d.ts +8 -5
- package/build/lib/commands/shell.d.ts.map +1 -1
- package/build/lib/commands/shell.js +29 -33
- package/build/lib/commands/shell.js.map +1 -1
- package/build/lib/commands/streamscreen.d.ts +34 -6
- package/build/lib/commands/streamscreen.d.ts.map +1 -1
- package/build/lib/commands/streamscreen.js +166 -162
- package/build/lib/commands/streamscreen.js.map +1 -1
- package/build/lib/commands/system-bars.d.ts +18 -13
- package/build/lib/commands/system-bars.d.ts.map +1 -1
- package/build/lib/commands/system-bars.js +68 -64
- package/build/lib/commands/system-bars.js.map +1 -1
- package/build/lib/commands/time.d.ts +14 -0
- package/build/lib/commands/time.d.ts.map +1 -0
- package/build/lib/commands/time.js +39 -0
- package/build/lib/commands/time.js.map +1 -0
- package/build/lib/commands/touch.d.ts +99 -6
- package/build/lib/commands/touch.d.ts.map +1 -1
- package/build/lib/commands/touch.js +399 -280
- package/build/lib/commands/touch.js.map +1 -1
- package/build/lib/commands/types.d.ts +110 -2
- package/build/lib/commands/types.d.ts.map +1 -1
- package/build/lib/doctor/checks.d.ts.map +1 -1
- package/build/lib/doctor/checks.js +4 -4
- package/build/lib/doctor/checks.js.map +1 -1
- package/build/lib/driver.d.ts +224 -27
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +232 -7
- package/build/lib/driver.js.map +1 -1
- package/build/lib/index.d.ts +1 -4
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +1 -13
- package/build/lib/index.js.map +1 -1
- package/build/lib/logger.js.map +1 -1
- package/build/lib/method-map.d.ts +0 -23
- package/build/lib/method-map.d.ts.map +1 -1
- package/build/lib/method-map.js +0 -11
- package/build/lib/method-map.js.map +1 -1
- package/build/lib/utils.d.ts +12 -0
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js +38 -2
- package/build/lib/utils.js.map +1 -1
- package/lib/commands/app-management.js +470 -145
- package/lib/commands/appearance.js +29 -36
- package/lib/commands/context/cache.js +29 -0
- package/lib/commands/context/exports.js +379 -0
- package/lib/commands/context/helpers.js +802 -0
- package/lib/commands/device/common.js +264 -0
- package/lib/commands/device/emulator-actions.js +194 -0
- package/lib/commands/device/emulator-console.js +24 -0
- package/lib/commands/device/utils.js +285 -0
- package/lib/commands/deviceidle.js +31 -44
- package/lib/commands/element.js +149 -142
- package/lib/commands/execute.js +86 -87
- package/lib/commands/file-actions.js +249 -222
- package/lib/commands/find.ts +13 -19
- package/lib/commands/geolocation.js +179 -0
- package/lib/commands/ime.js +53 -45
- package/lib/commands/intent.js +149 -91
- package/lib/commands/keyboard.js +114 -17
- package/lib/commands/lock/exports.js +139 -0
- package/lib/commands/lock/helpers.js +379 -0
- package/lib/commands/log.js +170 -166
- package/lib/commands/media-projection.js +75 -70
- package/lib/commands/memory.js +17 -29
- package/lib/commands/misc.js +94 -0
- package/lib/commands/network.js +209 -223
- package/lib/commands/performance.js +88 -73
- package/lib/commands/permissions.js +83 -84
- package/lib/commands/recordscreen.js +171 -170
- package/lib/commands/resources.js +96 -0
- package/lib/commands/shell.js +28 -42
- package/lib/commands/streamscreen.js +207 -206
- package/lib/commands/system-bars.js +76 -77
- package/lib/commands/time.js +36 -0
- package/lib/commands/touch.js +442 -346
- package/lib/commands/types.ts +123 -2
- package/lib/doctor/checks.js +24 -16
- package/lib/driver.ts +454 -12
- package/lib/index.ts +1 -13
- package/lib/logger.js +1 -1
- package/lib/method-map.js +0 -11
- package/lib/utils.js +40 -3
- package/package.json +1 -1
- package/build/lib/commands/actions.d.ts +0 -8
- package/build/lib/commands/actions.d.ts.map +0 -1
- package/build/lib/commands/actions.js +0 -207
- package/build/lib/commands/actions.js.map +0 -1
- package/build/lib/commands/alert.d.ts +0 -8
- package/build/lib/commands/alert.d.ts.map +0 -1
- package/build/lib/commands/alert.js +0 -29
- package/build/lib/commands/alert.js.map +0 -1
- package/build/lib/commands/context.d.ts +0 -10
- package/build/lib/commands/context.d.ts.map +0 -1
- package/build/lib/commands/context.js +0 -431
- package/build/lib/commands/context.js.map +0 -1
- package/build/lib/commands/emu-console.d.ts +0 -7
- package/build/lib/commands/emu-console.d.ts.map +0 -1
- package/build/lib/commands/emu-console.js +0 -27
- package/build/lib/commands/emu-console.js.map +0 -1
- package/build/lib/commands/general.d.ts +0 -9
- package/build/lib/commands/general.d.ts.map +0 -1
- package/build/lib/commands/general.js +0 -293
- package/build/lib/commands/general.js.map +0 -1
- package/build/lib/commands/index.d.ts +0 -28
- package/build/lib/commands/index.d.ts.map +0 -1
- package/build/lib/commands/index.js +0 -57
- package/build/lib/commands/index.js.map +0 -1
- package/build/lib/commands/mixins.d.ts +0 -747
- package/build/lib/commands/mixins.d.ts.map +0 -1
- package/build/lib/commands/mixins.js +0 -19
- package/build/lib/commands/mixins.js.map +0 -1
- package/build/lib/helpers/android.d.ts +0 -163
- package/build/lib/helpers/android.d.ts.map +0 -1
- package/build/lib/helpers/android.js +0 -818
- package/build/lib/helpers/android.js.map +0 -1
- package/build/lib/helpers/index.d.ts +0 -7
- package/build/lib/helpers/index.d.ts.map +0 -1
- package/build/lib/helpers/index.js +0 -29
- package/build/lib/helpers/index.js.map +0 -1
- package/build/lib/helpers/types.d.ts +0 -122
- package/build/lib/helpers/types.d.ts.map +0 -1
- package/build/lib/helpers/types.js +0 -3
- package/build/lib/helpers/types.js.map +0 -1
- package/build/lib/helpers/unlock.d.ts +0 -32
- package/build/lib/helpers/unlock.d.ts.map +0 -1
- package/build/lib/helpers/unlock.js +0 -273
- package/build/lib/helpers/unlock.js.map +0 -1
- package/build/lib/helpers/webview.d.ts +0 -74
- package/build/lib/helpers/webview.d.ts.map +0 -1
- package/build/lib/helpers/webview.js +0 -448
- package/build/lib/helpers/webview.js.map +0 -1
- package/lib/commands/actions.js +0 -244
- package/lib/commands/alert.js +0 -34
- package/lib/commands/context.js +0 -507
- package/lib/commands/emu-console.js +0 -31
- package/lib/commands/general.js +0 -343
- package/lib/commands/index.ts +0 -54
- package/lib/commands/mixins.ts +0 -976
- package/lib/helpers/android.ts +0 -1153
- package/lib/helpers/index.ts +0 -6
- package/lib/helpers/types.ts +0 -136
- package/lib/helpers/unlock.ts +0 -329
- package/lib/helpers/webview.ts +0 -610
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import {errors} from 'appium/driver';
|
|
4
4
|
import _ from 'lodash';
|
|
5
5
|
import {requireArgs} from '../utils';
|
|
6
|
-
import {mixin} from './mixins';
|
|
7
6
|
|
|
8
7
|
const WINDOW_TITLE_PATTERN = /^\s+Window\s#\d+\sWindow\{[0-9a-f]+\s\w+\s([\w-]+)\}:$/;
|
|
9
8
|
const FRAME_PATTERN = /\bm?[Ff]rame=\[([0-9.-]+),([0-9.-]+)\]\[([0-9.-]+),([0-9.-]+)\]/;
|
|
@@ -20,22 +19,86 @@ const DEFAULT_WINDOW_PROPERTIES = {
|
|
|
20
19
|
height: 0,
|
|
21
20
|
};
|
|
22
21
|
|
|
22
|
+
/**
|
|
23
|
+
* @this {import('../driver').AndroidDriver}
|
|
24
|
+
* @returns {Promise<StringRecord>}
|
|
25
|
+
*/
|
|
26
|
+
export async function getSystemBars() {
|
|
27
|
+
/** @type {string} */
|
|
28
|
+
let stdout;
|
|
29
|
+
try {
|
|
30
|
+
stdout = await this.adb.shell(['dumpsys', 'window', 'windows']);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Cannot retrieve system bars details. Original error: ${/** @type {Error} */ (e).message}`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return parseWindows.bind(this)(stdout);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @this {import('../driver').AndroidDriver}
|
|
41
|
+
* @param {import('./types').StatusBarCommandOpts} opts
|
|
42
|
+
* @returns {Promise<string>}
|
|
43
|
+
*/
|
|
44
|
+
export async function mobilePerformStatusBarCommand(opts) {
|
|
45
|
+
const {command} = requireArgs('command', opts);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* @param {string} cmd
|
|
50
|
+
* @param {(() => string[]|string)} [argsCallable]
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
const toStatusBarCommandCallable = (cmd, argsCallable) => async () =>
|
|
54
|
+
await this.adb.shell([
|
|
55
|
+
'cmd',
|
|
56
|
+
'statusbar',
|
|
57
|
+
cmd,
|
|
58
|
+
...(argsCallable ? _.castArray(argsCallable()) : []),
|
|
59
|
+
]);
|
|
60
|
+
const tileCommandArgsCallable = () =>
|
|
61
|
+
/** @type {string} */ (requireArgs('component', opts).component);
|
|
62
|
+
const statusBarCommands = _.fromPairs(
|
|
63
|
+
/** @type {const} */ ([
|
|
64
|
+
['expandNotifications', ['expand-notifications']],
|
|
65
|
+
['expandSettings', ['expand-settings']],
|
|
66
|
+
['collapse', ['collapse']],
|
|
67
|
+
['addTile', ['add-tile', tileCommandArgsCallable]],
|
|
68
|
+
['removeTile', ['remove-tile', tileCommandArgsCallable]],
|
|
69
|
+
['clickTile', ['click-tile', tileCommandArgsCallable]],
|
|
70
|
+
['getStatusIcons', ['get-status-icons']],
|
|
71
|
+
]).map(([name, args]) => [name, toStatusBarCommandCallable(args[0], args[1])]),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const action = statusBarCommands[command];
|
|
75
|
+
if (!action) {
|
|
76
|
+
throw new errors.InvalidArgumentError(
|
|
77
|
+
`The '${command}' status bar command is unknown. Only the following commands ` +
|
|
78
|
+
`are supported: ${_.keys(statusBarCommands)}`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
return await action();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// #region Internal helpers
|
|
85
|
+
|
|
23
86
|
/**
|
|
24
87
|
* Parses window properties from adb dumpsys output
|
|
25
88
|
*
|
|
89
|
+
* @this {import('../driver').AndroidDriver}
|
|
26
90
|
* @param {string} name The name of the window whose properties are being parsed
|
|
27
91
|
* @param {Array<string>} props The list of particular window property lines.
|
|
28
92
|
* Check the corresponding unit tests for more details on the input format.
|
|
29
|
-
* @param {import('@appium/types').AppiumLogger} [log] Logger instance
|
|
30
93
|
* @returns {WindowProperties} Parsed properties object
|
|
31
94
|
* @throws {Error} If there was an issue while parsing the properties string
|
|
32
95
|
*/
|
|
33
|
-
function parseWindowProperties(name, props
|
|
96
|
+
export function parseWindowProperties(name, props) {
|
|
34
97
|
const result = _.cloneDeep(DEFAULT_WINDOW_PROPERTIES);
|
|
35
98
|
const propLines = props.join('\n');
|
|
36
99
|
const frameMatch = FRAME_PATTERN.exec(propLines);
|
|
37
100
|
if (!frameMatch) {
|
|
38
|
-
log
|
|
101
|
+
this.log.debug(propLines);
|
|
39
102
|
throw new Error(`Cannot parse the frame size from '${name}' window properties`);
|
|
40
103
|
}
|
|
41
104
|
result.x = parseFloat(frameMatch[1]);
|
|
@@ -44,7 +107,7 @@ function parseWindowProperties(name, props, log) {
|
|
|
44
107
|
result.height = parseFloat(frameMatch[4]) - result.y;
|
|
45
108
|
const visibilityMatch = VIEW_VISIBILITY_PATTERN.exec(propLines);
|
|
46
109
|
if (!visibilityMatch) {
|
|
47
|
-
log
|
|
110
|
+
this.log.debug(propLines);
|
|
48
111
|
throw new Error(`Cannot parse the visibility value from '${name}' window properties`);
|
|
49
112
|
}
|
|
50
113
|
result.visible = parseInt(visibilityMatch[1], 16) === VIEW_VISIBLE;
|
|
@@ -54,14 +117,14 @@ function parseWindowProperties(name, props, log) {
|
|
|
54
117
|
/**
|
|
55
118
|
* Extracts status and navigation bar information from the window manager output.
|
|
56
119
|
*
|
|
120
|
+
* @this {import('../driver').AndroidDriver}
|
|
57
121
|
* @param {string} lines Output from dumpsys command.
|
|
58
122
|
* Check the corresponding unit tests for more details on the input format.
|
|
59
|
-
* @param {import('@appium/types').AppiumLogger} [log] Logger instance
|
|
60
123
|
* @return {StringRecord} An object containing two items where keys are statusBar and navigationBar,
|
|
61
124
|
* and values are corresponding WindowProperties objects
|
|
62
125
|
* @throws {Error} If no window properties could be parsed
|
|
63
126
|
*/
|
|
64
|
-
function parseWindows(lines
|
|
127
|
+
export function parseWindows(lines) {
|
|
65
128
|
/**
|
|
66
129
|
* @type {StringRecord}
|
|
67
130
|
*/
|
|
@@ -84,7 +147,7 @@ function parseWindows(lines, log) {
|
|
|
84
147
|
}
|
|
85
148
|
}
|
|
86
149
|
if (_.isEmpty(windows)) {
|
|
87
|
-
log
|
|
150
|
+
this.log.debug(lines);
|
|
88
151
|
throw new Error('Cannot parse any window information from the dumpsys output');
|
|
89
152
|
}
|
|
90
153
|
|
|
@@ -92,9 +155,9 @@ function parseWindows(lines, log) {
|
|
|
92
155
|
const result = {};
|
|
93
156
|
for (const [name, props] of _.toPairs(windows)) {
|
|
94
157
|
if (name.startsWith(STATUS_BAR_WINDOW_NAME_PREFIX)) {
|
|
95
|
-
result.statusBar = parseWindowProperties(name, props
|
|
158
|
+
result.statusBar = parseWindowProperties.bind(this)(name, props);
|
|
96
159
|
} else if (name.startsWith(NAVIGATION_BAR_WINDOW_NAME_PREFIX)) {
|
|
97
|
-
result.navigationBar = parseWindowProperties(name, props
|
|
160
|
+
result.navigationBar = parseWindowProperties.bind(this)(name, props);
|
|
98
161
|
}
|
|
99
162
|
}
|
|
100
163
|
const unmatchedWindows = /** @type {const} */ ([
|
|
@@ -102,81 +165,17 @@ function parseWindows(lines, log) {
|
|
|
102
165
|
['navigationBar', NAVIGATION_BAR_WINDOW_NAME_PREFIX],
|
|
103
166
|
]).filter(([name]) => _.isNil(result[name]));
|
|
104
167
|
for (const [window, namePrefix] of unmatchedWindows) {
|
|
105
|
-
log
|
|
168
|
+
this.log.info(
|
|
106
169
|
`No windows have been found whose title matches to ` +
|
|
107
170
|
`'${namePrefix}'. Assuming it is invisible. ` +
|
|
108
|
-
`Only the following windows are available: ${_.keys(windows)}
|
|
171
|
+
`Only the following windows are available: ${_.keys(windows)}`,
|
|
109
172
|
);
|
|
110
173
|
result[window] = _.cloneDeep(DEFAULT_WINDOW_PROPERTIES);
|
|
111
174
|
}
|
|
112
175
|
return result;
|
|
113
176
|
}
|
|
114
177
|
|
|
115
|
-
|
|
116
|
-
* @type {import('./mixins').SystemBarsMixin & ThisType<import('../driver').AndroidDriver>}
|
|
117
|
-
* @satisfies {import('@appium/types').ExternalDriver}
|
|
118
|
-
*/
|
|
119
|
-
const SystemBarsMixin = {
|
|
120
|
-
async getSystemBars() {
|
|
121
|
-
/** @type {string} */
|
|
122
|
-
let stdout;
|
|
123
|
-
try {
|
|
124
|
-
stdout = await this.adb.shell(['dumpsys', 'window', 'windows']);
|
|
125
|
-
} catch (e) {
|
|
126
|
-
throw new Error(
|
|
127
|
-
`Cannot retrieve system bars details. Original error: ${/** @type {Error} */ (e).message}`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
return parseWindows(stdout, this.log);
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
async mobilePerformStatusBarCommand(opts) {
|
|
134
|
-
const {command} = requireArgs('command', opts);
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
*
|
|
138
|
-
* @param {string} cmd
|
|
139
|
-
* @param {(() => string[]|string)} [argsCallable]
|
|
140
|
-
* @returns
|
|
141
|
-
*/
|
|
142
|
-
const toStatusBarCommandCallable = (cmd, argsCallable) => async () =>
|
|
143
|
-
await this.adb.shell([
|
|
144
|
-
'cmd',
|
|
145
|
-
'statusbar',
|
|
146
|
-
cmd,
|
|
147
|
-
...(argsCallable ? _.castArray(argsCallable()) : []),
|
|
148
|
-
]);
|
|
149
|
-
const tileCommandArgsCallable = () =>
|
|
150
|
-
/** @type {string} */ (requireArgs('component', opts).component);
|
|
151
|
-
const statusBarCommands = _.fromPairs(
|
|
152
|
-
/** @type {const} */ ([
|
|
153
|
-
['expandNotifications', ['expand-notifications']],
|
|
154
|
-
['expandSettings', ['expand-settings']],
|
|
155
|
-
['collapse', ['collapse']],
|
|
156
|
-
['addTile', ['add-tile', tileCommandArgsCallable]],
|
|
157
|
-
['removeTile', ['remove-tile', tileCommandArgsCallable]],
|
|
158
|
-
['clickTile', ['click-tile', tileCommandArgsCallable]],
|
|
159
|
-
['getStatusIcons', ['get-status-icons']],
|
|
160
|
-
]).map(([name, args]) => [name, toStatusBarCommandCallable(args[0], args[1])])
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
const action = statusBarCommands[command];
|
|
164
|
-
if (!action) {
|
|
165
|
-
throw new errors.InvalidArgumentError(
|
|
166
|
-
`The '${command}' status bar command is unknown. Only the following commands ` +
|
|
167
|
-
`are supported: ${_.keys(statusBarCommands)}`
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
return await action();
|
|
171
|
-
},
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
mixin(SystemBarsMixin);
|
|
175
|
-
|
|
176
|
-
// for unit tests
|
|
177
|
-
export {parseWindowProperties, parseWindows};
|
|
178
|
-
|
|
179
|
-
export default SystemBarsMixin;
|
|
178
|
+
// #endregion
|
|
180
179
|
|
|
181
180
|
/**
|
|
182
181
|
* @typedef {import('appium-adb').ADB} ADB
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import moment from 'moment';
|
|
2
|
+
|
|
3
|
+
const MOMENT_FORMAT_ISO8601 = 'YYYY-MM-DDTHH:mm:ssZ';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @this {import('../driver').AndroidDriver}
|
|
7
|
+
* @param {string} [format=MOMENT_FORMAT_ISO8601]
|
|
8
|
+
* @returns {Promise<string>}
|
|
9
|
+
*/
|
|
10
|
+
export async function getDeviceTime(format = MOMENT_FORMAT_ISO8601) {
|
|
11
|
+
this.log.debug(
|
|
12
|
+
'Attempting to capture android device date and time. ' + `The format specifier is '${format}'`,
|
|
13
|
+
);
|
|
14
|
+
const deviceTimestamp = (await this.adb.shell(['date', '+%Y-%m-%dT%T%z'])).trim();
|
|
15
|
+
this.log.debug(`Got device timestamp: ${deviceTimestamp}`);
|
|
16
|
+
const parsedTimestamp = moment.utc(deviceTimestamp, 'YYYY-MM-DDTHH:mm:ssZZ');
|
|
17
|
+
if (!parsedTimestamp.isValid()) {
|
|
18
|
+
this.log.warn('Cannot parse the returned timestamp. Returning as is');
|
|
19
|
+
return deviceTimestamp;
|
|
20
|
+
}
|
|
21
|
+
// @ts-expect-error private API
|
|
22
|
+
return parsedTimestamp.utcOffset(parsedTimestamp._tzm || 0).format(format);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @this {import('../driver').AndroidDriver}
|
|
27
|
+
* @param {import('./types').DeviceTimeOpts} [opts={}]
|
|
28
|
+
* @returns {Promise<string>}
|
|
29
|
+
*/
|
|
30
|
+
export async function mobileGetDeviceTime(opts = {}) {
|
|
31
|
+
return await this.getDeviceTime(opts.format);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {import('appium-adb').ADB} ADB
|
|
36
|
+
*/
|