appium-android-driver 5.0.5 → 5.0.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.
Files changed (40) hide show
  1. package/README.md +0 -1
  2. package/build/lib/commands/actions.js +16 -20
  3. package/build/lib/commands/app-management.js +10 -18
  4. package/build/lib/commands/context.js +43 -56
  5. package/build/lib/commands/coverage.js +2 -6
  6. package/build/lib/commands/element.js +3 -9
  7. package/build/lib/commands/emu-console.js +3 -5
  8. package/build/lib/commands/execute.js +3 -6
  9. package/build/lib/commands/file-actions.js +22 -29
  10. package/build/lib/commands/general.js +18 -30
  11. package/build/lib/commands/ime.js +8 -21
  12. package/build/lib/commands/network.js +14 -27
  13. package/build/lib/commands/performance.js +3 -6
  14. package/build/lib/commands/recordscreen.js +27 -38
  15. package/build/lib/commands/shell.js +6 -7
  16. package/build/lib/commands/streamscreen.js +29 -43
  17. package/build/lib/commands/system-bars.js +10 -16
  18. package/build/lib/commands/touch.js +4 -10
  19. package/build/lib/driver.js +36 -60
  20. package/build/lib/webview-helpers.js +3 -3
  21. package/lib/commands/actions.js +18 -19
  22. package/lib/commands/app-management.js +10 -11
  23. package/lib/commands/context.js +33 -34
  24. package/lib/commands/coverage.js +1 -4
  25. package/lib/commands/element.js +2 -3
  26. package/lib/commands/emu-console.js +2 -2
  27. package/lib/commands/execute.js +2 -3
  28. package/lib/commands/file-actions.js +31 -25
  29. package/lib/commands/general.js +16 -18
  30. package/lib/commands/ime.js +7 -8
  31. package/lib/commands/network.js +15 -16
  32. package/lib/commands/performance.js +2 -3
  33. package/lib/commands/recordscreen.js +23 -22
  34. package/lib/commands/shell.js +6 -6
  35. package/lib/commands/streamscreen.js +22 -23
  36. package/lib/commands/system-bars.js +11 -10
  37. package/lib/commands/touch.js +3 -4
  38. package/lib/driver.js +35 -36
  39. package/lib/webview-helpers.js +3 -1
  40. package/package.json +2 -2
package/lib/driver.js CHANGED
@@ -5,7 +5,6 @@ import {
5
5
  helpers, ensureNetworkSpeed,
6
6
  SETTINGS_HELPER_PKG_ID,
7
7
  } from './android-helpers';
8
- import log from './logger';
9
8
  import _ from 'lodash';
10
9
  import { DEFAULT_ADB_PORT } from 'appium-adb';
11
10
  import { fs, tempDir, util } from '@appium/support';
@@ -139,7 +138,7 @@ class AndroidDriver extends BaseDriver {
139
138
  });
140
139
 
