How to use this.adb.setAnimationState method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

driver.js

Source:driver.js Github

copy

Full Screen

...219          log.warn('Relaxing hidden api policy to manage animation scale');220          await this.adb.setHiddenApiPolicy('1', !!this.opts.ignoreHiddenApiPolicyError);221        }222        log.info('Disabling window animation as it is requested by "disableWindowAnimation" capability');223        await this.adb.setAnimationState(false);224        this._wasWindowAnimationDisabled = true;225      } else {226        log.info('Window animation is already disabled');227      }228    }229    // If the user sets autoLaunch to false, they are responsible for initAUT() and startAUT()230    if (this.opts.autoLaunch) {231      // set up app under test232      await this.initAUT();233    }234    // start UiAutomator235    this.bootstrap = new helpers.bootstrap(this.adb, this.opts.bootstrapPort, this.opts.websocket);236    await this.bootstrap.start(this.opts.appPackage, this.opts.disableAndroidWatchers, this.opts.acceptSslCerts);237    // handling unexpected shutdown238    this.bootstrap.onUnexpectedShutdown.catch(async (err) => { // eslint-disable-line promise/prefer-await-to-callbacks239      if (!this.bootstrap.ignoreUnexpectedShutdown) {240        await this.startUnexpectedShutdown(err);241      }242    });243    if (!this.opts.skipUnlock) {244      // Let's try to unlock the device245      await helpers.unlock(this, this.adb, this.caps);246    }247    // Set CompressedLayoutHierarchy on the device based on current settings object248    // this has to happen _after_ bootstrap is initialized249    if (this.opts.ignoreUnimportantViews) {250      await this.settings.update({ignoreUnimportantViews: this.opts.ignoreUnimportantViews});251    }252    if (this.isChromeSession) {253      // start a chromedriver session and proxy to it254      await this.startChromeSession();255    } else {256      if (this.opts.autoLaunch) {257        // start app258        await this.startAUT();259      }260    }261    if (util.hasValue(this.opts.orientation)) {262      log.debug(`Setting initial orientation to '${this.opts.orientation}'`);263      await this.setOrientation(this.opts.orientation);264    }265    await this.initAutoWebview();266  }267  async initAutoWebview () {268    if (this.opts.autoWebview) {269      let viewName = this.defaultWebviewName();270      let timeout = (this.opts.autoWebviewTimeout) || 2000;271      log.info(`Setting auto webview to context '${viewName}' with timeout ${timeout}ms`);272      // try every 500ms until timeout is over273      await retryInterval(timeout / 500, 500, async () => {274        await this.setContext(viewName);275      });276    }277  }278  async initAUT () {279    // populate appPackage, appActivity, appWaitPackage, appWaitActivity,280    // and the device being used281    // in the opts and caps (so it gets back to the user on session creation)282    let launchInfo = await helpers.getLaunchInfo(this.adb, this.opts);283    Object.assign(this.opts, launchInfo);284    Object.assign(this.caps, launchInfo);285    // Uninstall any uninstallOtherPackages which were specified in caps286    if (this.opts.uninstallOtherPackages) {287      helpers.validateDesiredCaps(this.opts);288      // Only SETTINGS_HELPER_PKG_ID package is used by UIA1289      await helpers.uninstallOtherPackages(290        this.adb,291        helpers.parseArray(this.opts.uninstallOtherPackages),292        [SETTINGS_HELPER_PKG_ID]293      );294    }295    // Install any "otherApps" that were specified in caps296    if (this.opts.otherApps) {297      let otherApps;298      try {299        otherApps = helpers.parseArray(this.opts.otherApps);300      } catch (e) {301        log.errorAndThrow(`Could not parse "otherApps" capability: ${e.message}`);302      }303      otherApps = await B.all(otherApps.map((app) => this.helpers.configureApp(app, APP_EXTENSION)));304      await helpers.installOtherApks(otherApps, this.adb, this.opts);305    }306    // install app307    if (!this.opts.app) {308      if (this.opts.fullReset) {309        log.errorAndThrow('Full reset requires an app capability, use fastReset if app is not provided');310      }311      log.debug('No app capability. Assuming it is already on the device');312      if (this.opts.fastReset) {313        await helpers.resetApp(this.adb, this.opts);314      }315      return;316    }317    if (!this.opts.skipUninstall) {318      await this.adb.uninstallApk(this.opts.appPackage);319    }320    await helpers.installApk(this.adb, this.opts);321    const apkStringsForLanguage = await helpers.pushStrings(this.opts.language, this.adb, this.opts);322    if (this.opts.language) {323      this.apkStrings[this.opts.language] = apkStringsForLanguage;324    }325    // This must run after installing the apk, otherwise it would cause the326    // install to fail. And before running the app.327    if (!_.isUndefined(this.opts.sharedPreferences)) {328      await this.setSharedPreferences(this.opts);329    }330  }331  async checkAppPresent () {332    log.debug('Checking whether app is actually present');333    if (!(await fs.exists(this.opts.app))) {334      log.errorAndThrow(`Could not find app apk at ${this.opts.app}`);335    }336  }337  async checkPackagePresent () {338    log.debug('Checking whether package is present on the device');339    if (!(await this.adb.shell(['pm', 'list', 'packages', this.opts.appPackage]))) {340      log.errorAndThrow(`Could not find package ${this.opts.appPackage} on the device`);341    }342  }343  // Set CompressedLayoutHierarchy on the device344  async setCompressedLayoutHierarchy (compress) {345    await this.bootstrap.sendAction('compressedLayoutHierarchy', {compressLayout: compress});346  }347  async deleteSession () {348    log.debug('Shutting down Android driver');349    await helpers.removeAllSessionWebSocketHandlers(this.server, this.sessionId);350    await this.mobileStopScreenStreaming();351    await super.deleteSession();352    if (this.bootstrap) {353      // certain cleanup we only care to do if the bootstrap was ever run354      await this.stopChromedriverProxies();355      if (this.opts.unicodeKeyboard && this.opts.resetKeyboard && this.defaultIME) {356        log.debug(`Resetting IME to ${this.defaultIME}`);357        await this.adb.setIME(this.defaultIME);358      }359      if (!this.isChromeSession && !this.opts.dontStopAppOnReset) {360        await this.adb.forceStop(this.opts.appPackage);361      }362      if (this.opts.autoLaunch) {363        await this.adb.goToHome();364      }365      if (this.opts.fullReset && !this.opts.skipUninstall && !this.appOnDevice) {366        await this.adb.uninstallApk(this.opts.appPackage);367      }368      await this.bootstrap.shutdown();369      this.bootstrap = null;370    } else {371      log.debug("Called deleteSession but bootstrap wasn't active");372    }373    // some cleanup we want to do regardless, in case we are shutting down374    // mid-startup375    await this.adb.stopLogcat();376    if (this.useUnlockHelperApp) {377      await this.adb.forceStop('io.appium.unlock');378    }379    if (this._wasWindowAnimationDisabled) {380      log.info('Restoring window animation state');381      await this.adb.setAnimationState(true);382      // This was necessary to change animation scale over Android P. We must reset the policy for the security.383      if (await this.adb.getApiLevel() >= 28) {384        log.info('Restoring hidden api policy to the device default configuration');385        await this.adb.setDefaultHiddenApiPolicy(!!this.opts.ignoreHiddenApiPolicyError);386      }387    }388    if (this.opts.reboot) {389      let avdName = this.opts.avd.replace('@', '');390      log.debug(`closing emulator '${avdName}'`);391      await this.adb.killEmulator(avdName);392    }393  }394  async setSharedPreferences () {395    let sharedPrefs = this.opts.sharedPreferences;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var chai = require('chai');3var chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5var expect = chai.expect;6var assert = chai.assert;7var should = chai.should();8var driver = wd.promiseChainRemote("localhost", 4723);9var desired = {10};11driver.init(desired).then(function() {12  driver.setAnimationState({enabled: false});13  driver.setAnimationState({enabled: true});14  driver.quit();15});

