How to use appium-android-driver - 10 common examples

To help you get started, we’ve selected a few appium-android-driver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github appium / appium-uiautomator2-driver / test / functional / commands / strings-e2e-specs.js View on Github external
afterEach(async function () {
      if (driver) {
        if (await adb.getApiLevel() > 23) {
          let [language, country] = initialLocale.split('-');
          await androidHelpers.ensureDeviceLocale(adb, language, country);
        } else {
          // This method is flakey in CI
          if (!process.env.CI) {
            await androidHelpers.ensureDeviceLocale(adb, null, initialLocale);
          }
        }

        await deleteSession();
      }
    });
github appium / appium-uiautomator2-driver / test / functional / commands / strings-e2e-specs.js View on Github external
afterEach(async function () {
      if (driver) {
        if (await adb.getApiLevel() > 23) {
          let [language, country] = initialLocale.split('-');
          await androidHelpers.ensureDeviceLocale(adb, language, country);
        } else {
          // This method is flakey in CI
          if (!process.env.CI) {
            await androidHelpers.ensureDeviceLocale(adb, null, initialLocale);
          }
        }

        await deleteSession();
      }
    });
github appium / appium-uiautomator2-driver / bin / install.js View on Github external
function doInstall () {
  // UiAutomator2 needs Java. Fail early if it doesn't exist
  let androidHelpers = require('appium-android-driver').androidHelpers;
  androidHelpers.getJavaVersion().then(function () {
    let tries = 0;
    function onErr (err) {
      console.log(err.message);
      let codeNotBuilt = err.message.indexOf('Cannot find module') !== -1;
      if (tries >= MAX_ATTEMPTS) {
        console.log("Tried too many times to install UiAutomator2, failing");
        console.log("Original error: " + err.message);
        throw new Error("Unable to import and run the installer. " +
                        "If you're running from source, run `gulp transpile` " +
                        "and then re-run `npm install`");
      }
      tries++;
      if (codeNotBuilt && !attemptedToBuild) {
        attemptedToBuild = true;
        console.log("Attempting to transpile setup code...");
        exec("npm run transpile", {cwd: path.resolve(__dirname, "..")}, function (err) {
github appium / appium-uiautomator2-driver / bin / install.js View on Github external
function doInstall () {
  // UiAutomator2 needs Java. Fail early if it doesn't exist
  let androidHelpers = require('appium-android-driver').androidHelpers;
  androidHelpers.getJavaVersion().then(function () {
    let tries = 0;
    function onErr (err) {
      console.log(err.message);
      let codeNotBuilt = err.message.indexOf('Cannot find module') !== -1;
      if (tries >= MAX_ATTEMPTS) {
        console.log("Tried too many times to install UiAutomator2, failing");
        console.log("Original error: " + err.message);
        throw new Error("Unable to import and run the installer. " +
                        "If you're running from source, run `gulp transpile` " +
                        "and then re-run `npm install`");
      }
      tries++;
      if (codeNotBuilt && !attemptedToBuild) {
        attemptedToBuild = true;
        console.log("Attempting to transpile setup code...");
github appium / appium-uiautomator2-server / gulpfile.js View on Github external
gulp.task('sign-apk', async function signApks () {
  // Signs the APK with the default Appium Certificate
  const adb = await androidHelpers.createADB({});
  const pathToApk = path.resolve('apks', `appium-uiautomator2-server-v${version}.apk`);
  return adb.sign(pathToApk);
});
github appium / appium-uiautomator2-driver / lib / driver.js View on Github external
async startUiAutomator2Session () {
    // get device udid for this session
    let {udid, emPort} = await helpers.getDeviceInfoFromCaps(this.opts);
    this.opts.udid = udid;
    this.opts.emPort = emPort;

    // now that we know our java version and device info, we can create our
    // ADB instance
    this.adb = await androidHelpers.createADB(this.opts);

    const apiLevel = await this.adb.getApiLevel();

    if (apiLevel < 21) {
      logger.errorAndThrow('UIAutomator2 is only supported since Android 5.0 (Lollipop). ' +
        'You could still use other supported backends in order to automate older Android versions.');
    }

    if (apiLevel >= 28) { // Android P
      logger.warn('Relaxing hidden api policy');
      await this.adb.setHiddenApiPolicy('1');
    }

    // check if we have to enable/disable gps before running the application
    if (util.hasValue(this.opts.gpsEnabled)) {
      if (this.isEmulator()) {
github appium / appium-uiautomator2-server / lib / scripts / sign-apk.js View on Github external
async function main () {
  // Signs the APK with the default Appium Certificate
  const adb = await androidHelpers.createADB({});
  const pathToApk = path.resolve('apks', `appium-uiautomator2-server-v${packageJson.version}.apk`);
  await adb.sign(pathToApk);
}
github appium / appium-uiautomator2-driver / test / functional / commands / language-e2e-specs.js View on Github external
after(async function () {
    if (driver) {
      if (await adb.getApiLevel() > 23) {
        let [language, country] = initialLocale.split('-');
        await androidHelpers.ensureDeviceLocale(driver.adb, language, country);
      } else {
        await androidHelpers.ensureDeviceLocale(driver.adb, null, initialLocale);
      }
      await deleteSession();
    }
  });
github appium / appium-uiautomator2-driver / test / functional / commands / language-e2e-specs.js View on Github external
after(async function () {
    if (driver) {
      if (await adb.getApiLevel() > 23) {
        let [language, country] = initialLocale.split('-');
        await androidHelpers.ensureDeviceLocale(driver.adb, language, country);
      } else {
        await androidHelpers.ensureDeviceLocale(driver.adb, null, initialLocale);
      }
      await deleteSession();
    }
  });
github appium / appium-uiautomator2-driver / lib / driver.js View on Github external
async deleteSession () {
    logger.debug('Deleting UiAutomator2 session');
    await androidHelpers.removeAllSessionWebSocketHandlers(this.server, this.sessionId);
    await this.mobileStopScreenStreaming();
    if (this.uiautomator2) {
      try {
        await this.stopChromedriverProxies();
      } catch (err) {
        logger.warn(`Unable to stop ChromeDriver proxies: ${err.message}`);
      }
      if (this.jwpProxyActive) {
        try {
          await this.uiautomator2.deleteSession();
        } catch (err) {
          logger.warn(`Unable to proxy deleteSession to UiAutomator2: ${err.message}`);
        }
      }
      this.uiautomator2 = null;
    }