Best JavaScript code snippet using appium-android-driver
android-common.js
Source:android-common.js
...125 this.adb.shell(cmd, function (err) {126 if (err) {127 cb(err);128 } else {129 this.adb.waitForNotActivity(foundPackage, foundActivity, 5000, cb);130 }131 }.bind(this));132 }.bind(this));133};134androidCommon.toggleSetting = function (setting, preKeySeq, ocb) {135 var doKey = function (key) {136 return function (cb) {137 setTimeout(function () {138 this.adb.keyevent(key, cb);139 }.bind(this), 2000);140 }.bind(this);141 }.bind(this);142 var settPkg, settAct;143 var back = function (cb) {144 this.adb.back(function (err) {145 if (err) {146 cb(err);147 } else {148 this.adb.waitForNotActivity(settPkg, settAct, 5000, cb);149 }150 }.bind(this));151 }.bind(this);152 /*153 * preKeySeq is the keyevent sequence to send over ADB in order154 * to position the cursor on the right option.155 * By default it's [up, up, down] because we usually target the 1st item in156 * the screen, and sometimes when opening settings activities the cursor is157 * already positionned on the 1st item, but we can't know for sure158 */159 if (preKeySeq === null) preKeySeq = [19, 19, 20]; // up, up, down160 var sequence = [161 function (cb) {162 this.openSettingsActivity(setting, cb);163 }.bind(this)164 ];165 var len = preKeySeq.length;166 for (var i = 0; i < len; i++) {167 sequence.push(doKey(preKeySeq[i]));168 }169 sequence.push(170 function (cb) {171 this.adb.getFocusedPackageAndActivity(function (err, foundPackage,172 foundActivity) {173 settPkg = foundPackage;174 settAct = foundActivity;175 cb(err);176 }.bind(this));177 }.bind(this)178 , function (cb) {179 /*180 * Click and handle potential ADB disconnect that occurs on official181 * emulator when the network connection is disabled182 */183 this.wrapActionAndHandleADBDisconnect(doKey(23), cb);184 }.bind(this)185 , function (cb) {186 /*187 * In one particular case (enable Location Services), a pop-up is188 * displayed on some platforms so the user accepts or refuses that Google189 * collects location data. So we wait for that pop-up to open, if it190 * doesn't then proceed191 */192 this.adb.waitForNotActivity(settPkg, settAct, 5000, function (err) {193 if (err) {194 cb(null);195 } else {196 // Click on right button, "Accept"197 async.series([198 doKey(22) // right199 , doKey(23) // click200 , function (cb) {201 // Wait for pop-up to close202 this.adb.waitForActivity(settPkg, settAct, 5000, cb);203 }.bind(this)204 ], function (err) {205 cb(err);206 }.bind(this));...
android.js
Source:android.js
...510Android.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 {522 logger.debug("Device is at release version " + version);523 this.capabilities.platformVersion = version;524 }525 return cb();526 }.bind(this));527};528Android.prototype.resetTimeout = deviceCommon.resetTimeout;...
general.js
Source:general.js
...55};56commands.openSettingsActivity = async function (setting) {57 let {appPackage, appActivity} = await this.adb.getFocusedPackageAndActivity();58 await this.adb.shell(['am', 'start', '-a', `android.settings.${setting}`]);59 await this.adb.waitForNotActivity(appPackage, appActivity, 5000);60};61commands.getWindowSize = function () {62 return this.bootstrap.sendAction('getDeviceSize');63};64commands.getCurrentActivity = async function () {65 return (await this.adb.getFocusedPackageAndActivity()).appActivity;66};67commands.getCurrentPackage = async function () {68 return (await this.adb.getFocusedPackageAndActivity()).appPackage;69};70commands.getLogTypes = function () {71 return _.keys(logTypesSupported);72};73commands.getLog = function (logType) {...
network.js
Source:network.js
...140 * collects location data. So we wait for that pop-up to open, if it141 * doesn't then proceed142 */143 try {144 await this.adb.waitForNotActivity(appPackage, appActivity, 5000);145 await this.doKey(22); // right146 await this.doKey(23); // click147 await this.adb.waitForNotActivity(appPackage, appActivity, 5000);148 } catch (ign) {}149 await this.adb.back();150};151helpers.doKey = async function (key) {152 // TODO: Confirm we need this delay. Seems to work without it.153 await B.delay(2000);154 await this.adb.keyevent(key);155};156helpers.wrapBootstrapDisconnect = async function (wrapped) {157 this.bootstrap.ignoreUnexpectedShutdown = true;158 try {159 await wrapped();160 await this.adb.restart();161 await this.bootstrap.start(this.opts.appPackage, this.opts.disableAndroidWatchers, this.opts.acceptSslCerts);...
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var should = chai.should();7var driver = wd.promiseChainRemote('localhost', 4723);8var desiredCaps = {9};10driver.init(desiredCaps).then(function () {11 driver.sleep(5000).then(function () {12 driver.waitForNotActivity('app activity').then(function () {13 driver.sleep(5000).then(function () {14 driver.quit();15 });16 });17 });18});19I have also tried with driver.waitForNotActivity('app activity', 5000) method, but it throws error as below:20at Object.module.exports.waitForNotActivity (C:\Users\username\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\general.js:112:11)21at Object.module.exports.waitForNotActivity (C:\Users\username\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\general.js:100:13)22at Object.module.exports.waitForNotActivity (C:\Users\username\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\general.js:100:13)23at Object.module.exports.waitForNotActivity (C:\Users\username\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\general.js:100:13)24at Object.module.exports.waitForNotActivity (C:\Users\username\AppData\
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var _ = require('underscore');4var fs = require('fs');5var path = require('path');6var desired = {7};8var driver = wd.promiseChainRemote('localhost', 4723);9 .init(desired)10 .then(function() {11 return driver.setImplicitWaitTimeout(5000);12 })13 .then(function() {14 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);15 })16 .then(function() {17 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);18 })19 .then(function() {20 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);21 })22 .then(function() {23 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);24 })25 .then(function() {26 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);27 })28 .then(function() {29 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);30 })31 .then(function() {32 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);33 })34 .then(function() {35 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);36 })37 .then(function() {38 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);39 })40 .then(function() {41 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);42 })43 .then(function() {44 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);45 })46 .then(function() {47 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);48 })49 .then(function() {50 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);51 })52 .then(function() {53 return driver.waitForNotActivity('com.android.browser.BrowserActivity', 10000);54 })55 .then(function() {
Using AI Code Generation
1var webdriver = require('wd');2var assert = require('assert');3var path = require('path');4var Appium = require('appium');5var AndroidDriver = require('appium/lib/devices/android/android-driver');6var logger = require('appium/lib/devices/android/logger');7var desired = {8 app: path.resolve(__dirname, 'appium-test-app-0.1.1.apk'),9};10var driver = new webdriver.Builder()11 .withCapabilities(desired)12 .build();13 .init(desired)14 .elementByName('Content')15 .click()16 .elementByName('Split
Using AI Code Generation
1var Appium = require('appium');2var AndroidDriver = Appium.AndroidDriver;3var driver = new AndroidDriver();4driver.adb.waitForNotActivity('com.android.settings', 10000);5 at Object.<anonymous> (/Users/rishabhsinghal/Downloads/test.js:6:23)6 at Module._compile (module.js:456:26)7 at Object.Module._extensions..js (module.js:474:10)8 at Module.load (module.js:356:32)9 at Function.Module._load (module.js:312:12)10 at Function.Module.runMain (module.js:497:10)11 at startup (node.js:119:16)12var Appium = require('appium');13var AndroidDriver = Appium.AndroidDriver;14var driver = new AndroidDriver();15var adb = driver.adb;16adb.waitForNotActivity('com.android.settings', 10000);17 at Object.<anonymous> (/Users/rishabhsinghal/Downloads/test.js:7:7)18 at Module._compile (module.js:456:26)19 at Object.Module._extensions..js (module.js:474:10)20 at Module.load (module.js:356:32)21 at Function.Module._load (module.js:312:12)22 at Function.Module.runMain (module.js:497:10)23 at startup (node.js:119:16)24var Appium = require('appium');25var AndroidDriver = Appium.AndroidDriver;26var driver = new AndroidDriver();27driver.adb.waitForNotActivity('com.android.settings', 10000);
Using AI Code Generation
1this.adb.waitForNotActivity(packageName, activityName, timeout, interval, cb);2AndroidDriver.prototype.waitForNotActivity = function (pkg, activity, waitMs, intervalMs, cb) {3 var start = Date.now();4 var timeoutMs = waitMs || 20000;5 var intMs = intervalMs || 3000;6 var self = this;7 var onActivity = function (err, curActivity) {8 if (err) return cb(err);9 if (curActivity !== activity) {10 logger.debug("Activity changed to '" + curActivity + "' (from '" + activity + "')");11 return cb();12 }13 if (Date.now() - start < timeoutMs) {14 setTimeout(function () {15 self.shell("dumpsys window windows", onActivity);16 }, intMs);17 } else {18 var msg = "Activity did not stop after " + timeoutMs + "ms; it is still '" + activity + "'";19 logger.error(msg);20 cb(new Error(msg));21 }22 };23 self.shell("dumpsys window windows", onActivity);24};25Android.prototype.waitForNotActivity = function (pkg, activity, waitMs, intervalMs, cb) {26 if (_.isFunction(waitMs)) {27 cb = waitMs;28 waitMs = null;29 intervalMs = null;30 } else if (_.isFunction(intervalMs)) {31 cb = intervalMs;32 intervalMs = null;33 }34 this.adb.waitForNotActivity(pkg, activity, waitMs, intervalMs, cb);35};36Android.prototype.waitForNotActivity = function (pkg, activity, waitMs, intervalMs, cb) {37 if (_.isFunction(waitMs)) {38 cb = waitMs;39 waitMs = null;40 intervalMs = null;41 } else if (_.isFunction(intervalMs)) {42 cb = intervalMs;43 intervalMs = null;44 }45 this.adb.waitForNotActivity(pkg, activity, waitMs, intervalMs, cb);46};
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!