Full Screen

Using AI Code Generation

copy

Full Screen

1    withCapabilities({2    build();3driver.setAnimationState(false);4driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');5driver.findElement(webdriver.By.name('btnG')).click();6driver.quit();7client.setAnimationState(false).then(function () {8    return client.findElement('name', 'q');9}).then(function (el) {10    return el.sendKeys('webdriver');11}).then(function () {12    return client.findElement('name', 'btnG');13}).then(function (el) {14    return el.click();15}).then(function () {16    return client.quit();17});18return this.adb.setAnimationState(false).then(function () {19    return this.findElement('name', 'q');20}).then(function (el) {21    return el.sendKeys('webdriver');22}).then(function () {23    return this.findElement('name', 'btnG');24}).then(function (el) {25    return el.click();26}).then(function () {27    return this.quit();28});29this.adb.setAnimationState(false);30this.findElement('name', 'q').sendKeys('webdriver');31this.findElement('name', 'btnG').click();

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require("appium-adb");2var driver = new adb.ADB();3driver.setAnimationState(true, function(err, res) {4    console.log("err: " + err);5    console.log("res: " + res);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var androidDriver = wd.promiseChainRemote('localhost', 4723);4    .init({5    })6    .setAnimationState('false')7    .quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1this.adb.setAnimationState(false)2this.adb.setAnimationState(true)3setAnimationState (state) {4    let cmd = 'settings put global window_animation_scale';5    cmd += state ? ' 1.0' : ' 0.0';6    this.shell(cmd);7    cmd = 'settings put global transition_animation_scale';8    cmd += state ? ' 1.0' : ' 0.0';9    this.shell(cmd);10    cmd = 'settings put global animator_duration_scale';11    cmd += state ? ' 1.0' : ' 0.0';12    this.shell(cmd);13  }14methods.setAnimationState = async function (state) {15  let cmd = 'settings put global window_animation_scale';16  cmd += state ? ' 1.0' : ' 0.0';17  await this.shell(cmd);18  cmd = 'settings put global transition_animation_scale';19  cmd += state ? ' 1.0' : ' 0.0';20  await this.shell(cmd);21  cmd = 'settings put global animator_duration_scale';22  cmd += state ? ' 1.0' : ' 0.0';23  await this.shell(cmd);24};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful