appium-android-driver 12.4.7 → 12.4.8
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 +6 -0
- package/build/lib/commands/file-actions.d.ts +37 -19
- package/build/lib/commands/file-actions.d.ts.map +1 -1
- package/build/lib/commands/file-actions.js +44 -58
- package/build/lib/commands/file-actions.js.map +1 -1
- package/build/lib/commands/intent.d.ts +103 -107
- package/build/lib/commands/intent.d.ts.map +1 -1
- package/build/lib/commands/intent.js +103 -97
- package/build/lib/commands/intent.js.map +1 -1
- package/build/lib/commands/recordscreen.d.ts +25 -40
- package/build/lib/commands/recordscreen.d.ts.map +1 -1
- package/build/lib/commands/recordscreen.js +46 -63
- package/build/lib/commands/recordscreen.js.map +1 -1
- package/build/lib/commands/types.d.ts.map +1 -1
- package/build/lib/driver.d.ts +2 -1
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js.map +1 -1
- package/lib/commands/{file-actions.js → file-actions.ts} +88 -74
- package/lib/commands/intent.ts +422 -0
- package/lib/commands/{recordscreen.js → recordscreen.ts} +77 -73
- package/lib/commands/types.ts +17 -0
- package/lib/driver.ts +2 -1
- package/package.json +1 -1
- package/lib/commands/intent.js +0 -409
package/lib/commands/intent.js
DELETED
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import {errors} from 'appium/driver';
|
|
3
|
-
import {util} from '@appium/support';
|
|
4
|
-
|
|
5
|
-
const NO_VALUE_ARG_TYPE = 'sn';
|
|
6
|
-
const SUPPORTED_EXTRA_TYPES = [
|
|
7
|
-
's',
|
|
8
|
-
NO_VALUE_ARG_TYPE,
|
|
9
|
-
'z',
|
|
10
|
-
'i',
|
|
11
|
-
'l',
|
|
12
|
-
'f',
|
|
13
|
-
'u',
|
|
14
|
-
'cn',
|
|
15
|
-
'ia',
|
|
16
|
-
'ial',
|
|
17
|
-
'la',
|
|
18
|
-
'lal',
|
|
19
|
-
'fa',
|
|
20
|
-
'fal',
|
|
21
|
-
'sa',
|
|
22
|
-
'sal',
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated
|
|
27
|
-
* @this {import('../driver').AndroidDriver}
|
|
28
|
-
* @param {string} appPackage
|
|
29
|
-
* @param {string} appActivity
|
|
30
|
-
* @param {string} [appWaitPackage]
|
|
31
|
-
* @param {string} [appWaitActivity]
|
|
32
|
-
* @param {string} [intentAction]
|
|
33
|
-
* @param {string} [intentCategory]
|
|
34
|
-
* @param {string} [intentFlags]
|
|
35
|
-
* @param {string} [optionalIntentArguments]
|
|
36
|
-
* @param {boolean} [dontStopAppOnReset]
|
|
37
|
-
* @returns {Promise<void>}
|
|
38
|
-
*/
|
|
39
|
-
export async function startActivity(
|
|
40
|
-
appPackage,
|
|
41
|
-
appActivity,
|
|
42
|
-
appWaitPackage,
|
|
43
|
-
appWaitActivity,
|
|
44
|
-
intentAction,
|
|
45
|
-
intentCategory,
|
|
46
|
-
intentFlags,
|
|
47
|
-
optionalIntentArguments,
|
|
48
|
-
dontStopAppOnReset,
|
|
49
|
-
) {
|
|
50
|
-
this.log.debug(`Starting package '${appPackage}' and activity '${appActivity}'`);
|
|
51
|
-
|
|
52
|
-
// dontStopAppOnReset is both an argument here, and a desired capability
|
|
53
|
-
// if the argument is set, use it, otherwise use the cap
|
|
54
|
-
if (!util.hasValue(dontStopAppOnReset)) {
|
|
55
|
-
dontStopAppOnReset = !!this.opts.dontStopAppOnReset;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** @type {import('appium-adb').StartAppOptions} */
|
|
59
|
-
let args = {
|
|
60
|
-
pkg: appPackage,
|
|
61
|
-
activity: appActivity,
|
|
62
|
-
waitPkg: appWaitPackage || appPackage,
|
|
63
|
-
waitActivity: appWaitActivity || appActivity,
|
|
64
|
-
action: intentAction,
|
|
65
|
-
category: intentCategory,
|
|
66
|
-
flags: intentFlags,
|
|
67
|
-
optionalIntentArguments,
|
|
68
|
-
stopApp: !dontStopAppOnReset,
|
|
69
|
-
};
|
|
70
|
-
this._cachedActivityArgs = this._cachedActivityArgs || {};
|
|
71
|
-
this._cachedActivityArgs[`${args.waitPkg}/${args.waitActivity}`] = args;
|
|
72
|
-
await this.adb.startApp(args);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @this {import('../driver').AndroidDriver}
|
|
77
|
-
* @param {boolean} [wait] Set it to `true` if you want to block the method call
|
|
78
|
-
* until the activity manager's process returns the control to the system.
|
|
79
|
-
* false by default.
|
|
80
|
-
* @param {boolean} [stop] Set it to `true` to force stop the target
|
|
81
|
-
* app before starting the activity
|
|
82
|
-
* false by default.
|
|
83
|
-
* @param {string | number} [windowingMode] The windowing mode to launch the activity into.
|
|
84
|
-
* Check
|
|
85
|
-
* https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/WindowConfiguration.java
|
|
86
|
-
* for more details on possible windowing modes (constants starting with
|
|
87
|
-
* `WINDOWING_MODE_`).
|
|
88
|
-
* @param {string | number} [activityType] The activity type to launch the activity as.
|
|
89
|
-
* Check https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/app/WindowConfiguration.java
|
|
90
|
-
* for more details on possible activity types (constants starting with `ACTIVITY_TYPE_`).
|
|
91
|
-
* @param {number | string} [display] The display identifier to launch the activity into.
|
|
92
|
-
* @param {string} [user]
|
|
93
|
-
* @param {string} [intent]
|
|
94
|
-
* @param {string} [action]
|
|
95
|
-
* @param {string} [pkg]
|
|
96
|
-
* @param {string} [uri]
|
|
97
|
-
* @param {string} [mimeType]
|
|
98
|
-
* @param {string} [identifier]
|
|
99
|
-
* @param {string} [component]
|
|
100
|
-
* @param {string | string[]} [categories]
|
|
101
|
-
* @param {string[][]} [extras]
|
|
102
|
-
* @param {string} [flags]
|
|
103
|
-
* @returns {Promise<string>}
|
|
104
|
-
*/
|
|
105
|
-
export async function mobileStartActivity(
|
|
106
|
-
wait,
|
|
107
|
-
stop,
|
|
108
|
-
windowingMode,
|
|
109
|
-
activityType,
|
|
110
|
-
display,
|
|
111
|
-
user,
|
|
112
|
-
intent,
|
|
113
|
-
action,
|
|
114
|
-
pkg,
|
|
115
|
-
uri,
|
|
116
|
-
mimeType,
|
|
117
|
-
identifier,
|
|
118
|
-
component,
|
|
119
|
-
categories,
|
|
120
|
-
extras,
|
|
121
|
-
flags,
|
|
122
|
-
) {
|
|
123
|
-
const cmd = [
|
|
124
|
-
'am',
|
|
125
|
-
'start-activity',
|
|
126
|
-
];
|
|
127
|
-
if (!_.isNil(user)) {
|
|
128
|
-
cmd.push('--user', String(user));
|
|
129
|
-
}
|
|
130
|
-
if (wait) {
|
|
131
|
-
cmd.push('-W');
|
|
132
|
-
}
|
|
133
|
-
if (stop) {
|
|
134
|
-
cmd.push('-S');
|
|
135
|
-
}
|
|
136
|
-
if (!_.isNil(windowingMode)) {
|
|
137
|
-
cmd.push('--windowingMode', String(windowingMode));
|
|
138
|
-
}
|
|
139
|
-
if (!_.isNil(activityType)) {
|
|
140
|
-
cmd.push('--activityType', String(activityType));
|
|
141
|
-
}
|
|
142
|
-
if (!_.isNil(display)) {
|
|
143
|
-
cmd.push('--display', String(display));
|
|
144
|
-
}
|
|
145
|
-
cmd.push(...parseIntentSpec({
|
|
146
|
-
intent,
|
|
147
|
-
action,
|
|
148
|
-
package: pkg,
|
|
149
|
-
uri,
|
|
150
|
-
mimeType,
|
|
151
|
-
identifier,
|
|
152
|
-
component,
|
|
153
|
-
categories,
|
|
154
|
-
extras,
|
|
155
|
-
flags,
|
|
156
|
-
}));
|
|
157
|
-
return await this.adb.shell(cmd);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* @this {import('../driver').AndroidDriver}
|
|
162
|
-
* @param {string | number} [user] The user ID for which the broadcast is sent.
|
|
163
|
-
* The `current` alias assumes the current user ID.
|
|
164
|
-
* `all` by default.
|
|
165
|
-
* @param {string} [receiverPermission] Require receiver to hold the given permission.
|
|
166
|
-
* @param {boolean} [allowBackgroundActivityStarts] Whether the receiver may start activities even if in the background.
|
|
167
|
-
* @param {string} [intent]
|
|
168
|
-
* @param {string} [action]
|
|
169
|
-
* @param {string} [pkg]
|
|
170
|
-
* @param {string} [uri]
|
|
171
|
-
* @param {string} [mimeType]
|
|
172
|
-
* @param {string} [identifier]
|
|
173
|
-
* @param {string} [component]
|
|
174
|
-
* @param {string | string[]} [categories]
|
|
175
|
-
* @param {string[][]} [extras]
|
|
176
|
-
* @param {string} [flags]
|
|
177
|
-
* @returns {Promise<string>}
|
|
178
|
-
*/
|
|
179
|
-
export async function mobileBroadcast(
|
|
180
|
-
receiverPermission,
|
|
181
|
-
allowBackgroundActivityStarts,
|
|
182
|
-
user,
|
|
183
|
-
intent,
|
|
184
|
-
action,
|
|
185
|
-
pkg,
|
|
186
|
-
uri,
|
|
187
|
-
mimeType,
|
|
188
|
-
identifier,
|
|
189
|
-
component,
|
|
190
|
-
categories,
|
|
191
|
-
extras,
|
|
192
|
-
flags,
|
|
193
|
-
) {
|
|
194
|
-
const cmd = ['am', 'broadcast'];
|
|
195
|
-
if (!_.isNil(user)) {
|
|
196
|
-
cmd.push('--user', String(user));
|
|
197
|
-
}
|
|
198
|
-
if (receiverPermission) {
|
|
199
|
-
cmd.push('--receiver-permission', receiverPermission);
|
|
200
|
-
}
|
|
201
|
-
if (allowBackgroundActivityStarts) {
|
|
202
|
-
cmd.push('--allow-background-activity-starts');
|
|
203
|
-
}
|
|
204
|
-
cmd.push(...parseIntentSpec({
|
|
205
|
-
intent,
|
|
206
|
-
action,
|
|
207
|
-
package: pkg,
|
|
208
|
-
uri,
|
|
209
|
-
mimeType,
|
|
210
|
-
identifier,
|
|
211
|
-
component,
|
|
212
|
-
categories,
|
|
213
|
-
extras,
|
|
214
|
-
flags,
|
|
215
|
-
}));
|
|
216
|
-
return await this.adb.shell(cmd);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @this {import('../driver').AndroidDriver}
|
|
221
|
-
* @param {boolean} [foreground] Set it to `true` if your service must be started as foreground service.
|
|
222
|
-
* This option is ignored if the API level of the device under test is below
|
|
223
|
-
* 26 (Android 8).
|
|
224
|
-
* @param {string} [user]
|
|
225
|
-
* @param {string} [intent]
|
|
226
|
-
* @param {string} [action]
|
|
227
|
-
* @param {string} [pkg]
|
|
228
|
-
* @param {string} [uri]
|
|
229
|
-
* @param {string} [mimeType]
|
|
230
|
-
* @param {string} [identifier]
|
|
231
|
-
* @param {string} [component]
|
|
232
|
-
* @param {string | string[]} [categories]
|
|
233
|
-
* @param {string[][]} [extras]
|
|
234
|
-
* @param {string} [flags]
|
|
235
|
-
* @returns {Promise<string>}
|
|
236
|
-
*/
|
|
237
|
-
export async function mobileStartService(
|
|
238
|
-
foreground,
|
|
239
|
-
user,
|
|
240
|
-
intent,
|
|
241
|
-
action,
|
|
242
|
-
pkg,
|
|
243
|
-
uri,
|
|
244
|
-
mimeType,
|
|
245
|
-
identifier,
|
|
246
|
-
component,
|
|
247
|
-
categories,
|
|
248
|
-
extras,
|
|
249
|
-
flags,
|
|
250
|
-
) {
|
|
251
|
-
const cmd = ['am'];
|
|
252
|
-
cmd.push(foreground ? 'start-foreground-service' : 'start-service');
|
|
253
|
-
if (!_.isNil(user)) {
|
|
254
|
-
cmd.push('--user', String(user));
|
|
255
|
-
}
|
|
256
|
-
cmd.push(...parseIntentSpec({
|
|
257
|
-
intent,
|
|
258
|
-
action,
|
|
259
|
-
package: pkg,
|
|
260
|
-
uri,
|
|
261
|
-
mimeType,
|
|
262
|
-
identifier,
|
|
263
|
-
component,
|
|
264
|
-
categories,
|
|
265
|
-
extras,
|
|
266
|
-
flags,
|
|
267
|
-
}));
|
|
268
|
-
return await this.adb.shell(cmd);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* @this {import('../driver').AndroidDriver}
|
|
273
|
-
* @param {string} [user]
|
|
274
|
-
* @param {string} [intent]
|
|
275
|
-
* @param {string} [action]
|
|
276
|
-
* @param {string} [pkg]
|
|
277
|
-
* @param {string} [uri]
|
|
278
|
-
* @param {string} [mimeType]
|
|
279
|
-
* @param {string} [identifier]
|
|
280
|
-
* @param {string} [component]
|
|
281
|
-
* @param {string | string[]} [categories]
|
|
282
|
-
* @param {string[][]} [extras]
|
|
283
|
-
* @param {string} [flags]
|
|
284
|
-
* @returns {Promise<string>}
|
|
285
|
-
*/
|
|
286
|
-
export async function mobileStopService(
|
|
287
|
-
user,
|
|
288
|
-
intent,
|
|
289
|
-
action,
|
|
290
|
-
pkg,
|
|
291
|
-
uri,
|
|
292
|
-
mimeType,
|
|
293
|
-
identifier,
|
|
294
|
-
component,
|
|
295
|
-
categories,
|
|
296
|
-
extras,
|
|
297
|
-
flags,
|
|
298
|
-
) {
|
|
299
|
-
const cmd = [
|
|
300
|
-
'am',
|
|
301
|
-
'stop-service',
|
|
302
|
-
];
|
|
303
|
-
if (!_.isNil(user)) {
|
|
304
|
-
cmd.push('--user', String(user));
|
|
305
|
-
}
|
|
306
|
-
cmd.push(...parseIntentSpec({
|
|
307
|
-
intent,
|
|
308
|
-
action,
|
|
309
|
-
package: pkg,
|
|
310
|
-
uri,
|
|
311
|
-
mimeType,
|
|
312
|
-
identifier,
|
|
313
|
-
component,
|
|
314
|
-
categories,
|
|
315
|
-
extras,
|
|
316
|
-
flags,
|
|
317
|
-
}));
|
|
318
|
-
try {
|
|
319
|
-
return await this.adb.shell(cmd);
|
|
320
|
-
} catch (e) {
|
|
321
|
-
// https://github.com/appium/appium-uiautomator2-driver/issues/792
|
|
322
|
-
if (e.code === 255 && e.stderr?.includes('Service stopped')) {
|
|
323
|
-
return e.stderr;
|
|
324
|
-
}
|
|
325
|
-
throw e;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// #region Internal helpers
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
*
|
|
333
|
-
* @param {import('./types').IntentOpts} opts
|
|
334
|
-
* @returns {string[]}
|
|
335
|
-
*/
|
|
336
|
-
function parseIntentSpec(opts = {}) {
|
|
337
|
-
const {intent, action, uri, mimeType, identifier, categories, component, extras, flags} = opts;
|
|
338
|
-
const resultArgs = [];
|
|
339
|
-
if (intent) {
|
|
340
|
-
resultArgs.push(intent);
|
|
341
|
-
}
|
|
342
|
-
if (action) {
|
|
343
|
-
resultArgs.push('-a', action);
|
|
344
|
-
}
|
|
345
|
-
if (uri) {
|
|
346
|
-
resultArgs.push('-d', uri);
|
|
347
|
-
}
|
|
348
|
-
if (mimeType) {
|
|
349
|
-
resultArgs.push('-t', mimeType);
|
|
350
|
-
}
|
|
351
|
-
if (!_.isNil(identifier)) {
|
|
352
|
-
resultArgs.push('-i', identifier);
|
|
353
|
-
}
|
|
354
|
-
if (categories) {
|
|
355
|
-
if (_.isArray(categories)) {
|
|
356
|
-
resultArgs.push(..._.flatMap(categories.map((cName) => ['-c', cName])));
|
|
357
|
-
} else {
|
|
358
|
-
resultArgs.push('-c', categories);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
if (component) {
|
|
362
|
-
resultArgs.push('-n', component);
|
|
363
|
-
}
|
|
364
|
-
if (opts.package) {
|
|
365
|
-
resultArgs.push('-p', opts.package);
|
|
366
|
-
}
|
|
367
|
-
if (extras) {
|
|
368
|
-
if (!_.isArray(extras)) {
|
|
369
|
-
throw new errors.InvalidArgumentError(`'extras' must be an array`);
|
|
370
|
-
}
|
|
371
|
-
for (const item of extras) {
|
|
372
|
-
if (!_.isArray(item)) {
|
|
373
|
-
throw new errors.InvalidArgumentError(`Extra argument '${item}' must be an array`);
|
|
374
|
-
}
|
|
375
|
-
const [type, key, value] = item;
|
|
376
|
-
if (!_.includes(SUPPORTED_EXTRA_TYPES, type)) {
|
|
377
|
-
throw new errors.InvalidArgumentError(
|
|
378
|
-
`Extra argument type '${type}' is not known. ` +
|
|
379
|
-
`Supported intent argument types are: ${SUPPORTED_EXTRA_TYPES}`,
|
|
380
|
-
);
|
|
381
|
-
}
|
|
382
|
-
if (_.isEmpty(key) || (_.isString(key) && _.trim(key) === '')) {
|
|
383
|
-
throw new errors.InvalidArgumentError(
|
|
384
|
-
`Extra argument's key in '${JSON.stringify(item)}' must be a valid string identifier`,
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
if (type === NO_VALUE_ARG_TYPE) {
|
|
388
|
-
resultArgs.push(`--e${type}`, key);
|
|
389
|
-
} else if (_.isUndefined(value)) {
|
|
390
|
-
throw new errors.InvalidArgumentError(
|
|
391
|
-
`Intent argument type '${type}' in '${JSON.stringify(item)}' requires a ` +
|
|
392
|
-
`valid value to be provided`,
|
|
393
|
-
);
|
|
394
|
-
} else {
|
|
395
|
-
resultArgs.push(`--e${type}`, key, value);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
if (flags) {
|
|
400
|
-
resultArgs.push('-f', flags);
|
|
401
|
-
}
|
|
402
|
-
return resultArgs;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
// #endregion
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* @typedef {import('appium-adb').ADB} ADB
|
|
409
|
-
*/
|