How to use this.setCompressedLayoutHierarchy method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

driver.js

Source:driver.js Github

copy

Full Screen

...196    return helpers.isChromeBrowser(this.opts.browserName);197  }198  async onSettingsUpdate (key, value) {199    if (key === 'ignoreUnimportantViews') {200      await this.setCompressedLayoutHierarchy(value);201    }202  }203  async startAndroidSession () {204    this.log.info(`Starting Android session`);205    // set up the device to run on (real or emulator, etc)206    this.defaultIME = await helpers.initDevice(this.adb, this.opts);207    // set actual device name, udid, platform version, screen size, model and manufacturer details.208    this.caps.deviceName = this.adb.curDeviceId;209    this.caps.deviceUDID = this.opts.udid;210    this.caps.platformVersion = await this.adb.getPlatformVersion();211    this.caps.deviceScreenSize = await this.adb.getScreenSize();212    this.caps.deviceModel = await this.adb.getModel();213    this.caps.deviceManufacturer = await this.adb.getManufacturer();214    if (this.opts.disableWindowAnimation) {...

Full Screen

Full Screen

android.js

Source:android.js Github

copy

Full Screen

...69  ];70  // listen for changes to ignoreUnimportantViews71  this.settings.on("update", function (update) {72    if (update.key === "ignoreUnimportantViews") {73      this.setCompressedLayoutHierarchy(update.value, update.callback);74    } else {75      update.callback();76    }77  }.bind(this));78};79Android.prototype._deviceConfigure = Device.prototype.configure;80Android.prototype.noLaunchSetup = function (cb) {81  logger.debug("Setting up Android for 'autoLaunch: false'");82  async.series([83    this.initJavaVersion.bind(this),84    this.initAdb.bind(this),85  ], function (err) { cb(err); });86};87Android.prototype.start = function (cb, onDie) {88  this.launchCb = cb;89  this.uiautomatorExitCb = onDie;90  logger.info("Starting android appium");91  async.series([92    this.initJavaVersion.bind(this),93    this.initAdb.bind(this),94    this.packageAndLaunchActivityFromManifest.bind(this),95    this.initUiautomator.bind(this),96    this.prepareDevice.bind(this),97    this.checkApiLevel.bind(this),98    this.pushStrings.bind(this),99    this.processFromManifest.bind(this),100    this.uninstallApp.bind(this),101    this.installAppForTest.bind(this),102    this.forwardPort.bind(this),103    //this.pushAppium.bind(this),104    this.initUnicode.bind(this),105    //this.pushSettingsApp.bind(this),106    //this.pushUnlock.bind(this),107    function (cb) {this.uiautomator.start(cb);}.bind(this),108    this.wakeUp.bind(this),109    this.unlock.bind(this),110    this.getDataDir.bind(this),111    this.setupCompressedLayoutHierarchy.bind(this),112    this.startAppUnderTest.bind(this),113    this.initAutoWebview.bind(this),114    this.setActualCapabilities.bind(this)115  ], function (err) {116    if (err) {117      this.shutdown(function () {118        this.launchCb(err);119      }.bind(this));120    } else {121      this.didLaunch = true;122      this.launchCb(null, this.proxySessionId);123    }124  }.bind(this));125};126Android.prototype.initUiautomator = function (cb) {127  if (this.uiautomator === null) {128    this.uiautomator = new UiAutomator(this.adb, this.args);129    this.uiautomator.setExitHandler(this.onUiautomatorExit.bind(this));130  }131  return cb();132};133Android.prototype.onLaunch = function (err) {134  var readyToGo = function () {135    this.didLaunch = true;136    this.launchCb();137  }.bind(this);138  var giveUp = function (err) {139    this.shutdown(function () {140      this.launchCb(err);141    }.bind(this));142  }.bind(this);143  if (err) {144    if (this.checkShouldRelaunch(err)) {145      logger.error(err);146      logger.error("Above error isn't fatal, maybe relaunching adb will help....");147      this.adb.waitForDevice(function (err) {148        if (err) return giveUp(err);149        readyToGo();150      });151    } else {152      giveUp(err);153    }154  } else {155    readyToGo();156  }157};158Android.prototype.restartUiautomator = function (cb) {159  async.series([160    this.forwardPort.bind(this)161    , this.uiautomator.start.bind(this.uiautomator)162    , this.setupCompressedLayoutHierarchy.bind(this)163  ], cb);164};165/*166 * Execute an arbitrary function and handle potential ADB disconnection before167 * proceeding168 */169Android.prototype.wrapActionAndHandleADBDisconnect = function (action, ocb) {170  async.series([171    function (cb) {172      this.uiautomatorIgnoreExit = true;173      action(cb);174    }.bind(this)175    , this.adb.restart.bind(this.adb)176    , this.restartUiautomator.bind(this)177  ], function (err) {178    this.uiautomatorIgnoreExit = false;179    ocb(err);180  }.bind(this));181};182Android.prototype.onUiautomatorExit = function () {183  logger.debug("UiAutomator exited");184  var respondToClient = function () {185    this.stopChromedriverProxies(function () {186      this.cleanup();187      if (!this.didLaunch) {188        var msg = "UiAutomator quit before it successfully launched";189        logger.error(msg);190        this.launchCb(new Error(msg));191        return;192      } else if (typeof this.cbForCurrentCmd === "function") {193        var error = new UnknownError("UiAutomator died while responding to " +194                                      "command, please check appium logs!");195        this.cbForCurrentCmd(error, null);196      }197      // make sure appium.js knows we crashed so it can clean up198      this.uiautomatorExitCb();199    }.bind(this));200  }.bind(this);201  if (this.adb) {202    var uninstall = function () {203      logger.debug("Attempting to uninstall app");204      this.uninstallApp(function () {205        this.shuttingDown = false;206        respondToClient();207      }.bind(this));208    }.bind(this);209    if (!this.uiautomatorIgnoreExit) {210      this.adb.ping(function (err, ok) {211        if (ok) {212          uninstall();213        } else {214          logger.debug(err);215          this.adb.restart(function (err) {216            if (err) {217              logger.debug(err);218            }219            if (this.uiautomatorRestartOnExit) {220              this.uiautomatorRestartOnExit = false;221              this.restartUiautomator(function (err) {222                if (err) {223                  logger.debug(err);224                  uninstall();225                }226              }.bind(this));227            } else {228              uninstall();229            }230          }.bind(this));231        }232      }.bind(this));233    } else {234      this.uiautomatorIgnoreExit = false;235    }236  } else {237    logger.debug("We're in uiautomator's exit callback but adb is gone already");238    respondToClient();239  }240};241Android.prototype.checkShouldRelaunch = function (launchErr) {242  if (launchErr.message === null || typeof launchErr.message === 'undefined') {243    logger.error("We're checking if we should relaunch based on something " +244                 "which isn't an error object. Check the codez!");245    return false;246  }247  var msg = launchErr.message.toString();248  var relaunchOn = [249    'Could not find a connected Android device'250    , 'Device did not become ready'251  ];252  var relaunch = false;253  _.each(relaunchOn, function (relaunchMsg) {254    relaunch = relaunch || msg.indexOf(relaunchMsg) !== -1;255  });256  return relaunch;257};258Android.prototype.checkApiLevel = function (cb) {259  this.adb.getApiLevel(function (err, apiLevel) {260    if (err) return cb(err);261    logger.info('Device API level is:', parseInt(apiLevel, 10));262    if (parseInt(apiLevel) < 17) {263      var msg = "Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device.";264      logger.error(msg); // logs the error when we encounter it265      return cb(new Error(msg)); // send the error up the chain266    }267    cb();268  });269};270Android.prototype.decorateChromeOptions = function (caps) {271  // add options from appium session caps272  if (this.args.chromeOptions) {273    _.each(this.args.chromeOptions, function (val, option) {274      if (typeof caps.chromeOptions[option] === "undefined") {275        caps.chromeOptions[option] = val;276      } else {277        logger.warn("Cannot pass option " + caps.chromeOptions[option] + " because Appium needs it to make chromeDriver work");278      }279    });280  }281  // add device id from adb282  caps.chromeOptions.androidDeviceSerial = this.adb.curDeviceId;283  return caps;284};285Android.prototype.processFromManifest = function (cb) {286  if (!this.args.app) {287    return cb();288  } else { // apk must be local to process the manifest.289    this.adb.processFromManifest(this.args.app, function (err, process) {290      var value = process || this.args.appPackage;291      this.appProcess = value;292      logger.debug("Set app process to: " + this.appProcess);293      cb();294    }.bind(this));295  }296};297Android.prototype.pushStrings = function (cb, language) {298  var outputPath = path.resolve(this.args.tmpDir, this.args.appPackage);299  var remotePath = '/data/local/tmp';300  var stringsJson = 'strings.json';301  this.extractStrings(function (err) {302    if (err) {303      if (!fs.existsSync(this.args.app)) {304        // apk doesn't exist locally so remove old strings.json305        logger.debug("Could not get strings, but it looks like we had an " +306                     "old strings file anyway, so ignoring");307        return this.adb.rimraf(remotePath + '/' + stringsJson, function (err) {308          if (err) return cb(new Error("Could not remove old strings"));309          cb();310        });311      } else {312        // if we can't get strings, just dump an empty json and continue313        logger.warn("Could not get strings, continuing anyway");314        var remoteFile = remotePath + '/' + stringsJson;315        return this.adb.shell("echo '{}' > " + remoteFile, cb);316      }317    }318    var jsonFile = path.resolve(outputPath, stringsJson);319    this.adb.push(jsonFile, remotePath, function (err) {320      if (err) return cb(new Error("Could not push strings.json"));321      cb();322    });323  }.bind(this), language);324};325Android.prototype.getStrings = function (language, stringFile, cb) {326  if (this.language && this.language === language) {327    // Return last strings328    return cb(null, {329      status: status.codes.Success.code,330      value: this.apkStrings331    });332  }333  // Extract, push and return strings334  return this.pushStrings(function () {335    this.proxy(["updateStrings", {}], function (err, res) {336      if (err || res.status !== status.codes.Success.code) return cb(err, res);337      cb(null, {338        status: status.codes.Success.code,339        value: this.apkStrings340      });341    }.bind(this));342  }.bind(this), language);343};344Android.prototype.pushAppium = function (cb) {345  logger.debug("Pushing appium bootstrap to device...");346  var binPath = path.resolve(__dirname, "..", "..", "..", "build",347      "android_bootstrap", "AppiumBootstrap.jar");348  fs.stat(binPath, function (err) {349    if (err) {350      cb(new Error("Could not find AppiumBootstrap.jar; please run " +351                   "'grunt buildAndroidBootstrap'"));352    } else {353      this.adb.push(binPath, this.remoteTempPath(), cb);354    }355  }.bind(this));356};357Android.prototype.startAppUnderTest = function (cb) {358  this.startApp(this.args, cb);359};360Android.prototype.startApp = function (args, cb) {361  if (args.androidCoverage) {362    this.adb.androidCoverage(args.androidCoverage, args.appWaitPackage,363      args.appWaitActivity, cb);364  } else {365    this.adb.startApp({366      pkg: args.appPackage,367      activity: args.appActivity,368      action: args.intentAction,369      category: args.intentCategory,370      flags: args.intentFlags,371      waitPkg: args.appWaitPackage,372      waitActivity: args.appWaitActivity,373      optionalIntentArguments: args.optionalIntentArguments,374      stopApp: args.stopAppOnReset || !args.dontStopAppOnReset375    }, cb);376  }377};378Android.prototype.stop = function (cb) {379  if (this.shuttingDown) {380    logger.debug("Already in process of shutting down.");381    return cb();382  }383  this.shuttingDown = true;384  var completeShutdown = function (cb) {385    if (this.adb) {386      this.adb.goToHome(function () {387        this.shutdown(cb);388      }.bind(this));389    } else {390      this.shutdown(cb);391    }392  }.bind(this);393  if (this.args.fullReset) {394    logger.debug("Removing app from device");395    this.uninstallApp(function (err) {396      if (err) {397        // simply warn on error here, because we don't want to stop the shutdown398        // process399        logger.warn(err);400      }401      completeShutdown(cb);402    });403  } else {404    completeShutdown(cb);405  }406};407Android.prototype.cleanup = function () {408  logger.debug("Cleaning up android objects");409  this.adb = null;410  this.uiautomator = null;411  this.shuttingDown = false;412};413Android.prototype.shutdown = function (cb) {414  var next = function () {415    this.stopChromedriverProxies(function () {416      if (this.uiautomator) {417        this.uiautomator.shutdown(function () {418          this.cleanup();419          cb();420        }.bind(this));421      } else {422        this.cleanup();423        cb();424      }425    }.bind(this));426  }.bind(this);427  if (this.adb) {428    this.adb.endAndroidCoverage();429    if (this.args.unicodeKeyboard && this.args.resetKeyboard && this.defaultIME) {430      logger.debug('Resetting IME to \'' + this.defaultIME + '\'');431      this.adb.setIME(this.defaultIME, function (err) {432        if (err) {433          // simply warn on error here, because we don't want to stop the shutdown434          // process435          logger.warn(err);436        }437        if (this.adb) {438          this.adb.stopLogcat(function () {439            next();440          }.bind(this));441        }442      }.bind(this));443    } else {444      this.adb.stopLogcat(function () {445        next();446      }.bind(this));447    }448  } else {449    next();450  }451};452Android.prototype.proxy = deviceCommon.proxy;453Android.prototype.respond = deviceCommon.respond;454Android.prototype.initQueue = function () {455  this.queue = async.queue(function (task, cb) {456    var action = task.action,457        params = task.params;458    this.cbForCurrentCmd = cb;459    if (this.adb && !this.shuttingDown) {460      this.uiautomator.sendAction(action, params, function (response) {461        this.cbForCurrentCmd = null;462        if (typeof cb === 'function') {463          this.respond(response, cb);464        }465      }.bind(this));466    } else {467      this.cbForCurrentCmd = null;468      var msg = "Tried to send command to non-existent Android device, " +469                 "maybe it shut down?";470      if (this.shuttingDown) {471        msg = "We're in the middle of shutting down the Android device, " +472              "so your request won't be executed. Sorry!";473      }474      this.respond({475        status: status.codes.UnknownError.code476      , value: msg477      }, cb);478    }479  }.bind(this), 1);480};481Android.prototype.push = function (elem) {482  this.queue.push({action: elem[0][0], params: elem[0][1] || {}}, elem[1]);483};484Android.prototype.wakeUp = function (cb) {485  // requires an appium bootstrap connection loaded486  logger.debug("Waking up device if it's not alive");487  this.proxy(["wake", {}], cb);488};489Android.prototype.getDataDir = function (cb) {490  this.proxy(["getDataDir", {}], function (err, res) {491    if (err) return cb(err);492    this.dataDir = res.value;493    logger.debug("dataDir set to: " + this.dataDir);494    cb();495  }.bind(this));496};497// Set CompressedLayoutHierarchy on the device based on current settings object498Android.prototype.setupCompressedLayoutHierarchy = function (cb) {499  // setup using cap500  if (_.has(this.args, 'ignoreUnimportantViews')) {501    // set the setting directly on the internal _settings object, this way we don't trigger an update event502    this.settings._settings.ignoreUnimportantViews = this.args.ignoreUnimportantViews;503  }504  if (_.isUndefined(this.getSetting("ignoreUnimportantViews"))) {505    return cb();506  }507  this.setCompressedLayoutHierarchy(this.getSetting("ignoreUnimportantViews"), cb);508};509// Set CompressedLayoutHierarchy on the device510Android.prototype.setCompressedLayoutHierarchy = function (compress, cb) {511  this.proxy(["compressedLayoutHierarchy", {compressLayout: compress}], cb);512};513Android.prototype.waitForActivityToStop = function (cb) {514  this.adb.waitForNotActivity(this.args.appWaitPackage, this.args.appWaitActivity, cb);515};516Android.prototype.setActualCapabilities = function (cb) {517  this.capabilities.deviceName = this.adb.udid || this.adb.curDeviceId;518  this.adb.shell("getprop ro.build.version.release", function (err, version) {519    if (err) {520      logger.warn(err);521    } else {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var By = webdriver.By;3var until = webdriver.until;4var driver = new webdriver.Builder().forBrowser('chrome').build();5driver.findElement(By.name('q')).sendKeys('webdriver');6driver.findElement(By.name('btnG')).click();7driver.wait(until.titleIs('webdriver - Google Search'), 1000);8driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.setCompressedLayoutHierarchy(true);2driver.getCompressedLayoutHierarchy();3driver.getDevicePixelRatio();4driver.getDisplayDensity();5driver.getNetworkConnection();6driver.getPerformanceData("packageName", "dataType", ["dataReadTimeout"]);7driver.getPerformanceDataTypes();8driver.getSettings();9driver.getSupportedPerformanceDataTypes();10driver.getSystemBars();11driver.getSystemBars();12driver.isDeviceLocked();13driver.isKeyboardShown();14driver.isLocked();15driver.isScreenOn();16driver.lock(1000);17driver.longPressKeyCode(1000);18driver.openNotifications();19driver.performEditorAction("action");

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.setCompressedLayoutHierarchy(true);2driver.quit();3driver.getCompressedLayoutHierarchy().then(function(value) {4console.log('Compressed Layout Hierarchy: ' + value);5});6driver.quit();7driver.getDisplayDensity().then(function(value) {8console.log('Display Density: ' + value);9});10driver.quit();11driver.getDisplaySize().then(function(value) {12console.log('Display Size: ' + value);13});14driver.quit();15driver.getPerformanceData('com.example', 'memoryinfo', 10).then(function(value) {16console.log('Performance Data: ' + value);17});18driver.quit();19driver.getPerformanceDataTypes().then(function(value) {20console.log('Performance Data Types: ' + value);21});22driver.quit();23driver.pushFile('/sdcard/test.txt', 'Hello World!').then(function(value) {24console.log('File Pushed: ' + value);25});26driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2(async () => {3    const browser = await remote({4        capabilities: {5        }6    })7    await browser.setCompressedLayoutHierarchy(true)8    await browser.pause(5000)9    await browser.setCompressedLayoutHierarchy(false)10    await browser.pause(5000)11    await browser.deleteSession()12})().catch((e) => console.error(e))

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