appium-uiautomator2-driver 2.31.4 → 2.32.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 +14 -0
- package/README.md +13 -0
- package/build/lib/commands/actions.js +10 -10
- package/build/lib/commands/actions.js.map +1 -1
- package/build/lib/commands/alert.js +3 -3
- package/build/lib/commands/alert.js.map +1 -1
- package/build/lib/commands/app-strings.d.ts.map +1 -1
- package/build/lib/commands/app-strings.js +3 -4
- package/build/lib/commands/app-strings.js.map +1 -1
- package/build/lib/commands/element.js +19 -19
- package/build/lib/commands/element.js.map +1 -1
- package/build/lib/commands/general.d.ts.map +1 -1
- package/build/lib/commands/general.js +17 -19
- package/build/lib/commands/general.js.map +1 -1
- package/build/lib/commands/gestures.js +11 -11
- package/build/lib/commands/gestures.js.map +1 -1
- package/build/lib/commands/touch.js +3 -3
- package/build/lib/commands/touch.js.map +1 -1
- package/build/lib/driver.d.ts +9 -4
- package/build/lib/driver.d.ts.map +1 -1
- package/build/lib/driver.js +36 -66
- package/build/lib/driver.js.map +1 -1
- package/build/lib/execute-method-map.d.ts +7 -0
- package/build/lib/execute-method-map.d.ts.map +1 -1
- package/build/lib/execute-method-map.js +7 -0
- package/build/lib/execute-method-map.js.map +1 -1
- package/build/lib/types.d.ts +7 -9
- package/build/lib/types.d.ts.map +1 -1
- package/build/lib/uiautomator2.d.ts +3 -3
- package/build/lib/uiautomator2.d.ts.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/commands/actions.js +10 -10
- package/lib/commands/alert.js +3 -3
- package/lib/commands/app-strings.js +3 -4
- package/lib/commands/element.js +19 -19
- package/lib/commands/general.js +17 -18
- package/lib/commands/gestures.js +11 -11
- package/lib/commands/touch.js +3 -3
- package/lib/driver.ts +44 -76
- package/lib/execute-method-map.ts +8 -0
- package/lib/types.ts +7 -11
- package/npm-shrinkwrap.json +173 -157
- package/package.json +8 -8
package/lib/driver.ts
CHANGED
|
@@ -25,10 +25,10 @@ import {executeMethodMap} from './execute-method-map';
|
|
|
25
25
|
import {APKS_EXTENSION, APK_EXTENSION} from './extensions';
|
|
26
26
|
import uiautomator2Helpers from './helpers';
|
|
27
27
|
import {newMethodMap} from './method-map';
|
|
28
|
+
import type { EmptyObject } from 'type-fest';
|
|
28
29
|
import type {
|
|
29
30
|
Uiautomator2Settings,
|
|
30
31
|
Uiautomator2DeviceDetails,
|
|
31
|
-
Uiautomator2DeviceInfo,
|
|
32
32
|
Uiautomator2DriverCaps,
|
|
33
33
|
Uiautomator2DriverOpts,
|
|
34
34
|
Uiautomator2SessionCaps,
|
|
@@ -174,7 +174,7 @@ class AndroidUiautomator2Driver
|
|
|
174
174
|
|
|
175
175
|
static executeMethodMap = executeMethodMap;
|
|
176
176
|
|
|
177
|
-
uiautomator2
|
|
177
|
+
uiautomator2: UiAutomator2Server;
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
180
|
* @privateRemarks moved from `this.opts`
|
|
@@ -278,11 +278,6 @@ class AndroidUiautomator2Driver
|
|
|
278
278
|
this.log.info(`Chrome-type package and activity are ${pkg} and ${activity}`);
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
// @ts-expect-error FIXME: missing CLI option?
|
|
282
|
-
if (this.opts.reboot) {
|
|
283
|
-
this.setAvdFromCapabilities(startSessionOpts);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
281
|
if (this.opts.app) {
|
|
287
282
|
// find and copy, or download and unzip an app url or path
|
|
288
283
|
this.opts.app = await this.helpers.configureApp(this.opts.app, [
|
|
@@ -317,12 +312,29 @@ class AndroidUiautomator2Driver
|
|
|
317
312
|
}
|
|
318
313
|
|
|
319
314
|
async getDeviceDetails(): Promise<Uiautomator2DeviceDetails> {
|
|
320
|
-
const [
|
|
315
|
+
const [
|
|
316
|
+
pixelRatio,
|
|
317
|
+
statBarHeight,
|
|
318
|
+
viewportRect,
|
|
319
|
+
{apiVersion, platformVersion, manufacturer, model, realDisplaySize, displayDensity},
|
|
320
|
+
] = await B.all([
|
|
321
321
|
this.getDevicePixelRatio(),
|
|
322
322
|
this.getStatusBarHeight(),
|
|
323
323
|
this.getViewPortRect(),
|
|
324
|
+
this.mobileGetDeviceInfo(),
|
|
324
325
|
]);
|
|
325
|
-
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
pixelRatio,
|
|
329
|
+
statBarHeight,
|
|
330
|
+
viewportRect,
|
|
331
|
+
deviceApiLevel: _.parseInt(apiVersion),
|
|
332
|
+
platformVersion,
|
|
333
|
+
deviceManufacturer: manufacturer,
|
|
334
|
+
deviceModel: model,
|
|
335
|
+
deviceScreenSize: realDisplaySize,
|
|
336
|
+
deviceScreenDensity: displayDensity,
|
|
337
|
+
};
|
|
326
338
|
}
|
|
327
339
|
|
|
328
340
|
override get driverData() {
|
|
@@ -337,27 +349,6 @@ class AndroidUiautomator2Driver
|
|
|
337
349
|
return {...sessionData, ...uia2Data};
|
|
338
350
|
}
|
|
339
351
|
|
|
340
|
-
setAvdFromCapabilities(caps: Uiautomator2StartSessionOpts) {
|
|
341
|
-
if (this.opts.avd) {
|
|
342
|
-
this.log.info('avd name defined, ignoring device name and platform version');
|
|
343
|
-
} else {
|
|
344
|
-
if (!caps.deviceName) {
|
|
345
|
-
this.log.errorAndThrow(
|
|
346
|
-
'avd or deviceName should be specified when reboot option is enables'
|
|
347
|
-
);
|
|
348
|
-
throw new Error(); // unreachable
|
|
349
|
-
}
|
|
350
|
-
if (!caps.platformVersion) {
|
|
351
|
-
this.log.errorAndThrow(
|
|
352
|
-
'avd or platformVersion should be specified when reboot option is enabled'
|
|
353
|
-
);
|
|
354
|
-
throw new Error(); // unreachable
|
|
355
|
-
}
|
|
356
|
-
const avdDevice = caps.deviceName.replace(/[^a-zA-Z0-9_.]/g, '-');
|
|
357
|
-
this.opts.avd = `${avdDevice}__${caps.platformVersion}`;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
352
|
async allocateSystemPort() {
|
|
362
353
|
const forwardPort = async (localPort: number) => {
|
|
363
354
|
this.log.debug(
|
|
@@ -534,11 +525,18 @@ class AndroidUiautomator2Driver
|
|
|
534
525
|
|
|
535
526
|
// launch UiAutomator2 and wait till its online and we have a session
|
|
536
527
|
await uiautomator2.startSession(capsWithSessionInfo);
|
|
528
|
+
// now that everything has started successfully, turn on proxying so all
|
|
529
|
+
// subsequent session requests go straight to/from uiautomator2
|
|
530
|
+
this.jwpProxyActive = true;
|
|
537
531
|
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
532
|
+
const deviceInfoPromise: Promise<Uiautomator2DeviceDetails|EmptyObject> = (async () => {
|
|
533
|
+
try {
|
|
534
|
+
return await this.getDeviceDetails();
|
|
535
|
+
} catch (e) {
|
|
536
|
+
this.log.warn(`Cannot fetch device details. Original error: ${e.message}`);
|
|
537
|
+
return {};
|
|
538
|
+
}
|
|
539
|
+
})();
|
|
542
540
|
|
|
543
541
|
// Unlock the device after the session is started.
|
|
544
542
|
if (!this.opts.skipUnlock) {
|
|
@@ -570,24 +568,7 @@ class AndroidUiautomator2Driver
|
|
|
570
568
|
await retryInterval(timeout / 500, 500, this.setContext.bind(this), viewName);
|
|
571
569
|
}
|
|
572
570
|
|
|
573
|
-
|
|
574
|
-
// subsequent session requests go straight to/from uiautomator2
|
|
575
|
-
this.jwpProxyActive = true;
|
|
576
|
-
|
|
577
|
-
return {...capsWithSessionAndDeviceInfo, ...(await this.getDeviceDetails())};
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
async getDeviceInfoFromUia2(): Promise<Uiautomator2DeviceInfo> {
|
|
581
|
-
const {apiVersion, platformVersion, manufacturer, model, realDisplaySize, displayDensity} =
|
|
582
|
-
await this.mobileGetDeviceInfo();
|
|
583
|
-
return {
|
|
584
|
-
deviceApiLevel: _.parseInt(apiVersion),
|
|
585
|
-
platformVersion,
|
|
586
|
-
deviceManufacturer: manufacturer,
|
|
587
|
-
deviceModel: model,
|
|
588
|
-
deviceScreenSize: realDisplaySize,
|
|
589
|
-
deviceScreenDensity: displayDensity,
|
|
590
|
-
};
|
|
571
|
+
return {...capsWithSessionInfo, ...(await deviceInfoPromise)};
|
|
591
572
|
}
|
|
592
573
|
|
|
593
574
|
async initUiAutomator2Server() {
|
|
@@ -668,7 +649,7 @@ class AndroidUiautomator2Driver
|
|
|
668
649
|
) {
|
|
669
650
|
if (
|
|
670
651
|
!this.opts.noSign &&
|
|
671
|
-
!(await this.adb!.checkApkCert(this.opts.app, this.opts.appPackage
|
|
652
|
+
!(await this.adb!.checkApkCert(this.opts.app, this.opts.appPackage!, {
|
|
672
653
|
requireDefaultCert: false,
|
|
673
654
|
}))
|
|
674
655
|
) {
|
|
@@ -764,22 +745,20 @@ class AndroidUiautomator2Driver
|
|
|
764
745
|
|
|
765
746
|
await androidHelpers.removeAllSessionWebSocketHandlers(this.server, this.sessionId);
|
|
766
747
|
|
|
767
|
-
|
|
748
|
+
try {
|
|
749
|
+
await this.stopChromedriverProxies();
|
|
750
|
+
} catch (err) {
|
|
751
|
+
this.log.warn(`Unable to stop ChromeDriver proxies: ${(err as Error).message}`);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
if (this.jwpProxyActive) {
|
|
768
755
|
try {
|
|
769
|
-
await this.
|
|
756
|
+
await this.uiautomator2.deleteSession();
|
|
770
757
|
} catch (err) {
|
|
771
|
-
this.log.warn(`Unable to
|
|
758
|
+
this.log.warn(`Unable to proxy deleteSession to UiAutomator2: ${(err as Error).message}`);
|
|
772
759
|
}
|
|
773
|
-
|
|
774
|
-
try {
|
|
775
|
-
await this.uiautomator2.deleteSession();
|
|
776
|
-
} catch (err) {
|
|
777
|
-
this.log.warn(`Unable to proxy deleteSession to UiAutomator2: ${(err as Error).message}`);
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
this.uiautomator2 = undefined;
|
|
760
|
+
this.jwpProxyActive = false;
|
|
781
761
|
}
|
|
782
|
-
this.jwpProxyActive = false;
|
|
783
762
|
|
|
784
763
|
if (this.adb) {
|
|
785
764
|
await B.all(
|
|
@@ -856,17 +835,6 @@ class AndroidUiautomator2Driver
|
|
|
856
835
|
this.log.info('Restoring hidden api policy to the device default configuration');
|
|
857
836
|
await this.adb.setDefaultHiddenApiPolicy(!!this.opts.ignoreHiddenApiPolicyError);
|
|
858
837
|
}
|
|
859
|
-
|
|
860
|
-
// @ts-expect-error unknown option
|
|
861
|
-
if (this.opts.reboot) {
|
|
862
|
-
const avdName = this.opts.avd!.replace('@', '');
|
|
863
|
-
this.log.debug(`Closing emulator '${avdName}'`);
|
|
864
|
-
try {
|
|
865
|
-
await this.adb.killEmulator(avdName);
|
|
866
|
-
} catch (err) {
|
|
867
|
-
this.log.warn(`Unable to close emulator: ${(err as Error).message}`);
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
838
|
}
|
|
871
839
|
if (this.mjpegStream) {
|
|
872
840
|
this.log.info('Closing MJPEG stream');
|
|
@@ -112,6 +112,14 @@ export const executeMethodMap = {
|
|
|
112
112
|
command: 'mobileStopLogsBroadcast',
|
|
113
113
|
},
|
|
114
114
|
|
|
115
|
+
'mobile: deviceidle': {
|
|
116
|
+
command: 'mobileDeviceidle',
|
|
117
|
+
params: {
|
|
118
|
+
required: ['action'],
|
|
119
|
+
optional: ['packages'],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
|
|
115
123
|
'mobile: acceptAlert': {
|
|
116
124
|
command: 'mobileAcceptAlert',
|
|
117
125
|
params: {
|
package/lib/types.ts
CHANGED
|
@@ -9,15 +9,6 @@ export type Uiautomator2DriverCaps = DriverCaps<Uiautomator2Constraints>;
|
|
|
9
9
|
|
|
10
10
|
export type W3CUiautomator2DriverCaps = W3CDriverCaps<Uiautomator2Constraints>;
|
|
11
11
|
|
|
12
|
-
export interface Uiautomator2DeviceInfo {
|
|
13
|
-
deviceApiLevel: number;
|
|
14
|
-
deviceScreenSize: string;
|
|
15
|
-
deviceScreenDensity: string;
|
|
16
|
-
deviceModel: string;
|
|
17
|
-
deviceManufacturer: string;
|
|
18
|
-
platformVersion: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
12
|
export interface Uiautomator2SessionInfo {
|
|
22
13
|
deviceName: string;
|
|
23
14
|
deviceUDID: string;
|
|
@@ -27,6 +18,12 @@ export interface Uiautomator2DeviceDetails {
|
|
|
27
18
|
pixelRatio: string;
|
|
28
19
|
statBarHeight: number;
|
|
29
20
|
viewportRect: RelativeRect;
|
|
21
|
+
deviceApiLevel: number;
|
|
22
|
+
deviceScreenSize: string;
|
|
23
|
+
deviceScreenDensity: string;
|
|
24
|
+
deviceModel: string;
|
|
25
|
+
deviceManufacturer: string;
|
|
26
|
+
platformVersion: string;
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
export interface Uiautomator2ServerInfo {
|
|
@@ -48,8 +45,7 @@ export interface Uiautomator2StartSessionOpts
|
|
|
48
45
|
export interface Uiautomator2SessionCaps
|
|
49
46
|
extends Uiautomator2ServerInfo,
|
|
50
47
|
Uiautomator2SessionInfo,
|
|
51
|
-
|
|
52
|
-
Uiautomator2DeviceDetails {}
|
|
48
|
+
Partial<Uiautomator2DeviceDetails> {}
|
|
53
49
|
|
|
54
50
|
export interface Uiautomator2Settings {
|
|
55
51
|
ignoreUnimportantViews: boolean;
|