appium-uiautomator2-driver 2.32.0 → 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.
Files changed (36) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/build/lib/commands/actions.js +10 -10
  3. package/build/lib/commands/actions.js.map +1 -1
  4. package/build/lib/commands/alert.js +3 -3
  5. package/build/lib/commands/alert.js.map +1 -1
  6. package/build/lib/commands/app-strings.d.ts.map +1 -1
  7. package/build/lib/commands/app-strings.js +3 -4
  8. package/build/lib/commands/app-strings.js.map +1 -1
  9. package/build/lib/commands/element.js +19 -19
  10. package/build/lib/commands/element.js.map +1 -1
  11. package/build/lib/commands/general.d.ts.map +1 -1
  12. package/build/lib/commands/general.js +17 -19
  13. package/build/lib/commands/general.js.map +1 -1
  14. package/build/lib/commands/gestures.js +11 -11
  15. package/build/lib/commands/gestures.js.map +1 -1
  16. package/build/lib/commands/touch.js +3 -3
  17. package/build/lib/commands/touch.js.map +1 -1
  18. package/build/lib/driver.d.ts +2 -4
  19. package/build/lib/driver.d.ts.map +1 -1
  20. package/build/lib/driver.js +36 -66
  21. package/build/lib/driver.js.map +1 -1
  22. package/build/lib/types.d.ts +7 -9
  23. package/build/lib/types.d.ts.map +1 -1
  24. package/build/lib/uiautomator2.d.ts +1 -1
  25. package/build/tsconfig.tsbuildinfo +1 -1
  26. package/lib/commands/actions.js +10 -10
  27. package/lib/commands/alert.js +3 -3
  28. package/lib/commands/app-strings.js +3 -4
  29. package/lib/commands/element.js +19 -19
  30. package/lib/commands/general.js +17 -18
  31. package/lib/commands/gestures.js +11 -11
  32. package/lib/commands/touch.js +3 -3
  33. package/lib/driver.ts +44 -76
  34. package/lib/types.ts +7 -11
  35. package/npm-shrinkwrap.json +9 -9
  36. package/package.json +3 -3
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?: UiAutomator2Server;
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 [pixelRatio, statBarHeight, viewportRect] = await B.all([
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
- return {pixelRatio, statBarHeight, viewportRect};
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 capsWithSessionAndDeviceInfo = {
539
- ...capsWithSessionInfo,
540
- ...(await this.getDeviceInfoFromUia2()),
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
- // now that everything has started successfully, turn on proxying so all
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
- if (this.uiautomator2) {
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.stopChromedriverProxies();
756
+ await this.uiautomator2.deleteSession();
770
757
  } catch (err) {
771
- this.log.warn(`Unable to stop ChromeDriver proxies: ${(err as Error).message}`);
758
+ this.log.warn(`Unable to proxy deleteSession to UiAutomator2: ${(err as Error).message}`);
772
759
  }
773
- if (this.jwpProxyActive) {
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');
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
- Uiautomator2DeviceInfo,
52
- Uiautomator2DeviceDetails {}
48
+ Partial<Uiautomator2DeviceDetails> {}
53
49
 
54
50
  export interface Uiautomator2Settings {
55
51
  ignoreUnimportantViews: boolean;
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "appium-uiautomator2-driver",
3
- "version": "2.32.0",
3
+ "version": "2.32.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "appium-uiautomator2-driver",
9
- "version": "2.32.0",
9
+ "version": "2.32.1",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
- "appium-adb": "^9.14.12",
13
- "appium-android-driver": "^7.1.0",
12
+ "appium-adb": "^10.0.0",
13
+ "appium-android-driver": "^7.1.3",
14
14
  "appium-chromedriver": "^5.6.5",
15
15
  "appium-uiautomator2-server": "^5.12.2",
16
16
  "asyncbox": "^2.3.1",
@@ -1147,7 +1147,7 @@
1147
1147
  }
1148
1148
  },
1149
1149
  "node_modules/appium-adb": {
1150
- "version": "9.14.12",
1150
+ "version": "10.0.0",
1151
1151
  "license": "Apache-2.0",
1152
1152
  "dependencies": {
1153
1153
  "@appium/support": "^4.0.0",
@@ -1175,10 +1175,10 @@
1175
1175
  }
1176
1176
  },
1177
1177
  "node_modules/appium-android-driver": {
1178
- "version": "7.1.0",
1178
+ "version": "7.1.3",
1179
1179
  "license": "Apache-2.0",
1180
1180
  "dependencies": {
1181
- "appium-adb": "^9.12.0",
1181
+ "appium-adb": "^10.0.0",
1182
1182
  "appium-chromedriver": "^5.5.1",
1183
1183
  "asyncbox": "^2.8.0",
1184
1184
  "axios": "^1.x",
@@ -1211,14 +1211,14 @@
1211
1211
  }
1212
1212
  },
1213
1213
  "node_modules/appium-chromedriver": {
1214
- "version": "5.6.13",
1214
+ "version": "5.6.14",
1215
1215
  "hasInstallScript": true,
1216
1216
  "license": "Apache-2.0",
1217
1217
  "dependencies": {
1218
1218
  "@appium/base-driver": "^9.1.0",
1219
1219
  "@appium/support": "^4.0.0",
1220
1220
  "@xmldom/xmldom": "^0.x",
1221
- "appium-adb": "^9.14.1",
1221
+ "appium-adb": "^10.0.0",
1222
1222
  "asyncbox": "^2.0.2",
1223
1223
  "axios": "^1.x",
1224
1224
  "bluebird": "^3.5.1",
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "automated testing",
8
8
  "android"
9
9
  ],
10
- "version": "2.32.0",
10
+ "version": "2.32.1",
11
11
  "bugs": {
12
12
  "url": "https://github.com/appium/appium-uiautomator2-driver/issues"
13
13
  },
@@ -62,8 +62,8 @@
62
62
  "singleQuote": true
63
63
  },
64
64
  "dependencies": {
65
- "appium-adb": "^9.14.12",
66
- "appium-android-driver": "^7.1.0",
65
+ "appium-adb": "^10.0.0",
66
+ "appium-android-driver": "^7.1.3",
67
67
  "appium-chromedriver": "^5.6.5",
68
68
  "appium-uiautomator2-server": "^5.12.2",
69
69
  "asyncbox": "^2.3.1",