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

Best JavaScript code snippet using appium-android-driver

android-common.js

Source:android-common.js Github

copy

Full Screen

...99 status: status.codes.Success.code,100 value: null101 });102 };103 this.adb.startApp({104 pkg: this.args.appPackage,105 activity: this.args.appActivity,106 action: this.args.intentAction,107 category: this.args.intentCategory,108 flags: this.args.intentFlags,109 waitPkg: pack,110 waitActivity: activity,111 optionalIntentArguments: this.args.optionalIntentArguments,112 retry: true,113 stopApp: false114 }, onStart);115 }.bind(this), secs * 1000);116 }.bind(this));117 }.bind(this));118};119androidCommon.openSettingsActivity = function (setting, cb) {120 this.adb.getFocusedPackageAndActivity(function (err, foundPackage,121 foundActivity) {122 var cmd = 'am start -a android.settings.' + setting;123 this.adb.shell(cmd, function (err) {124 if (err) {125 cb(err);126 } else {127 this.adb.waitForNotActivity(foundPackage, foundActivity, 5000, cb);128 }129 }.bind(this));130 }.bind(this));131};132androidCommon.toggleSetting = function (setting, preKeySeq, ocb) {133 var doKey = function (key) {134 return function (cb) {135 setTimeout(function () {136 this.adb.keyevent(key, cb);137 }.bind(this), 2000);138 }.bind(this);139 }.bind(this);140 var settPkg, settAct;141 var back = function (cb) {142 this.adb.back(function (err) {143 if (err) {144 cb(err);145 } else {146 this.adb.waitForNotActivity(settPkg, settAct, 5000, cb);147 }148 }.bind(this));149 }.bind(this);150 /*151 * preKeySeq is the keyevent sequence to send over ADB in order152 * to position the cursor on the right option.153 * By default it's [up, up, down] because we usually target the 1st item in154 * the screen, and sometimes when opening settings activities the cursor is155 * already positionned on the 1st item, but we can't know for sure156 */157 if (preKeySeq === null) preKeySeq = [19, 19, 20]; // up, up, down158 var sequence = [159 function (cb) {160 this.openSettingsActivity(setting, cb);161 }.bind(this)162 ];163 var len = preKeySeq.length;164 for (var i = 0; i < len; i++) {165 sequence.push(doKey(preKeySeq[i]));166 }167 sequence.push(168 function (cb) {169 this.adb.getFocusedPackageAndActivity(function (err, foundPackage,170 foundActivity) {171 settPkg = foundPackage;172 settAct = foundActivity;173 cb(err);174 }.bind(this));175 }.bind(this)176 , function (cb) {177 /*178 * Click and handle potential ADB disconnect that occurs on official179 * emulator when the network connection is disabled180 */181 this.wrapActionAndHandleADBDisconnect(doKey(23), cb);182 }.bind(this)183 , function (cb) {184 /*185 * In one particular case (enable Location Services), a pop-up is186 * displayed on some platforms so the user accepts or refuses that Google187 * collects location data. So we wait for that pop-up to open, if it188 * doesn't then proceed189 */190 this.adb.waitForNotActivity(settPkg, settAct, 5000, function (err) {191 if (err) {192 cb(null);193 } else {194 // Click on right button, "Accept"195 async.series([196 doKey(22) // right197 , doKey(23) // click198 , function (cb) {199 // Wait for pop-up to close200 this.adb.waitForActivity(settPkg, settAct, 5000, cb);201 }.bind(this)202 ], function (err) {203 cb(err);204 }.bind(this));205 }206 }.bind(this));207 }.bind(this)208 , back209 );210 async.series(sequence, function (err) {211 if (err) return ocb(err);212 ocb(null, { status: status.codes.Success.code });213 }.bind(this));214};215androidCommon.toggleData = function (cb) {216 this.adb.isDataOn(function (err, dataOn) {217 if (err) return cb(err);218 this.wrapActionAndHandleADBDisconnect(function (ncb) {219 this.adb.setData(dataOn ? 0 : 1, ncb);220 }.bind(this), function (err) {221 if (err) return cb(err);222 cb(null, {223 status: status.codes.Success.code224 });225 });226 }.bind(this));227};228androidCommon.toggleFlightMode = function (ocb) {229 this.adb.isAirplaneModeOn(function (err, airplaneModeOn) {230 if (err) return ocb(err);231 async.series([232 function (cb) {233 this.wrapActionAndHandleADBDisconnect(function (ncb) {234 this.adb.setAirplaneMode(airplaneModeOn ? 0 : 1, ncb);235 }.bind(this), cb);236 }.bind(this),237 function (cb) {238 this.wrapActionAndHandleADBDisconnect(function (ncb) {239 this.adb.broadcastAirplaneMode(airplaneModeOn ? 0 : 1, ncb);240 }.bind(this), cb);241 }.bind(this)242 ], function (err) {243 if (err) return ocb(err);244 ocb(null, {245 status: status.codes.Success.code246 });247 }.bind(this));248 }.bind(this));249};250androidCommon.toggleWiFi = function (cb) {251 this.adb.isWifiOn(function (err, dataOn) {252 if (err) return cb(err);253 this.wrapActionAndHandleADBDisconnect(function (ncb) {254 this.adb.setWifi(dataOn ? 0 : 1, ncb);255 }.bind(this), function (err) {256 if (err) return cb(err);257 cb(null, {258 status: status.codes.Success.code259 });260 });261 }.bind(this));262};263androidCommon.toggleLocationServices = function (ocb) {264 this.adb.getApiLevel(function (err, api) {265 if (api > 15) {266 var seq = [19, 19]; // up, up267 if (api === 16) {268 // This version of Android has a "parent" button in its action bar269 seq.push(20); // down270 } else if (api >= 19) {271 // Newer versions of Android have the toggle in the Action bar272 seq = [22, 22, 19]; // right, right, up273 /*274 * Once the Location services switch is OFF, it won't receive focus275 * when going back to the Location Services settings screen unless we276 * send a dummy keyevent (UP) *before* opening the settings screen277 */278 this.adb.keyevent(19, function (/*err*/) {279 this.toggleSetting('LOCATION_SOURCE_SETTINGS', seq, ocb);280 }.bind(this));281 return;282 }283 this.toggleSetting('LOCATION_SOURCE_SETTINGS', seq, ocb);284 } else {285 // There's no global location services toggle on older Android versions286 ocb(new NotYetImplementedError(), null);287 }288 }.bind(this));289};290androidCommon.prepareDevice = function (onReady) {291 logger.debug("Preparing device for session");292 async.series([293 function (cb) { this.checkAppPresent(cb); }.bind(this),294 function (cb) { this.adb.checkAdbPresent(cb); }.bind(this),295 function (cb) { this.prepareEmulator(cb); }.bind(this),296 function (cb) { this.prepareActiveDevice(cb); }.bind(this),297 function (cb) { this.adb.waitForDevice(cb); }.bind(this),298 function (cb) { this.adb.startLogcat(cb); }.bind(this)299 ], onReady);300};301androidCommon.checkAppPresent = function (cb) {302 if (this.args.app === null) {303 logger.debug("Not checking whether app is present since we are assuming " +304 "it's already on the device");305 cb();306 } else {307 logger.debug("Checking whether app is actually present");308 fs.stat(this.args.app, function (err) {309 if (err) {310 logger.error("Could not find app apk at " + this.args.app);311 cb(err);312 } else {313 cb();314 }315 }.bind(this));316 }317};318androidCommon.prepareEmulator = function (cb) {319 if (this.args.avd !== null) {320 var avdName = this.args.avd.replace('@', '');321 this.adb.getRunningAVD(avdName, function (err, runningAVD) {322 if (err && err.message.indexOf('No devices') === -1 &&323 err.message.indexOf('No emulators') === -1) return cb(err);324 if (runningAVD !== null) {325 logger.debug("Did not launch AVD because it was already running.");326 return cb();327 }328 this.adb.launchAVD(this.args.avd, this.args.avdArgs, this.args.language, this.args.locale,329 this.args.avdLaunchTimeout, this.args.avdReadyTimeout, cb);330 }.bind(this));331 } else if (typeof this.args.language === "string" || typeof this.args.locale === "string") {332 var adbCmd = "";333 if (this.args.language && typeof this.args.language === "string") {334 logger.debug("Setting Android Device Language to " + this.args.language);335 adbCmd += "setprop persist.sys.language " + this.args.language.toLowerCase() + ";";336 }337 if (this.args.locale && typeof this.args.locale === "string") {338 logger.debug("Setting Android Device Country to " + this.args.locale);339 adbCmd += "setprop persist.sys.country " + this.args.locale.toUpperCase() + ";";340 }341 this.adb.shell(adbCmd, function (err) {342 if (err) return cb(err);343 this.adb.reboot(cb);344 }.bind(this));345 } else {346 cb();347 }348};349androidCommon.prepareActiveDevice = function (cb) {350 if (this.adb.curDeviceId) {351 // deviceId is already setted352 return cb();353 }354 logger.info('Retrieving device');355 this.adb.getDevicesWithRetry(function (err, devices) {356 if (err) return cb(err);357 var deviceId = null;358 if (this.adb.udid) {359 if (!_.contains(_.pluck(devices, 'udid'), this.adb.udid)) {360 return cb(new Error("Device " + this.adb.udid + " was not in the list " +361 "of connected devices"));362 }363 deviceId = this.adb.udid;364 } else {365 deviceId = devices[0].udid;366 var emPort = this.adb.getPortFromEmulatorString(deviceId);367 this.adb.setEmulatorPort(emPort);368 }369 logger.info('Found device', deviceId);370 this.adb.setDeviceId(deviceId);371 cb();372 }.bind(this));373};374androidCommon.resetApp = function (cb) {375 if (this.args.fastReset) {376 logger.debug("Running fast reset (stop and clear)");377 this.adb.stopAndClear(this.args.appPackage, cb);378 } else {379 logger.debug("Running old fashion reset (reinstall)");380 this.remoteApkExists(function (err, remoteApk) {381 if (err) return cb(err);382 if (!remoteApk) {383 return cb(new Error("Can't run reset if remote apk doesn't exist"));384 }385 this.adb.uninstallApk(this.args.appPackage, function (err) {386 if (err) return cb(err);387 this.adb.installRemote(remoteApk, cb);388 }.bind(this));389 }.bind(this));390 }391};392androidCommon.getRemoteApk = function (cb) {393 var next = function () {394 cb(null, this.remoteTempPath() + this.appMd5Hash + '.apk', this.appMd5Hash);395 }.bind(this);396 if (this.appMd5Hash) {397 next();398 } else {399 this.getAppMd5(function (err, md5Hash) {400 if (err) return cb(err);401 this.appMd5Hash = md5Hash;402 next();403 }.bind(this));404 }405};406androidCommon.remoteApkExists = function (cb) {407 this.getRemoteApk(function (err, remoteApk) {408 if (err) return cb(err);409 this.adb.shell("ls " + remoteApk, function (err, stdout) {410 if (err) return cb(err);411 if (stdout.indexOf("No such file") !== -1) {412 return cb(new Error("remote apk did not exist"));413 }414 cb(null, stdout.trim());415 });416 }.bind(this));417};418androidCommon.uninstallApp = function (cb) {419 var next = function () {420 this.adb.uninstallApk(this.args.appPackage, function (err) {421 if (err) return cb(err);422 cb(null);423 }.bind(this));424 }.bind(this);425 if (this.args.skipUninstall) {426 logger.debug("Not uninstalling app since server not started with " +427 "--full-reset");428 cb();429 } else {430 next();431 }432};433androidCommon.installAppForTest = function (cb) {434 if (this.args.app === null) {435 logger.debug("Skipping install since we launched with a package instead " +436 "of an app path");437 return cb();438 }439 this.adb.checkAndSignApk(this.args.app, this.args.appPackage, function (err) {440 if (err) return cb(err);441 this.remoteApkExists(function (err, remoteApk) {442 // err is set if the remote apk doesn't exist so don't check it.443 this.adb.isAppInstalled(this.args.appPackage, function (err, installed) {444 if (installed && this.args.fastReset && remoteApk) {445 logger.info('App is already installed, resetting app');446 this.resetApp(cb);447 } else if (!installed || (this.args.fastReset && !remoteApk)) {448 logger.info('Installing App');449 this.adb.mkdir(this.remoteTempPath(), function (err) {450 if (err) return cb(err);451 this.getRemoteApk(function (err, remoteApk, md5Hash) {452 if (err) return cb(err);453 this.removeTempApks([md5Hash], function (err, appExists) {454 if (err) return cb(err);455 var install = function (err) {456 if (err) return cb(err);457 this.installRemoteWithRetry(remoteApk, cb);458 }.bind(this);459 if (appExists) {460 install();461 } else {462 this.adb.push(this.args.app, remoteApk, install);463 }464 }.bind(this));465 }.bind(this));466 }.bind(this));467 } else {468 cb();469 }470 }.bind(this));471 }.bind(this));472 }.bind(this));473};474androidCommon.installRemoteWithRetry = function (remoteApk, cb) {475 this.adb.uninstallApk(this.args.appPackage, function (err) {476 if (err) logger.warn("Uninstalling apk failed, continuing");477 this.adb.installRemote(remoteApk, function (err) {478 if (err) {479 logger.warn("Installing remote apk failed, going to uninstall and try " +480 "again");481 this.removeTempApks([], function () {482 this.adb.push(this.args.app, remoteApk, function (err) {483 if (err) return cb(err);484 logger.debug("Attempting to install again for the last time");485 this.adb.installRemote(remoteApk, cb);486 }.bind(this));487 }.bind(this));488 } else {489 cb();490 }491 }.bind(this));492 }.bind(this));493};494androidCommon.getAppMd5 = function (cb) {495 try {496 md5(this.args.app, function (err, md5Hash) {497 if (err) return cb(err);498 logger.debug("MD5 for app is " + md5Hash);499 cb(null, md5Hash);500 }.bind(this));501 } catch (e) {502 logger.error("Problem calculating md5: " + e);503 return cb(e);504 }505};506androidCommon.remoteTempPath = function () {507 return "/data/local/tmp/";508};509androidCommon.removeTempApks = function (exceptMd5s, cb) {510 logger.debug("Removing any old apks");511 if (typeof exceptMd5s === "function") {512 cb = exceptMd5s;513 exceptMd5s = [];514 }515 var listApks = function (cb) {516 var cmd = 'ls /data/local/tmp/*.apk';517 this.adb.shell(cmd, function (err, stdout) {518 if (err || stdout.indexOf("No such file") !== -1) {519 return cb(null, []);520 }521 var apks = stdout.split("\n");522 cb(null, apks);523 });524 }.bind(this);525 var removeApks = function (apks, cb) {526 if (apks.length < 1) {527 logger.debug("No apks to examine");528 return cb();529 }530 var matchingApkFound = false;531 var noMd5Matched = true;532 var removes = [];533 _.each(apks, function (path) {534 path = path.trim();535 if (path !== "") {536 noMd5Matched = true;537 _.each(exceptMd5s, function (md5Hash) {538 if (path.indexOf(md5Hash) !== -1) {539 noMd5Matched = false;540 }541 });542 if (noMd5Matched) {543 removes.push('rm "' + path + '"');544 } else {545 logger.debug("Found an apk we want to keep at " + path);546 matchingApkFound = true;547 }548 }549 });550 // Invoking adb shell with an empty string will open a shell console551 // so return here if there's nothing to remove.552 if (removes.length < 1) {553 logger.debug("Couldn't find any apks to remove");554 return cb(null, matchingApkFound);555 }556 var cmd = removes.join(" && ");557 this.adb.shell(cmd, function () {558 cb(null, matchingApkFound);559 });560 }.bind(this);561 async.waterfall([562 function (cb) { listApks(cb); },563 function (apks, cb) { removeApks(apks, cb); }564 ], function (err, matchingApkFound) { cb(null, matchingApkFound); });565};566androidCommon.forwardPort = function (cb) {567 this.adb.forwardPort(this.args.systemPort, this.args.devicePort, cb);568};569androidCommon.pushUnicodeIME = function (cb) {570 logger.debug("Pushing unicode ime to device...");571 var imePath = path.resolve(__dirname, "..", "..", "..", "build",572 "unicode_ime_apk", "UnicodeIME-debug.apk");573 fs.stat(imePath, function (err) {574 if (err) {575 cb(new Error("Could not find Unicode IME apk; please run " +576 "'reset.sh --android' to build it."));577 } else {578 this.adb.install(imePath, false, cb);579 }580 }.bind(this));581};582androidCommon.pushSettingsApp = function (cb) {583 logger.debug("Pushing settings apk to device...");584 var settingsPath = path.resolve(__dirname, "..", "..", "..", "build",585 "settings_apk", "settings_apk-debug.apk");586 fs.stat(settingsPath, function (err) {587 if (err) {588 cb(new Error("Could not find settings apk; please run " +589 "'reset.sh --android' to build it."));590 } else {591 this.adb.install(settingsPath, false, cb);592 }593 }.bind(this));594};595androidCommon.pushUnlock = function (cb) {596 logger.debug("Pushing unlock helper app to device...");597 var unlockPath = path.resolve(__dirname, "..", "..", "..", "build",598 "unlock_apk", "unlock_apk-debug.apk");599 fs.stat(unlockPath, function (err) {600 if (err) {601 cb(new Error("Could not find unlock.apk; please run " +602 "'reset.sh --android' to build it."));603 } else {604 this.adb.install(unlockPath, false, cb);605 }606 }.bind(this));607};608androidCommon.unlockScreen = function (cb) {609 this.adb.isScreenLocked(function (err, isLocked) {610 if (err) return cb(err);611 if (isLocked) {612 logger.info("Unlocking screen");613 var timeoutMs = 10000;614 var start = Date.now();615 var unlockAndCheck = function () {616 logger.debug("Screen is locked, trying to unlock");617 var onStart = function (err) {618 if (err) return cb(err);619 this.adb.isScreenLocked(function (err, isLocked) {620 if (err) return cb(err);621 if (!isLocked) {622 logger.debug("Screen is unlocked, continuing");623 return cb();624 }625 if ((Date.now() - timeoutMs) > start) {626 return cb(new Error("Screen did not unlock"));627 } else {628 setTimeout(unlockAndCheck, 1000);629 }630 }.bind(this));631 }.bind(this);632 this.adb.startApp({633 pkg: "io.appium.unlock",634 activity: ".Unlock",635 action: "android.intent.action.MAIN",636 category: "android.intent.category.LAUNCHER",637 flags: "0x10200000"638 }, onStart);639 }.bind(this);640 unlockAndCheck();641 } else {642 logger.debug('Screen already unlocked, continuing.');643 cb();644 }645 }.bind(this));646};...

Full Screen

Full Screen

selendroid.js

Source:selendroid.js Github

copy

Full Screen

...346 var onStart = function (err) {347 if (err) return cb(err);348 return cb(null, body.sessionId);349 }.bind(this);350 return this.adb.startApp({351 pkg: this.args.appPackage,352 activity: this.args.appActivity,353 action: this.args.intentAction,354 category: this.args.intentCategory,355 flags: this.args.intentFlags,356 waitPkg: this.args.appWaitPackage,357 waitActivity: this.args.appWaitActivity,358 optionalIntentArguments: this.args.optionalIntentArguments,359 stopApp: this.args.stopAppOnReset,360 retry: false361 }, onStart);362 }363 return cb(null, body.sessionId);364 }.bind(this), 1800);...

