appium-android-driver 5.14.7 → 6.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/build/index.d.ts +282 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js.map +1 -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/constraints.js +300 -0
- 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 +27 -20
- 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
|
@@ -1,27 +1,50 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import {retryInterval} from 'asyncbox';
|
|
1
3
|
import _ from 'lodash';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const commands = {};
|
|
4
|
+
import {requireArgs} from '../utils';
|
|
5
|
+
import {mixin} from './mixins';
|
|
6
6
|
|
|
7
7
|
const NETWORK_KEYS = [
|
|
8
|
-
[
|
|
9
|
-
|
|
8
|
+
[
|
|
9
|
+
'bucketStart',
|
|
10
|
+
'activeTime',
|
|
11
|
+
'rxBytes',
|
|
12
|
+
'rxPackets',
|
|
13
|
+
'txBytes',
|
|
14
|
+
'txPackets',
|
|
15
|
+
'operations',
|
|
16
|
+
'bucketDuration',
|
|
17
|
+
],
|
|
18
|
+
['st', 'activeTime', 'rb', 'rp', 'tb', 'tp', 'op', 'bucketDuration'],
|
|
10
19
|
];
|
|
11
|
-
const CPU_KEYS = ['user', 'kernel'];
|
|
20
|
+
const CPU_KEYS = /** @type {const} */ (['user', 'kernel']);
|
|
12
21
|
const BATTERY_KEYS = ['power'];
|
|
13
22
|
const MEMORY_KEYS = [
|
|
14
|
-
'totalPrivateDirty',
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
23
|
+
'totalPrivateDirty',
|
|
24
|
+
'nativePrivateDirty',
|
|
25
|
+
'dalvikPrivateDirty',
|
|
26
|
+
'eglPrivateDirty',
|
|
27
|
+
'glPrivateDirty',
|
|
28
|
+
'totalPss',
|
|
29
|
+
'nativePss',
|
|
30
|
+
'dalvikPss',
|
|
31
|
+
'eglPss',
|
|
32
|
+
'glPss',
|
|
33
|
+
'nativeHeapAllocatedSize',
|
|
34
|
+
'nativeHeapSize',
|
|
35
|
+
'nativeRss',
|
|
36
|
+
'dalvikRss',
|
|
37
|
+
'totalRss',
|
|
19
38
|
];
|
|
20
39
|
const SUPPORTED_PERFORMANCE_DATA_TYPES = Object.freeze({
|
|
21
|
-
cpuinfo:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
40
|
+
cpuinfo:
|
|
41
|
+
'the amount of cpu by user and kernel process - cpu information for applications on real devices and simulators',
|
|
42
|
+
memoryinfo:
|
|
43
|
+
'the amount of memory used by the process - memory information for applications on real devices and simulators',
|
|
44
|
+
batteryinfo:
|
|
45
|
+
'the remaining battery power - battery power information for applications on real devices and simulators',
|
|
46
|
+
networkinfo:
|
|
47
|
+
'the network statistics - network rx/tx information for applications on real devices and simulators',
|
|
25
48
|
});
|
|
26
49
|
const MEMINFO_TITLES = Object.freeze({
|
|
27
50
|
NATIVE: 'Native',
|
|
@@ -30,7 +53,7 @@ const MEMINFO_TITLES = Object.freeze({
|
|
|
30
53
|
GL: 'GL',
|
|
31
54
|
MTRACK: 'mtrack',
|
|
32
55
|
TOTAL: 'TOTAL',
|
|
33
|
-
HEAP: 'Heap'
|
|
56
|
+
HEAP: 'Heap',
|
|
34
57
|
});
|
|
35
58
|
const RETRY_PAUSE_MS = 1000;
|
|
36
59
|
|
|
@@ -40,16 +63,26 @@ const RETRY_PAUSE_MS = 1000;
|
|
|
40
63
|
* except 'TOTAL', which skips the second type name
|
|
41
64
|
* !!! valDict gets mutated
|
|
42
65
|
*/
|
|
43
|
-
|
|
66
|
+
// @ts-expect-error FIXME: type this properly
|
|
67
|
+
function parseMeminfoForApi19To29(entries, valDict) {
|
|
44
68
|
const [type, subType] = entries;
|
|
45
69
|
if (type === MEMINFO_TITLES.NATIVE && subType === MEMINFO_TITLES.HEAP) {
|
|
46
|
-
[
|
|
70
|
+
[
|
|
71
|
+
,
|
|
72
|
+
,
|
|
73
|
+
valDict.nativePss,
|
|
74
|
+
valDict.nativePrivateDirty,
|
|
75
|
+
,
|
|
76
|
+
,
|
|
77
|
+
valDict.nativeHeapSize,
|
|
78
|
+
valDict.nativeHeapAllocatedSize,
|
|
79
|
+
] = entries;
|
|
47
80
|
} else if (type === MEMINFO_TITLES.DALVIK && subType === MEMINFO_TITLES.HEAP) {
|
|
48
|
-
[
|
|
81
|
+
[, , valDict.dalvikPss, valDict.dalvikPrivateDirty] = entries;
|
|
49
82
|
} else if (type === MEMINFO_TITLES.EGL && subType === MEMINFO_TITLES.MTRACK) {
|
|
50
|
-
[
|
|
83
|
+
[, , valDict.eglPss, valDict.eglPrivateDirty] = entries;
|
|
51
84
|
} else if (type === MEMINFO_TITLES.GL && subType === MEMINFO_TITLES.MTRACK) {
|
|
52
|
-
[
|
|
85
|
+
[, , valDict.glPss, valDict.glPrivateDirty] = entries;
|
|
53
86
|
} else if (type === MEMINFO_TITLES.TOTAL && entries.length === 8) {
|
|
54
87
|
// there are two totals, and we only want the full listing, which has 8 entries
|
|
55
88
|
[, valDict.totalPss, valDict.totalPrivateDirty] = entries;
|
|
@@ -60,18 +93,26 @@ function parseMeminfoForApi19To29 (entries, valDict) {
|
|
|
60
93
|
* ['<System Type', '<pps>', '<shared dirty>', '<private dirty>', '<heap size>', '<heap alloc>', '<heap free>']
|
|
61
94
|
* !!! valDict gets mutated
|
|
62
95
|
*/
|
|
63
|
-
|
|
96
|
+
// @ts-expect-error FIXME: type this properly
|
|
97
|
+
function parseMeminfoForApiBelow19(entries, valDict) {
|
|
64
98
|
const type = entries[0];
|
|
65
99
|
if (type === MEMINFO_TITLES.NATIVE) {
|
|
66
|
-
[
|
|
100
|
+
[
|
|
101
|
+
,
|
|
102
|
+
valDict.nativePss,
|
|
103
|
+
,
|
|
104
|
+
valDict.nativePrivateDirty,
|
|
105
|
+
valDict.nativeHeapSize,
|
|
106
|
+
valDict.nativeHeapAllocatedSize,
|
|
107
|
+
] = entries;
|
|
67
108
|
} else if (type === MEMINFO_TITLES.DALVIK) {
|
|
68
|
-
[, valDict.dalvikPss
|
|
109
|
+
[, valDict.dalvikPss, , valDict.dalvikPrivateDirty] = entries;
|
|
69
110
|
} else if (type === MEMINFO_TITLES.EGL) {
|
|
70
|
-
[, valDict.eglPss
|
|
111
|
+
[, valDict.eglPss, , valDict.eglPrivateDirty] = entries;
|
|
71
112
|
} else if (type === MEMINFO_TITLES.GL) {
|
|
72
|
-
[, valDict.glPss
|
|
113
|
+
[, valDict.glPss, , valDict.glPrivateDirty] = entries;
|
|
73
114
|
} else if (type === MEMINFO_TITLES.TOTAL) {
|
|
74
|
-
[, valDict.totalPss
|
|
115
|
+
[, valDict.totalPss, , valDict.totalPrivateDirty] = entries;
|
|
75
116
|
}
|
|
76
117
|
}
|
|
77
118
|
|
|
@@ -80,36 +121,57 @@ function parseMeminfoForApiBelow19 (entries, valDict) {
|
|
|
80
121
|
* ['<System Type>', '<Memory Type>', <pss total>, <private dirty>, <private clean>, <swapPss dirty>, <rss total>, <heap size>, <heap alloc>, <heap free>]
|
|
81
122
|
* !!! valDict gets mutated
|
|
82
123
|
*/
|
|
83
|
-
|
|
124
|
+
// @ts-expect-error FIXME: type this properly
|
|
125
|
+
function parseMeminfoForApiAbove29(entries, valDict) {
|
|
84
126
|
const [type, subType] = entries;
|
|
85
127
|
if (type === MEMINFO_TITLES.NATIVE && subType === MEMINFO_TITLES.HEAP) {
|
|
86
|
-
[
|
|
128
|
+
[
|
|
129
|
+
,
|
|
130
|
+
,
|
|
131
|
+
valDict.nativePss,
|
|
132
|
+
valDict.nativePrivateDirty,
|
|
133
|
+
,
|
|
134
|
+
,
|
|
135
|
+
valDict.nativeRss,
|
|
136
|
+
valDict.nativeHeapSize,
|
|
137
|
+
valDict.nativeHeapAllocatedSize,
|
|
138
|
+
] = entries;
|
|
87
139
|
} else if (type === MEMINFO_TITLES.DALVIK && subType === MEMINFO_TITLES.HEAP) {
|
|
88
|
-
[
|
|
140
|
+
[, , valDict.dalvikPss, valDict.dalvikPrivateDirty, , , valDict.dalvikRss] = entries;
|
|
89
141
|
} else if (type === MEMINFO_TITLES.EGL && subType === MEMINFO_TITLES.MTRACK) {
|
|
90
|
-
[
|
|
142
|
+
[, , valDict.eglPss, valDict.eglPrivateDirty] = entries;
|
|
91
143
|
} else if (type === MEMINFO_TITLES.GL && subType === MEMINFO_TITLES.MTRACK) {
|
|
92
|
-
[
|
|
144
|
+
[, , valDict.glPss, valDict.glPrivateDirty] = entries;
|
|
93
145
|
} else if (type === MEMINFO_TITLES.TOTAL && entries.length === 9) {
|
|
94
146
|
// has 9 entries
|
|
95
|
-
[, valDict.totalPss, valDict.totalPrivateDirty
|
|
147
|
+
[, valDict.totalPss, valDict.totalPrivateDirty, , , valDict.totalRss] = entries;
|
|
96
148
|
}
|
|
97
149
|
}
|
|
98
150
|
|
|
99
|
-
|
|
151
|
+
/**
|
|
152
|
+
*
|
|
153
|
+
* @this {AndroidDriver}
|
|
154
|
+
* @param {string} packageName
|
|
155
|
+
* @param {number} retries
|
|
156
|
+
*/
|
|
157
|
+
async function getMemoryInfo(packageName, retries = 2) {
|
|
100
158
|
return await retryInterval(retries, RETRY_PAUSE_MS, async () => {
|
|
101
159
|
const cmd = [
|
|
102
|
-
'dumpsys',
|
|
103
|
-
'
|
|
160
|
+
'dumpsys',
|
|
161
|
+
'meminfo',
|
|
162
|
+
`'${packageName}'`,
|
|
163
|
+
'|',
|
|
164
|
+
'grep',
|
|
165
|
+
'-E',
|
|
104
166
|
`'${MEMINFO_TITLES.NATIVE}|${MEMINFO_TITLES.DALVIK}|${MEMINFO_TITLES.EGL}` +
|
|
105
|
-
|
|
167
|
+
`|${MEMINFO_TITLES.GL}|${MEMINFO_TITLES.TOTAL}'`,
|
|
106
168
|
];
|
|
107
|
-
const data = await this.adb.shell(cmd);
|
|
169
|
+
const data = await /** @type {ADB} */ (this.adb).shell(cmd);
|
|
108
170
|
if (!data) {
|
|
109
171
|
throw new Error('No data from dumpsys');
|
|
110
172
|
}
|
|
111
173
|
const valDict = {totalPrivateDirty: ''};
|
|
112
|
-
const apiLevel = await this.adb.getApiLevel();
|
|
174
|
+
const apiLevel = await /** @type {ADB} */ (this.adb).getApiLevel();
|
|
113
175
|
for (const line of data.split('\n')) {
|
|
114
176
|
const entries = line.trim().split(/\s+/).filter(Boolean);
|
|
115
177
|
if (apiLevel >= 30) {
|
|
@@ -122,25 +184,26 @@ async function getMemoryInfo (packageName, retries = 2) {
|
|
|
122
184
|
}
|
|
123
185
|
if (valDict.totalPrivateDirty && valDict.totalPrivateDirty !== 'nodex') {
|
|
124
186
|
const headers = _.clone(MEMORY_KEYS);
|
|
187
|
+
// @ts-expect-error FIXME: don't want to deal w/ it
|
|
125
188
|
const values = headers.map((header) => valDict[header]);
|
|
126
189
|
return [headers, values];
|
|
127
190
|
}
|
|
128
191
|
|
|
129
192
|
throw new Error(`Unable to parse memory data: '${data}'`);
|
|
130
193
|
});
|
|
131
|
-
}
|
|
194
|
+
}
|
|
132
195
|
|
|
133
196
|
/**
|
|
134
197
|
* @this {AndroidDriver}
|
|
135
198
|
* @param {number} retries
|
|
136
199
|
*/
|
|
137
|
-
async function getNetworkTrafficInfo
|
|
200
|
+
async function getNetworkTrafficInfo(retries = 2) {
|
|
138
201
|
return await retryInterval(retries, RETRY_PAUSE_MS, async () => {
|
|
139
202
|
let returnValue = [];
|
|
140
203
|
let bucketDuration, bucketStart, activeTime, rxBytes, rxPackets, txBytes, txPackets, operations;
|
|
141
204
|
|
|
142
205
|
let cmd = ['dumpsys', 'netstats'];
|
|
143
|
-
let data = await this.adb.shell(cmd);
|
|
206
|
+
let data = await /** @type {ADB} */ (this.adb).shell(cmd);
|
|
144
207
|
if (!data) throw new Error('No data from dumpsys'); //eslint-disable-line curly
|
|
145
208
|
|
|
146
209
|
// In case of network traffic information, it is different for the return data between emulator and real device.
|
|
@@ -200,7 +263,7 @@ async function getNetworkTrafficInfo (retries = 2) {
|
|
|
200
263
|
|
|
201
264
|
if (start >= 0) {
|
|
202
265
|
index = j;
|
|
203
|
-
returnValue[0] = [];
|
|
266
|
+
returnValue[0] = /** @type {string[]} */ ([]);
|
|
204
267
|
|
|
205
268
|
for (let k = 0; k < NETWORK_KEYS[j].length; ++k) {
|
|
206
269
|
returnValue[0][k] = NETWORK_KEYS[j][k];
|
|
@@ -270,16 +333,28 @@ async function getNetworkTrafficInfo (retries = 2) {
|
|
|
270
333
|
delimiter = data.indexOf('=', start + 1);
|
|
271
334
|
end = data.length;
|
|
272
335
|
operations = data.substring(delimiter + 1, end).trim();
|
|
273
|
-
|
|
274
336
|
}
|
|
275
337
|
}
|
|
276
|
-
returnValue[returnIndex++] = [
|
|
338
|
+
returnValue[returnIndex++] = [
|
|
339
|
+
bucketStart,
|
|
340
|
+
activeTime,
|
|
341
|
+
rxBytes,
|
|
342
|
+
rxPackets,
|
|
343
|
+
txBytes,
|
|
344
|
+
txPackets,
|
|
345
|
+
operations,
|
|
346
|
+
bucketDuration,
|
|
347
|
+
];
|
|
277
348
|
}
|
|
278
349
|
}
|
|
279
350
|
}
|
|
280
351
|
}
|
|
281
352
|
|
|
282
|
-
if (
|
|
353
|
+
if (
|
|
354
|
+
!_.isEqual(pendingBytes, '') &&
|
|
355
|
+
!_.isUndefined(pendingBytes) &&
|
|
356
|
+
!_.isEqual(pendingBytes, 'nodex')
|
|
357
|
+
) {
|
|
283
358
|
return returnValue;
|
|
284
359
|
} else {
|
|
285
360
|
throw new Error(`Unable to parse network traffic data: '${data}'`);
|
|
@@ -300,37 +375,48 @@ async function getNetworkTrafficInfo (retries = 2) {
|
|
|
300
375
|
* @this {AndroidDriver}
|
|
301
376
|
* @param {string} packageName The package name to get the CPU information.
|
|
302
377
|
* @param {number} retries The number of retry count.
|
|
303
|
-
* @returns {
|
|
378
|
+
* @returns {Promise<[typeof CPU_KEYS, [user: string, kernel: string]]>} The array of the parsed CPU upsage percentages.
|
|
304
379
|
* e.g. ['cpuinfo', ['14.3', '28.2']]
|
|
305
380
|
* '14.3' is usage by the user (%), '28.2' is usage by the kernel (%)
|
|
306
|
-
* @
|
|
381
|
+
* @throws {Error} If it failed to parse the result of dumpsys, or no package name exists.
|
|
307
382
|
*/
|
|
308
|
-
async function getCPUInfo
|
|
383
|
+
async function getCPUInfo(packageName, retries = 2) {
|
|
309
384
|
// TODO: figure out why this is
|
|
310
385
|
// sometimes, the function of 'adb.shell' fails. when I tested this function on the target of 'Galaxy Note5',
|
|
311
386
|
// adb.shell(dumpsys cpuinfo) returns cpu datas for other application packages, but I can't find the data for packageName.
|
|
312
387
|
// It usually fails 30 times and success for the next time,
|
|
313
388
|
// Since then, he has continued to succeed.
|
|
389
|
+
|
|
390
|
+
// @ts-expect-error retryInterval says it can return `null`, but it doesn't look like it actually can.
|
|
391
|
+
// FIXME: fix this in asyncbox
|
|
314
392
|
return await retryInterval(retries, RETRY_PAUSE_MS, async () => {
|
|
393
|
+
/** @type {string} */
|
|
315
394
|
let output;
|
|
316
395
|
try {
|
|
317
|
-
output = await this.adb.shell(['dumpsys', 'cpuinfo']);
|
|
396
|
+
output = await /** @type {ADB} */ (this.adb).shell(['dumpsys', 'cpuinfo']);
|
|
318
397
|
} catch (e) {
|
|
319
|
-
|
|
320
|
-
|
|
398
|
+
const err = /** @type {import('teen_process').ExecError} */ (e);
|
|
399
|
+
if (err.stderr) {
|
|
400
|
+
this.log.info(err.stderr);
|
|
321
401
|
}
|
|
322
402
|
throw e;
|
|
323
403
|
}
|
|
324
404
|
// `output` will be something like
|
|
325
405
|
// +0% 2209/io.appium.android.apis: 0.1% user + 0.2% kernel / faults: 70 minor
|
|
326
|
-
const usagesPattern =
|
|
327
|
-
|
|
406
|
+
const usagesPattern = new RegExp(
|
|
407
|
+
`^.+\\/${_.escapeRegExp(packageName)}:\\D+([\\d.]+)%\\s+user\\s+\\+\\s+([\\d.]+)%\\s+kernel`,
|
|
408
|
+
'm'
|
|
409
|
+
);
|
|
328
410
|
const match = usagesPattern.exec(output);
|
|
329
411
|
if (!match) {
|
|
330
412
|
this.log.debug(output);
|
|
331
|
-
throw new Error(
|
|
413
|
+
throw new Error(
|
|
414
|
+
`Unable to parse cpu usage data for '${packageName}'. Check the server log for more details`
|
|
415
|
+
);
|
|
332
416
|
}
|
|
333
|
-
|
|
417
|
+
const user = /** @type {string} */ (match[1]);
|
|
418
|
+
const kernel = /** @type {string} */ (match[2]);
|
|
419
|
+
return [CPU_KEYS, [user, kernel]];
|
|
334
420
|
});
|
|
335
421
|
}
|
|
336
422
|
|
|
@@ -338,10 +424,10 @@ async function getCPUInfo (packageName, retries = 2) {
|
|
|
338
424
|
* @this {AndroidDriver}
|
|
339
425
|
* @param {number} retries
|
|
340
426
|
*/
|
|
341
|
-
async function getBatteryInfo
|
|
427
|
+
async function getBatteryInfo(retries = 2) {
|
|
342
428
|
return await retryInterval(retries, RETRY_PAUSE_MS, async () => {
|
|
343
429
|
let cmd = ['dumpsys', 'battery', '|', 'grep', 'level'];
|
|
344
|
-
let data = await this.adb.shell(cmd);
|
|
430
|
+
let data = await /** @type {ADB} */ (this.adb).shell(cmd);
|
|
345
431
|
if (!data) throw new Error('No data from dumpsys'); //eslint-disable-line curly
|
|
346
432
|
|
|
347
433
|
let power = parseInt((data.split(':')[1] || '').trim(), 10);
|
|
@@ -354,83 +440,68 @@ async function getBatteryInfo (retries = 2) {
|
|
|
354
440
|
});
|
|
355
441
|
}
|
|
356
442
|
|
|
357
|
-
//
|
|
358
|
-
// returns the information type of the system state which is supported to read as like cpu, memory, network traffic, and battery.
|
|
359
|
-
// output - array like below
|
|
360
|
-
// [cpuinfo, batteryinfo, networkinfo, memoryinfo]
|
|
361
|
-
//
|
|
362
|
-
commands.getPerformanceDataTypes = function getPerformanceDataTypes () {
|
|
363
|
-
return _.keys(SUPPORTED_PERFORMANCE_DATA_TYPES);
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* @returns The information type of the system state which is supported to read as like cpu, memory, network traffic, and battery.
|
|
368
|
-
* input - (packageName) the package name of the application
|
|
369
|
-
* (dataType) the type of system state which wants to read. It should be one of the keys of the SUPPORTED_PERFORMANCE_DATA_TYPES
|
|
370
|
-
* (dataReadTimeout) the number of attempts to read
|
|
371
|
-
* output - table of the performance data, The first line of the table represents the type of data. The remaining lines represent the values of the data.
|
|
372
|
-
*
|
|
373
|
-
* in case of battery info : [[power], [23]]
|
|
374
|
-
* in case of memory info : [[totalPrivateDirty, nativePrivateDirty, dalvikPrivateDirty, eglPrivateDirty, glPrivateDirty, totalPss,
|
|
375
|
-
* nativePss, dalvikPss, eglPss, glPss, nativeHeapAllocatedSize, nativeHeapSize], [18360, 8296, 6132, null, null, 42588, 8406, 7024, null, null, 26519, 10344]]
|
|
376
|
-
* in case of network info : [[bucketStart, activeTime, rxBytes, rxPackets, txBytes, txPackets, operations, bucketDuration,],
|
|
377
|
-
* [1478091600000, null, 1099075, 610947, 928, 114362, 769, 0, 3600000], [1478095200000, null, 1306300, 405997, 509, 46359, 370, 0, 3600000]]
|
|
378
|
-
* in case of network info : [[st, activeTime, rb, rp, tb, tp, op, bucketDuration], [1478088000, null, null, 32115296, 34291, 2956805, 25705, 0, 3600],
|
|
379
|
-
* [1478091600, null, null, 2714683, 11821, 1420564, 12650, 0, 3600], [1478095200, null, null, 10079213, 19962, 2487705, 20015, 0, 3600],
|
|
380
|
-
* [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]]
|
|
381
|
-
* in case of cpu info : [[user, kernel], [0.9, 1.3]]
|
|
382
|
-
*/
|
|
383
|
-
commands.getPerformanceData = async function getPerformanceData (packageName, dataType, retries = 2) {
|
|
384
|
-
switch (_.toLower(dataType)) {
|
|
385
|
-
case 'batteryinfo':
|
|
386
|
-
return await getBatteryInfo.bind(this)(retries);
|
|
387
|
-
case 'cpuinfo':
|
|
388
|
-
return await getCPUInfo.bind(this)(packageName, retries);
|
|
389
|
-
case 'memoryinfo':
|
|
390
|
-
return await getMemoryInfo.bind(this)(packageName, retries);
|
|
391
|
-
case 'networkinfo':
|
|
392
|
-
return await getNetworkTrafficInfo.bind(this)(retries);
|
|
393
|
-
default:
|
|
394
|
-
throw new Error(`No performance data of type '${dataType}' found. ` +
|
|
395
|
-
`Only the following values are supported: ${JSON.stringify(SUPPORTED_PERFORMANCE_DATA_TYPES, ' ', 2)}`);
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
|
|
399
443
|
/**
|
|
400
|
-
* @
|
|
401
|
-
* @
|
|
402
|
-
* @property {'batteryinfo' | 'cpuinfo' | 'memoryinfo' | 'networkinfo'} dataType One of supported subsystem
|
|
403
|
-
* to fetch the data for.
|
|
444
|
+
* @type {import('./mixins').PerformanceMixin & ThisType<import('../driver').AndroidDriver>}
|
|
445
|
+
* @satisfies {import('@appium/types').ExternalDriver}
|
|
404
446
|
*/
|
|
447
|
+
const PerformanceMixin = {
|
|
448
|
+
async getPerformanceDataTypes() {
|
|
449
|
+
return /** @type {import('./types').PerformanceDataType[]} */ (
|
|
450
|
+
_.keys(SUPPORTED_PERFORMANCE_DATA_TYPES)
|
|
451
|
+
);
|
|
452
|
+
},
|
|
453
|
+
|
|
454
|
+
async getPerformanceData(packageName, dataType, retries = 2) {
|
|
455
|
+
let result;
|
|
456
|
+
switch (_.toLower(dataType)) {
|
|
457
|
+
case 'batteryinfo':
|
|
458
|
+
result = await getBatteryInfo.call(this, retries);
|
|
459
|
+
break;
|
|
460
|
+
case 'cpuinfo':
|
|
461
|
+
result = await getCPUInfo.call(this, packageName, retries);
|
|
462
|
+
break;
|
|
463
|
+
case 'memoryinfo':
|
|
464
|
+
result = await getMemoryInfo.call(this, packageName, retries);
|
|
465
|
+
break;
|
|
466
|
+
case 'networkinfo':
|
|
467
|
+
result = await getNetworkTrafficInfo.call(this, retries);
|
|
468
|
+
break;
|
|
469
|
+
default:
|
|
470
|
+
throw new Error(
|
|
471
|
+
`No performance data of type '${dataType}' found. ` +
|
|
472
|
+
`Only the following values are supported: ${JSON.stringify(
|
|
473
|
+
SUPPORTED_PERFORMANCE_DATA_TYPES,
|
|
474
|
+
[' '],
|
|
475
|
+
2
|
|
476
|
+
)}`
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
return /** @type {any[][]} */ (result);
|
|
480
|
+
},
|
|
405
481
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
* @param {PerformanceDataOptions} opts
|
|
411
|
-
* @returns {Promise<any[][]>} The output depends on the selected subsystem.
|
|
412
|
-
* It is orginized into a table, where the first row represent column names
|
|
413
|
-
* and the following rows represent the sampled data for each column.
|
|
414
|
-
* Example output for different data types:
|
|
415
|
-
* - batteryinfo: [[power], [23]]
|
|
416
|
-
* - memory info: [[totalPrivateDirty, nativePrivateDirty, dalvikPrivateDirty, eglPrivateDirty, glPrivateDirty, totalPss,
|
|
417
|
-
* nativePss, dalvikPss, eglPss, glPss, nativeHeapAllocatedSize, nativeHeapSize], [18360, 8296, 6132, null, null, 42588, 8406, 7024, null, null, 26519, 10344]]
|
|
418
|
-
* - networkinfo: [[bucketStart, activeTime, rxBytes, rxPackets, txBytes, txPackets, operations, bucketDuration,],
|
|
419
|
-
* [1478091600000, null, 1099075, 610947, 928, 114362, 769, 0, 3600000], [1478095200000, null, 1306300, 405997, 509, 46359, 370, 0, 3600000]]
|
|
420
|
-
*
|
|
421
|
-
* [[st, activeTime, rb, rp, tb, tp, op, bucketDuration], [1478088000, null, null, 32115296, 34291, 2956805, 25705, 0, 3600],
|
|
422
|
-
* [1478091600, null, null, 2714683, 11821, 1420564, 12650, 0, 3600], [1478095200, null, null, 10079213, 19962, 2487705, 20015, 0, 3600],
|
|
423
|
-
* [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]]
|
|
424
|
-
* - cpuinfo: [[user, kernel], [0.9, 1.3]]
|
|
425
|
-
*/
|
|
426
|
-
commands.mobileGetPerformanceData = async function mobileGetPerformanceData (opts = {}) {
|
|
427
|
-
const { packageName, dataType } = requireArgs(['packageName', 'dataType'], opts);
|
|
428
|
-
return await this.getPerformanceData(packageName, dataType);
|
|
482
|
+
async mobileGetPerformanceData(opts) {
|
|
483
|
+
const {packageName, dataType} = requireArgs(['packageName', 'dataType'], opts);
|
|
484
|
+
return await this.getPerformanceData(packageName, dataType);
|
|
485
|
+
},
|
|
429
486
|
};
|
|
430
487
|
|
|
488
|
+
mixin(PerformanceMixin);
|
|
489
|
+
|
|
431
490
|
export {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
491
|
+
BATTERY_KEYS,
|
|
492
|
+
CPU_KEYS,
|
|
493
|
+
MEMORY_KEYS,
|
|
494
|
+
NETWORK_KEYS,
|
|
495
|
+
SUPPORTED_PERFORMANCE_DATA_TYPES,
|
|
496
|
+
getBatteryInfo,
|
|
497
|
+
getCPUInfo,
|
|
498
|
+
getMemoryInfo,
|
|
499
|
+
getNetworkTrafficInfo,
|
|
435
500
|
};
|
|
436
|
-
|
|
501
|
+
|
|
502
|
+
export default PerformanceMixin;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* @typedef {import('../driver').AndroidDriver} AndroidDriver
|
|
506
|
+
* @typedef {import('appium-adb').ADB} ADB
|
|
507
|
+
*/
|