141
140
  if (await this.adb.getApiLevel() >= 23) {
142
- log.warn("Consider setting 'automationName' capability to " +
141
+ this.log.warn("Consider setting 'automationName' capability to " +
143
142
  "'uiautomator2' on Android >= 6, since UIAutomator framework " +
144
143
  'is not maintained anymore by the OS vendor.');
145
144
  }
@@ -157,7 +156,7 @@ class AndroidDriver extends BaseDriver {
157
156
  } else if (this.appOnDevice) {
158
157
  // the app isn't an actual app file but rather something we want to
159
158
  // assume is on the device and just launch via the appPackage
160
- log.info(`App file was not listed, instead we're going to run ` +
159
+ this.log.info(`App file was not listed, instead we're going to run ` +
161
160
  `${this.opts.appPackage} directly on the device`);
162
161
  await this.checkPackagePresent();
163
162
  }
@@ -166,7 +165,7 @@ class AndroidDriver extends BaseDriver {
166
165
  // is set for emulators by calling adb.networkSpeed before running the app
167
166
  if (util.hasValue(this.opts.networkSpeed)) {
168
167
  if (!this.isEmulator()) {
169
- log.warn('Sorry, networkSpeed capability is only available for emulators');
168
+ this.log.warn('Sorry, networkSpeed capability is only available for emulators');
170
169
  } else {
171
170
  const networkSpeed = ensureNetworkSpeed(this.adb, this.opts.networkSpeed);
172
171
  await this.adb.networkSpeed(networkSpeed);
@@ -175,10 +174,10 @@ class AndroidDriver extends BaseDriver {
175
174
  // check if we have to enable/disable gps before running the application
176
175
  if (util.hasValue(this.opts.gpsEnabled)) {
177
176
  if (this.isEmulator()) {
178
- log.info(`Trying to ${this.opts.gpsEnabled ? 'enable' : 'disable'} gps location provider`);
177
+ this.log.info(`Trying to ${this.opts.gpsEnabled ? 'enable' : 'disable'} gps location provider`);
179
178
  await this.adb.toggleGPSLocationProvider(this.opts.gpsEnabled);
180
179
  } else {
181
- log.warn('Sorry! gpsEnabled capability is only available for emulators');
180
+ this.log.warn('Sorry! gpsEnabled capability is only available for emulators');
182
181
  }
183
182
  }
184
183
 
@@ -200,13 +199,13 @@ class AndroidDriver extends BaseDriver {
200
199
 
201
200
  setAvdFromCapabilities (caps) {
202
201
  if (this.opts.avd) {
203
- log.info('avd name defined, ignoring device name and platform version');
202
+ this.log.info('avd name defined, ignoring device name and platform version');
204
203
  } else {
205
204
  if (!caps.deviceName) {
206
- log.errorAndThrow('avd or deviceName should be specified when reboot option is enables');
205
+ this.log.errorAndThrow('avd or deviceName should be specified when reboot option is enables');
207
206
  }
208
207
  if (!caps.platformVersion) {
209
- log.errorAndThrow('avd or platformVersion should be specified when reboot option is enabled');
208
+ this.log.errorAndThrow('avd or platformVersion should be specified when reboot option is enabled');
210
209
  }
211
210
  let avdDevice = caps.deviceName.replace(/[^a-zA-Z0-9_.]/g, '-');
212
211
  this.opts.avd = `${avdDevice}__${caps.platformVersion}`;
@@ -229,7 +228,7 @@ class AndroidDriver extends BaseDriver {
229
228
  }
230
229
 
231
230
  async startAndroidSession () {
232
- log.info(`Starting Android session`);
231
+ this.log.info(`Starting Android session`);
233
232
  // set up the device to run on (real or emulator, etc)
234
233
  this.defaultIME = await helpers.initDevice(this.adb, this.opts);
235
234
 
@@ -245,15 +244,15 @@ class AndroidDriver extends BaseDriver {
245
244
  if (await this.adb.isAnimationOn()) {
246
245
  if (await this.adb.getApiLevel() >= 28) { // API level 28 is Android P
247
246
  // Don't forget to reset the relaxing in delete session
248
- log.warn('Relaxing hidden api policy to manage animation scale');
247
+ this.log.warn('Relaxing hidden api policy to manage animation scale');
249
248
  await this.adb.setHiddenApiPolicy('1', !!this.opts.ignoreHiddenApiPolicyError);
250
249
  }
251
250
 
252
- log.info('Disabling window animation as it is requested by "disableWindowAnimation" capability');
251
+ this.log.info('Disabling window animation as it is requested by "disableWindowAnimation" capability');
253
252
  await this.adb.setAnimationState(false);
254
253
  this._wasWindowAnimationDisabled = true;
255
254
  } else {
256
- log.info('Window animation is already disabled');
255
+ this.log.info('Window animation is already disabled');
257
256
  }
258
257
  }
259
258
 
@@ -292,7 +291,7 @@ class AndroidDriver extends BaseDriver {
292
291
  }
293
292
 
294
293
  if (util.hasValue(this.opts.orientation)) {
295
- log.debug(`Setting initial orientation to '${this.opts.orientation}'`);
294
+ this.addManagedDriverlog.debug(`Setting initial orientation to '${this.opts.orientation}'`);
296
295
  await this.setOrientation(this.opts.orientation);
297
296
  }
298
297
 
@@ -304,7 +303,7 @@ class AndroidDriver extends BaseDriver {
304
303
  let viewName = this.defaultWebviewName();
305
304
  let timeout = (this.opts.autoWebviewTimeout) || 2000;
306
305
 
307
- log.info(`Setting auto webview to context '${viewName}' with timeout ${timeout}ms`);
306
+ this.log.info(`Setting auto webview to context '${viewName}' with timeout ${timeout}ms`);
308
307
 
309
308
  // try every 500ms until timeout is over
310
309
  await retryInterval(timeout / 500, 500, async () => {
@@ -338,7 +337,7 @@ class AndroidDriver extends BaseDriver {
338
337
  try {
339
338
  otherApps = helpers.parseArray(this.opts.otherApps);
340
339
  } catch (e) {
341
- log.errorAndThrow(`Could not parse "otherApps" capability: ${e.message}`);
340
+ this.log.errorAndThrow(`Could not parse "otherApps" capability: ${e.message}`);
342
341
  }
343
342
  otherApps = await B.all(otherApps.map((app) => this.helpers.configureApp(app, APP_EXTENSION)));
344
343
  await helpers.installOtherApks(otherApps, this.adb, this.opts);
@@ -347,9 +346,9 @@ class AndroidDriver extends BaseDriver {
347
346
  // install app
348
347
  if (!this.opts.app) {
349
348
  if (this.opts.fullReset) {
350
- log.errorAndThrow('Full reset requires an app capability, use fastReset if app is not provided');
349
+ this.log.errorAndThrow('Full reset requires an app capability, use fastReset if app is not provided');
351
350
  }
352
- log.debug('No app capability. Assuming it is already on the device');
351
+ this.log.debug('No app capability. Assuming it is already on the device');
353
352
  if (this.opts.fastReset) {
354
353
  await helpers.resetApp(this.adb, this.opts);
355
354
  }
@@ -372,16 +371,16 @@ class AndroidDriver extends BaseDriver {
372
371
  }
373
372
 
374
373
  async checkAppPresent () {
375
- log.debug('Checking whether app is actually present');
374
+ this.log.debug('Checking whether app is actually present');
376
375
  if (!(await fs.exists(this.opts.app))) {
377
- log.errorAndThrow(`Could not find app apk at ${this.opts.app}`);
376
+ this.log.errorAndThrow(`Could not find app apk at ${this.opts.app}`);
378
377
  }
379
378
  }
380
379
 
381
380
  async checkPackagePresent () {
382
- log.debug('Checking whether package is present on the device');
381
+ this.log.debug('Checking whether package is present on the device');
383
382
  if (!(await this.adb.shell(['pm', 'list', 'packages', this.opts.appPackage]))) {
384
- log.errorAndThrow(`Could not find package ${this.opts.appPackage} on the device`);
383
+ this.log.errorAndThrow(`Could not find package ${this.opts.appPackage} on the device`);
385
384
  }
386
385
  }
387
386
 
@@ -391,7 +390,7 @@ class AndroidDriver extends BaseDriver {
391
390
  }
392
391
 
393
392
  async deleteSession () {
394
- log.debug('Shutting down Android driver');
393
+ this.log.debug('Shutting down Android driver');
395
394
 
396
395
  try {
397
396
  if (!_.isEmpty(this._screenRecordingProperties)) {
@@ -409,7 +408,7 @@ class AndroidDriver extends BaseDriver {
409
408
  // certain cleanup we only care to do if the bootstrap was ever run
410
409
  await this.stopChromedriverProxies();
411
410
  if (this.opts.unicodeKeyboard && this.opts.resetKeyboard && this.defaultIME) {
412
- log.debug(`Resetting IME to ${this.defaultIME}`);
411
+ this.log.debug(`Resetting IME to ${this.defaultIME}`);
413
412
  await this.adb.setIME(this.defaultIME);
414
413
  }
415
414
  if (!this.isChromeSession && !this.opts.dontStopAppOnReset) {
@@ -422,7 +421,7 @@ class AndroidDriver extends BaseDriver {
422
421
  await this.bootstrap.shutdown();
423
422
  this.bootstrap = null;
424
423
  } else {
425
- log.debug("Called deleteSession but bootstrap wasn't active");
424
+ this.log.debug("Called deleteSession but bootstrap wasn't active");
426
425
  }
427
426
  // some cleanup we want to do regardless, in case we are shutting down
428
427
  // mid-startup
@@ -431,29 +430,29 @@ class AndroidDriver extends BaseDriver {
431
430
  await this.adb.forceStop('io.appium.unlock');
432
431
  }
433
432
  if (this._wasWindowAnimationDisabled) {
434
- log.info('Restoring window animation state');
433
+ this.log.info('Restoring window animation state');
435
434
  await this.adb.setAnimationState(true);
436
435
 
437
436
  // This was necessary to change animation scale over Android P. We must reset the policy for the security.
438
437
  if (await this.adb.getApiLevel() >= 28) {
439
- log.info('Restoring hidden api policy to the device default configuration');
438
+ this.log.info('Restoring hidden api policy to the device default configuration');
440
439
  await this.adb.setDefaultHiddenApiPolicy(!!this.opts.ignoreHiddenApiPolicyError);
441
440
  }
442
441
  }
443
442
 
444
443
  if (this.opts.reboot) {
445
444
  let avdName = this.opts.avd.replace('@', '');
446
- log.debug(`closing emulator '${avdName}'`);
445
+ this.log.debug(`closing emulator '${avdName}'`);
447
446
  await this.adb.killEmulator(avdName);
448
447
  }
449
448
  }
450
449
 
451
450
  async setSharedPreferences () {
452
451
  let sharedPrefs = this.opts.sharedPreferences;
453
- log.info('Trying to set shared preferences');
452
+ this.log.info('Trying to set shared preferences');
454
453
  let name = sharedPrefs.name;
455
454
  if (_.isUndefined(name)) {
456
- log.warn(`Skipping setting Shared preferences, name is undefined: ${JSON.stringify(sharedPrefs)}`);
455
+ this.log.warn(`Skipping setting Shared preferences, name is undefined: ${JSON.stringify(sharedPrefs)}`);
457
456
  return false;
458
457
  }
459
458
  let remotePath = `/data/data/${this.opts.appPackage}/shared_prefs`;
@@ -461,19 +460,19 @@ class AndroidDriver extends BaseDriver {
461
460
  let localPath = `/tmp/${name}.xml`;
462
461
  let builder = this.getPrefsBuilder();
463
462
  builder.build(sharedPrefs.prefs);
464
- log.info(`Creating temporary shared preferences: ${localPath}`);
463
+ this.log.info(`Creating temporary shared preferences: ${localPath}`);
465
464
  builder.toFile(localPath);
466
- log.info(`Creating shared_prefs remote folder: ${remotePath}`);
465
+ this.log.info(`Creating shared_prefs remote folder: ${remotePath}`);
467
466
  await this.adb.shell(['mkdir', '-p', remotePath]);
468
- log.info(`Pushing shared_prefs to ${remoteFile}`);
467
+ this.log.info(`Pushing shared_prefs to ${remoteFile}`);
469
468
  await this.adb.push(localPath, remoteFile);
470
469
  try {
471
- log.info(`Trying to remove shared preferences temporary file`);
470
+ this.log.info(`Trying to remove shared preferences temporary file`);
472
471
  if (await fs.exists(localPath)) {
473
472
  await fs.unlink(localPath);
474
473
  }
475
474
  } catch (e) {
476
- log.warn(`Error trying to remove temporary file ${localPath}`);
475
+ this.log.warn(`Error trying to remove temporary file ${localPath}`);
477
476
  }
478
477
  return true;
479
478
  }
@@ -490,7 +489,7 @@ class AndroidDriver extends BaseDriver {
490
489
  return false;
491
490
  }
492
491
  if ((!caps.browserName || !helpers.isChromeBrowser(caps.browserName)) && !caps.app && !caps.appPackage) {
493
- log.errorAndThrow('The desired capabilities must include either an app, appPackage or browserName');
492
+ this.log.errorAndThrow('The desired capabilities must include either an app, appPackage or browserName');
494
493
  }
495
494
  return helpers.validateDesiredCaps(caps);
496
495
  }
@@ -478,7 +478,9 @@ helpers.getWebviewDetails = function getWebviewDetails (adb, webview) {
478
478
  helpers.createChromedriverCaps = function createChromedriverCaps (opts, deviceId, webViewDetails) {
479
479
  const caps = { chromeOptions: {} };
480
480
 
481
- const androidPackage = opts.chromeOptions?.androidPackage || opts.appPackage;
481
+ const androidPackage = opts.chromeOptions?.androidPackage
482
+ || opts.appPackage
483
+ || webViewDetails?.info?.['Android-Package'];
482
484
  if (androidPackage) {
483
485
  // chromedriver raises an invalid argument error when androidPackage is 'null'
484
486
  caps.chromeOptions.androidPackage = androidPackage;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "mobile",
10
10
  "mobile testing"
11
11
  ],
12
- "version": "5.0.5",
12
+ "version": "5.0.8",
13
13
  "author": "appium",
14
14
  "license": "Apache-2.0",
15
15
  "repository": {
@@ -35,7 +35,7 @@
35
35
  "bootstrap/bin/AppiumBootstrap.jar"
36
36
  ],
37
37
  "dependencies": {
38
- "@appium/base-driver": "^8.0.0",
38
+ "@appium/base-driver": "^8.3.0",
39
39
  "@appium/support": "^2.55.3",
40
40
  "@babel/runtime": "^7.0.0",
41
41
  "appium-adb": "^9.0.0",