Full Screen

Full Screen

android.js

Source:android.js Github

copy

Full Screen

...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) {...

Full Screen

Full Screen

driver.js

Source:driver.js Github

copy

Full Screen

...202 } catch (e) {203 logger.info(`Selendroid did not start the activity we were waiting for, ` +204 `'${appWaitPackage}/${appWaitActivity}'. ` +205 `Starting it ourselves`);206 await this.adb.startApp({207 pkg: this.opts.appPackage,208 activity: this.opts.appActivity,209 action: this.opts.intentAction,210 category: this.opts.intentCategory,211 flags: this.opts.intentFlags,212 waitPkg: this.opts.appWaitPackage,213 waitActivity: this.opts.appWaitActivity,214 optionalIntentArguments: this.opts.optionalIntentArguments,215 stopApp: !this.opts.dontStopAppOnReset,216 retry: false217 });218 }219 }220 async deleteSession () {...

Full Screen

Full Screen

general.js

Source:general.js Github

copy

Full Screen

...136 };137 }138 args = await util.filterObject(args);139 log.debug(`Bringing application back to foreground with arguments: ${JSON.stringify(args)}`);140 return await this.adb.startApp(args);141};142commands.getStrings = async function (language) {143 if (!language) {144 language = await this.adb.getDeviceLanguage();145 log.info(`No language specified, returning strings for: ${language}`);146 }147 if (this.apkStrings[language]) {148 // Return cached strings149 return this.apkStrings[language];150 }151 // TODO: This is mutating the current language, but it's how appium currently works152 this.apkStrings[language] = await androidHelpers.pushStrings(language, this.adb, this.opts);153 await this.bootstrap.sendAction('updateStrings');154 return this.apkStrings[language];155};156commands.launchApp = async function () {157 await this.initAUT();158 await this.startAUT();159};160commands.startActivity = async function (appPackage, appActivity,161 appWaitPackage, appWaitActivity,162 intentAction, intentCategory,163 intentFlags, optionalIntentArguments,164 dontStopAppOnReset) {165 log.debug(`Starting package '${appPackage}' and activity '${appActivity}'`);166 // dontStopAppOnReset is both an argument here, and a desired capability167 // if the argument is set, use it, otherwise use the cap168 if (!util.hasValue(dontStopAppOnReset)) {169 dontStopAppOnReset = !!this.opts.dontStopAppOnReset;170 }171 let args = {172 pkg: appPackage,173 activity: appActivity,174 waitPkg: appWaitPackage || appPackage,175 waitActivity: appWaitActivity || appActivity,176 action: intentAction,177 category: intentCategory,178 flags: intentFlags,179 optionalIntentArguments,180 stopApp: !dontStopAppOnReset181 };182 this.opts.startActivityArgs = this.opts.startActivityArgs || {};183 this.opts.startActivityArgs[`${appPackage}/${appActivity}`] = args;184 await this.adb.startApp(args);185};186commands.reset = async function () {187 if (this.opts.fullReset) {188 log.info("Running old fashion reset (reinstall)");189 await this.adb.stopAndClear(this.opts.appPackage);190 await this.adb.uninstallApk(this.opts.appPackage);191 await androidHelpers.installApkRemotely(this.adb, this.opts);192 } else {193 log.info("Running fast reset (stop and clear)");194 await this.adb.stopAndClear(this.opts.appPackage);195 }196 await this.grantPermissions();197 return await this.startAUT();198};199commands.startAUT = async function () {200 await this.adb.startApp({201 pkg: this.opts.appPackage,202 activity: this.opts.appActivity,203 action: this.opts.intentAction,204 category: this.opts.intentCategory,205 flags: this.opts.intentFlags,206 waitPkg: this.opts.appWaitPackage,207 waitActivity: this.opts.appWaitActivity,208 waitDuration: this.opts.appWaitDuration,209 optionalIntentArguments: this.opts.optionalIntentArguments,210 stopApp: !this.opts.dontStopAppOnReset211 });212};213// we override setUrl to take an android URI which can be used for deep-linking214// inside an app, similar to starting an intent...

Full Screen

Full Screen

macaca-android.js

Source:macaca-android.js Github

copy

Full Screen

...208 yield this.adb.install(UnlockApk.apkPath);209 }210 var isScreenLocked = yield this.adb.isScreenLocked();211 if (isScreenLocked) {212 yield this.adb.startApp(UnlockApk);213 yield _.sleep(5000);214 yield this.unlock();215 }216};217Android.prototype.checkApkVersion = function * (app, pkg) {218 var newVersion = yield ADB.getApkVersion(app);219 var oldVersion = yield this.adb.getInstalledApkVersion(pkg);220 if (newVersion > oldVersion) {221 yield this.adb.install(app);222 }223};224Android.prototype.launchApk = function * () {225 if (!this.isChrome) {226 const reuse = this.args.reuse;227 const app = this.args.app;228 const pkg = this.apkInfo.package;229 const isInstalled = yield this.adb.isInstalled(pkg);230 if (!isInstalled && !app) {231 throw new Error('App is neither installed, nor provided!');232 }233 if (isInstalled) {234 switch (reuse) {235 case reuseStatus.noReuse:236 case reuseStatus.reuseEmu:237 if (app) {238 yield this.adb.unInstall(pkg);239 yield this.adb.install(app);240 } else {241 yield this.adb.clear(pkg);242 }243 break;244 case reuseStatus.reuseEmuApp:245 if (app) {246 yield this.adb.install(app);247 }248 break;249 case reuseStatus.reuseEmuAppState:250 // Keep app state, don't change to main activity.251 this.apkInfo.activity = '';252 }253 } else {254 yield this.adb.install(app);255 }256 }257 logger.debug(`start app with: ${JSON.stringify(this.apkInfo)}`);258 yield this.adb.startApp(this.apkInfo);259 yield _.sleep(5 * 1000);260};261Android.prototype.getWebviews = function * () {262 if (!this.chromedriver) {263 var webviewVersion = null;264 try {265 webviewVersion = yield this.adb.getWebviewVersion();266 } catch (error) {267 console.log(error);268 logger.info('No webview version found from adb shell!');269 webviewVersion = null;270 }271 try {272 if (webviewVersion) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const assert = require('assert');3const chai = require('chai');4const chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6chai.should();7const caps = {8};9async function main() {10 const driver = wd.promiseChainRemote('localhost', 4723);11 await driver.init(caps);12 await driver.sleep(3000);13 await driver.startApp({14 });15 await driver.sleep(3000);16 const el = await driver.elementByAccessibilityId('Controls');17 await el.click();18 await driver.sleep(3000);19 await driver.back();20 await driver.sleep(3000);21 await driver.back();22 await driver.sleep(3000);23 await driver.quit();24}25main();26from appium import webdriver27from time import sleep28caps = {29}30sleep(3)31driver.start_app('io.appium.android.apis', '.view.Controls1')32sleep(3)33driver.find_element_by_accessibility_id('Controls').click()34sleep(3)35driver.back()36sleep(3)37driver.back()38sleep(3)39driver.quit()

Full Screen

Using AI Code Generation

copy

Full Screen

1SyntaxError: lib/android.js: Unexpected token (11:12)2 9 | import logger from '../lib/logger';3 10 | import ADB from 'appium-adb';4>11 | import { startApp } from 'appium-adb';5 13 | class AndroidDriver extends BaseDriver {6 14 | constructor (opts = {}, shouldValidateCaps = true) {7import { startApp } from 'appium-adb';8import { stopApp } from 'appium-adb';9SyntaxError: lib/android.js: Unexpected token (11:12)10 9 | import logger from '../lib/logger';11 10 | import ADB from 'appium-adb';12>11 | import { startApp } from 'appium-adb';13 13 | class AndroidDriver extends BaseDriver {14 14 | constructor (opts = {}, shouldValidateCaps = true) {15import { startApp } from 'appium-adb';16import { stopApp } from 'appium-adb';

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AndroidDriver } = require("appium-android-driver");2const { ADB } = require("appium-adb");3const { util } = require("appium-support");4const adb = new ADB();5const androidDriver = new AndroidDriver();6async function test() {7 try {8 const opts = {9 ignoreUnimportantViews: true,10 ignoreUnimportantViews: true,11 ignoreUnimportantViews: true,

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var assert = require('assert');3var Appium = require('appium');4var AppiumDriver = require('appium/lib/appium.js').AppiumDriver;5var AndroidDriver = require('appium/lib/devices/android/android-driver.js').AndroidDriver;6var AndroidBootstrap = require('appium/lib/devices/android/bootstrap.js').AndroidBootstrap;7var ADB = require('appium/lib/devices/android/android-helpers.js').ADB;8var Selendroid = require('appium/lib/devices/selendroid.js').Selendroid;9var logger = require('appium/lib/devices/android/logger.js').logger;10var desired = {11};12var driver = new AppiumDriver();13var androidDriver = new AndroidDriver();14var androidBootstrap = new AndroidBootstrap();15var adb = new ADB();16var selendroid = new Selendroid();17var test = function() {18 androidDriver.adb = adb;19 androidDriver.selendroid = selendroid;20 androidDriver.androidBootstrap = androidBootstrap;21 androidDriver.opts = desired;22 androidDriver.startApp(desired, function(err, data) {23 if (err) {24 console.log(err);25 } else {26 console.log(data);27 }28 });29};30test();31AndroidDriver.prototype.startApp = function(opts, cb) {32 var appPackage = opts.appPackage;33 var appActivity = opts.appActivity;34 var appWaitPackage = opts.appWaitPackage;35 var appWaitActivity = opts.appWaitActivity;36 var intentAction = opts.intentAction;37 var intentCategory = opts.intentCategory;38 var intentFlags = opts.intentFlags;39 var optionalIntentArguments = opts.optionalIntentArguments;40 var dontStopAppOnReset = opts.dontStopAppOnReset;41 var stopAppAfterReset = opts.stopAppAfterReset;42 var intent = null;43 var intentArgs = null;

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('startApp', function () {2 it('should start the app', function () {3 return this.adb.startApp({pkg: 'com.android.calculator2', activity: 'com.android.calculator2.Calculator'});4 });5});6commands.startApp = async function (opts = {}) {7 let {pkg, activity, action, category, flags, waitPkg, waitActivity,8 optionalIntentArguments, stopApp} = opts;9 if (stopApp) {10 await this.stopApp();11 }12 await this.adb.startApp(pkg, activity, action, category, flags, optionalIntentArguments);13 await this.waitForCondition(() => {14 return this.adb.getCurrentActivity().then((currentActivity) => {15 return currentActivity === waitActivity;16 });17 }, {waitMs: 20000, intervalMs: 400});18 await this.waitForCondition(() => {19 return this.adb.getCurrentPackage().then((currentPackage) => {20 return currentPackage === waitPkg;21 });22 }, {waitMs: 20000, intervalMs: 400});23};24methods.startApp = async function (pkg, activity, action, category, flags, optionalIntentArguments) {25 if (this.isEmulator()) {26 throw new Error("startApp is not supported on emulators");27 }28 let intent = this.adb.defaultIntent({29 });30 await this.shell("am start -W " + intent);31};32methods.defaultIntent = function (opts = {}) {33 let {pkg, activity, action, category, flags, optionalIntentArguments} = opts;34 let intent = "";35 if (pkg && activity) {36 intent = "-n " + pkg + "/" + activity;37 }38 if (action) {39 intent += " -a " + action;40 }41 if (category) {42 intent += " -c " + category;43 }44 if (flags) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var Appium = require('appium');2var AppiumDriver = Appium.AndroidDriver;3var AppiumAdb = Appium.ADB;4var appiumDriver = new AppiumDriver();5var appiumAdb = new AppiumAdb();6appiumDriver.start(function(err) {7 appiumAdb.startApp({pkg: 'com.android.settings'}, function(err) {8 console.log('app started');9 });10});11var Appium = require('appium');12var AppiumDriver = Appium.AndroidDriver;13var AppiumAdb = Appium.ADB;14var appiumDriver = new AppiumDriver();15var appiumAdb = new AppiumAdb();16appiumDriver.start(function(err) {17 appiumAdb.shell('am start -n com.android.settings/.Settings', function(err, stdout) {18 console.log('app started');19 });20});

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