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

Best JavaScript code snippet using appium-android-driver

android-common.js

Source:android-common.js Github

copy

Full Screen

...89 this.args.avdReadyTimeout = this.args.avdReadyTimeout || 120000;90 this.args.noSign = this.args.noSign || false;91};92androidCommon.background = function (secs, cb) {93 this.adb.getFocusedPackageAndActivity(function (err, pack, activity) {94 if (err) return cb(err);95 this.adb.keyevent("3", function (err) {96 if (err) return cb(err);97 setTimeout(function () {98 var onStart = function (err) {99 if (err) return cb(err);100 cb(null,{101 status: status.codes.Success.code,102 value: null103 });104 };105 this.adb.startApp({106 pkg: this.args.appPackage,107 activity: this.args.appActivity,108 action: this.args.intentAction,109 category: this.args.intentCategory,110 flags: this.args.intentFlags,111 waitPkg: pack,112 waitActivity: activity,113 optionalIntentArguments: this.args.optionalIntentArguments,114 retry: true,115 stopApp: !this.args.dontStopAppOnReset116 }, onStart);117 }.bind(this), secs * 1000);118 }.bind(this));119 }.bind(this));120};121androidCommon.openSettingsActivity = function (setting, cb) {122 this.adb.getFocusedPackageAndActivity(function (err, foundPackage,123 foundActivity) {124 var cmd = 'am start -a android.settings.' + setting;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));207 }208 }.bind(this));209 }.bind(this)210 , back211 );212 async.series(sequence, function (err) {213 if (err) return ocb(err);214 ocb(null, { status: status.codes.Success.code });215 }.bind(this));216};217androidCommon.toggleData = function (cb) {218 this.adb.isDataOn(function (err, dataOn) {219 if (err) return cb(err);220 this.wrapActionAndHandleADBDisconnect(function (ncb) {221 this.adb.setData(dataOn ? 0 : 1, ncb);222 }.bind(this), function (err) {223 if (err) return cb(err);224 cb(null, {225 status: status.codes.Success.code226 });227 });228 }.bind(this));229};230androidCommon.toggleFlightMode = function (ocb) {231 this.adb.isAirplaneModeOn(function (err, airplaneModeOn) {232 if (err) return ocb(err);233 async.series([234 function (cb) {235 this.wrapActionAndHandleADBDisconnect(function (ncb) {236 this.adb.setAirplaneMode(airplaneModeOn ? 0 : 1, ncb);237 }.bind(this), cb);238 }.bind(this),239 function (cb) {240 this.wrapActionAndHandleADBDisconnect(function (ncb) {241 this.adb.broadcastAirplaneMode(airplaneModeOn ? 0 : 1, ncb);242 }.bind(this), cb);243 }.bind(this)244 ], function (err) {245 if (err) return ocb(err);246 ocb(null, {247 status: status.codes.Success.code248 });249 }.bind(this));250 }.bind(this));251};252androidCommon.toggleWiFi = function (cb) {253 this.adb.isWifiOn(function (err, dataOn) {254 if (err) return cb(err);255 this.wrapActionAndHandleADBDisconnect(function (ncb) {256 this.adb.setWifi(dataOn ? 0 : 1, ncb);257 }.bind(this), function (err) {258 if (err) return cb(err);259 cb(null, {260 status: status.codes.Success.code261 });262 });263 }.bind(this));264};265androidCommon.toggleLocationServices = function (ocb) {266 this.adb.getApiLevel(function (err, api) {267 if (api > 15) {268 var seq = [19, 19]; // up, up269 if (api === 16) {270 // This version of Android has a "parent" button in its action bar271 seq.push(20); // down272 } else if (api >= 19) {273 // Newer versions of Android have the toggle in the Action bar274 seq = [22, 22, 19]; // right, right, up275 /*276 * Once the Location services switch is OFF, it won't receive focus277 * when going back to the Location Services settings screen unless we278 * send a dummy keyevent (UP) *before* opening the settings screen279 */280 this.adb.keyevent(19, function (/*err*/) {281 this.toggleSetting('LOCATION_SOURCE_SETTINGS', seq, ocb);282 }.bind(this));283 return;284 }285 this.toggleSetting('LOCATION_SOURCE_SETTINGS', seq, ocb);286 } else {287 // There's no global location services toggle on older Android versions288 ocb(new NotYetImplementedError(), null);289 }290 }.bind(this));291};292androidCommon.prepareDevice = function (onReady) {293 logger.debug("Using fast reset? " + this.args.fastReset);294 logger.debug("Preparing device for session");295 async.series([296 function (cb) { this.checkAppPresent(cb); }.bind(this),297 function (cb) { this.prepareEmulator(cb); }.bind(this),298 function (cb) { this.prepareActiveDevice(cb); }.bind(this),299 function (cb) { this.adb.waitForDevice(cb); }.bind(this),300 function (cb) { this.adb.startLogcat(cb); }.bind(this)301 ], onReady);302};303androidCommon.checkAppPresent = function (cb) {304 if (this.args.app === null) {305 logger.debug("Not checking whether app is present since we are assuming " +306 "it's already on the device");307 cb();308 } else {309 logger.debug("Checking whether app is actually present");310 fs.stat(this.args.app, function (err) {311 if (err) {312 logger.error("Could not find app apk at " + this.args.app);313 cb(err);314 } else {315 cb();316 }317 }.bind(this));318 }319};320androidCommon.prepareEmulator = function (cb) {321 if (this.args.avd !== null) {322 var avdName = this.args.avd.replace('@', '');323 this.adb.getRunningAVD(avdName, function (err, runningAVD) {324 if (err && err.message.indexOf('No devices') === -1 &&325 err.message.indexOf('No emulators') === -1) return cb(err);326 if (runningAVD !== null) {327 logger.debug("Did not launch AVD because it was already running.");328 return this.ensureDeviceLocale(cb);329 }330 this.adb.launchAVD(this.args.avd, this.args.avdArgs, this.args.language, this.args.locale,331 this.args.avdLaunchTimeout, this.args.avdReadyTimeout, cb);332 }.bind(this));333 } else {334 this.ensureDeviceLocale(cb);335 }336};337androidCommon.ensureDeviceLocale = function (cb) {338 var haveLanguage = this.args.language && typeof this.args.language === "string";339 var haveCountry = this.args.locale && typeof this.args.locale === "string";340 if (!haveLanguage && !haveCountry) return cb();341 this.getDeviceLanguage(function (err, language) {342 if (err) return cb(err);343 this.getDeviceCountry(function (err, country) {344 if (err) return cb(err);345 var adbCmd = "";346 if (haveLanguage && this.args.language !== language) {347 logger.debug("Setting Android Device Language to " + this.args.language);348 adbCmd += "setprop persist.sys.language " + this.args.language.toLowerCase() + ";";349 }350 if (haveCountry && this.args.locale !== country) {351 logger.debug("Setting Android Device Country to " + this.args.locale);352 adbCmd += "setprop persist.sys.country " + this.args.locale.toUpperCase() + ";";353 }354 if (adbCmd === "") return cb();355 this.adb.shell(adbCmd, function (err) {356 if (err) return cb(err);357 this.adb.reboot(cb);358 }.bind(this));359 }.bind(this));360 }.bind(this));361};362androidCommon.prepareActiveDevice = function (cb) {363 if (this.adb.curDeviceId) {364 // deviceId is already setted365 return cb();366 }367 logger.info('Retrieving device');368 this.adb.getDevicesWithRetry(function (err, devices) {369 if (err) return cb(err);370 var deviceId = null;371 if (this.adb.udid) {372 if (!_.contains(_.pluck(devices, 'udid'), this.adb.udid)) {373 return cb(new Error("Device " + this.adb.udid + " was not in the list " +374 "of connected devices"));375 }376 deviceId = this.adb.udid;377 } else {378 deviceId = devices[0].udid;379 var emPort = this.adb.getPortFromEmulatorString(deviceId);380 this.adb.setEmulatorPort(emPort);381 }382 logger.info('Found device', deviceId);383 this.adb.setDeviceId(deviceId);384 cb();385 }.bind(this));386};387androidCommon.resetApp = function (cb) {388 if (this.args.fastReset) {389 logger.debug("Running fast reset (stop and clear)");390 this.adb.stopAndClear(this.args.appPackage, cb);391 } else {392 logger.debug("Running old fashion reset (reinstall)");393 this.remoteApkExists(function (err, remoteApk) {394 if (err) return cb(err);395 if (!remoteApk) {396 return cb(new Error("Can't run reset if remote apk doesn't exist"));397 }398 this.adb.uninstallApk(this.args.appPackage, function (err) {399 if (err) return cb(err);400 this.adb.installRemote(remoteApk, cb);401 }.bind(this));402 }.bind(this));403 }404};405androidCommon.getRemoteApk = function (cb) {406 var next = function () {407 cb(null, this.remoteTempPath() + this.appMd5Hash + '.apk', this.appMd5Hash);408 }.bind(this);409 if (this.appMd5Hash) {410 next();411 } else {412 this.getAppMd5(function (err, md5Hash) {413 if (err) return cb(err);414 this.appMd5Hash = md5Hash;415 next();416 }.bind(this));417 }418};419androidCommon.remoteApkExists = function (cb) {420 this.getRemoteApk(function (err, remoteApk) {421 if (err) return cb(err);422 this.adb.shell("ls " + remoteApk, function (err, stdout) {423 if (err) return cb(err);424 if (stdout.indexOf("No such file") !== -1) {425 return cb(new Error("remote apk did not exist"));426 }427 cb(null, stdout.trim());428 });429 }.bind(this));430};431androidCommon.uninstallApp = function (cb) {432 var next = function () {433 this.adb.uninstallApk(this.args.appPackage, function (err) {434 if (err) return cb(err);435 cb(null);436 }.bind(this));437 }.bind(this);438 if (this.args.skipUninstall) {439 logger.debug("Not uninstalling app since server not started with " +440 "--full-reset");441 cb();442 } else {443 next();444 }445};446androidCommon.installAppForTest = function (cb) {447 if (this.args.app === null) {448 logger.debug("Skipping install since we launched with a package instead " +449 "of an app path");450 return cb();451 }452 var afterSigning = function (err) {453 if (err) return cb(err);454 this.remoteApkExists(function (err, remoteApk) {455 // err is set if the remote apk doesn't exist so don't check it.456 this.adb.isAppInstalled(this.args.appPackage, function (err, installed) {457 if (installed && this.args.fastReset && remoteApk) {458 logger.info('App is already installed, resetting app');459 this.resetApp(cb);460 } else if (!installed || (this.args.fastReset && !remoteApk)) {461 logger.info('Installing App');462 this.adb.mkdir(this.remoteTempPath(), function (err) {463 if (err) return cb(err);464 this.getRemoteApk(function (err, remoteApk, md5Hash) {465 if (err) return cb(err);466 this.removeTempApks([md5Hash], function (err, appExists) {467 if (err) return cb(err);468 var install = function (err) {469 if (err) return cb(err);470 this.installRemoteWithRetry(remoteApk, cb);471 }.bind(this);472 if (appExists) {473 install();474 } else {475 this.adb.push(this.args.app, remoteApk, install);476 }477 }.bind(this));478 }.bind(this));479 }.bind(this));480 } else {481 cb();482 }483 }.bind(this));484 }.bind(this));485 }.bind(this);486 // Skipping sign apk for noSign true487 if (this.args.noSign) {488 logger.debug('noSign capability set to true, skipping checking and signing of app');489 afterSigning();490 } else {491 this.adb.checkAndSignApk(this.args.app, this.args.appPackage, afterSigning);492 }493};494androidCommon.installRemoteWithRetry = function (remoteApk, cb) {495 this.adb.uninstallApk(this.args.appPackage, function (err) {496 if (err) logger.warn("Uninstalling apk failed, continuing");497 this.adb.installRemote(remoteApk, function (err) {498 if (err) {499 logger.warn("Installing remote apk failed, going to uninstall and try " +500 "again");501 this.removeTempApks([], function () {502 this.adb.push(this.args.app, remoteApk, function (err) {503 if (err) return cb(err);504 logger.debug("Attempting to install again for the last time");505 this.adb.installRemote(remoteApk, cb);506 }.bind(this));507 }.bind(this));508 } else {509 cb();510 }511 }.bind(this));512 }.bind(this));513};514androidCommon.getAppMd5 = function (cb) {515 try {516 md5(this.args.app, function (err, md5Hash) {517 if (err) return cb(err);518 logger.debug("MD5 for app is " + md5Hash);519 cb(null, md5Hash);520 }.bind(this));521 } catch (e) {522 logger.error("Problem calculating md5: " + e);523 return cb(e);524 }525};526androidCommon.remoteTempPath = function () {527 return "/data/local/tmp/";528};529androidCommon.removeTempApks = function (exceptMd5s, cb) {530 logger.debug("Removing any old apks");531 if (typeof exceptMd5s === "function") {532 cb = exceptMd5s;533 exceptMd5s = [];534 }535 var listApks = function (cb) {536 var cmd = 'ls /data/local/tmp/*.apk';537 this.adb.shell(cmd, function (err, stdout) {538 if (err || stdout.indexOf("No such file") !== -1) {539 return cb(null, []);540 }541 var apks = stdout.split("\n");542 cb(null, apks);543 });544 }.bind(this);545 var removeApks = function (apks, cb) {546 if (apks.length < 1) {547 logger.debug("No apks to examine");548 return cb();549 }550 var matchingApkFound = false;551 var noMd5Matched = true;552 var removes = [];553 _.each(apks, function (path) {554 path = path.trim();555 if (path !== "") {556 noMd5Matched = true;557 _.each(exceptMd5s, function (md5Hash) {558 if (path.indexOf(md5Hash) !== -1) {559 noMd5Matched = false;560 }561 });562 if (noMd5Matched) {563 removes.push('rm "' + path + '"');564 } else {565 logger.debug("Found an apk we want to keep at " + path);566 matchingApkFound = true;567 }568 }569 });570 // Invoking adb shell with an empty string will open a shell console571 // so return here if there's nothing to remove.572 if (removes.length < 1) {573 logger.debug("Couldn't find any apks to remove");574 return cb(null, matchingApkFound);575 }576 var cmd = removes.join(" && ");577 this.adb.shell(cmd, function () {578 cb(null, matchingApkFound);579 });580 }.bind(this);581 async.waterfall([582 function (cb) { listApks(cb); },583 function (apks, cb) { removeApks(apks, cb); }584 ], function (err, matchingApkFound) { cb(null, matchingApkFound); });585};586androidCommon.forwardPort = function (cb) {587 this.adb.forwardPort(this.args.systemPort, this.args.devicePort, cb);588};589androidCommon.pushUnicodeIME = function (cb) {590 logger.debug("Pushing unicode ime to device...");591 var imePath = path.resolve(__dirname, "..", "..", "..", "build",592 "unicode_ime_apk", "UnicodeIME-debug.apk");593 fs.stat(imePath, function (err) {594 if (err) {595 cb(new Error("Could not find Unicode IME apk; please run " +596 "'reset.sh --android' to build it."));597 } else {598 this.adb.install(imePath, false, cb);599 }600 }.bind(this));601};602androidCommon.pushSettingsApp = function (cb) {603 logger.debug("Pushing settings apk to device...");604 var settingsPath = path.resolve(__dirname, "..", "..", "..", "build",605 "settings_apk", "settings_apk-debug.apk");606 fs.stat(settingsPath, function (err) {607 if (err) {608 cb(new Error("Could not find settings apk; please run " +609 "'reset.sh --android' to build it."));610 } else {611 this.adb.install(settingsPath, false, cb);612 }613 }.bind(this));614};615androidCommon.packageAndLaunchActivityFromManifest = function (cb) {616 if (!this.args.app) {617 logger.warn("No app capability, can't parse package/activity");618 return cb();619 }620 if (this.args.appPackage && this.args.appActivity) return cb();621 logger.debug("Parsing package and activity from app manifest");622 this.adb.packageAndLaunchActivityFromManifest(this.args.app, function (err, pkg, act) {623 if (err) {624 logger.error("Problem parsing package and activity from manifest: " +625 err);626 return cb(err);627 }628 if (pkg && !this.args.appPackage) this.args.appPackage = pkg;629 if (!this.args.appWaitPackage) this.args.appWaitPackage = this.args.appPackage;630 // Retrying to parse activity from AndroidManifest.xml631 if (act === null) {632 var appiumApkToolsJarPath = this.adb.jars['appium_apk_tools.jar'];633 var outputPath = path.resolve(this.args.tmpDir, pkg);634 var getLaunchActivity = ['java -jar "', appiumApkToolsJarPath,635 '" "', 'printLaunchActivity',636 '" "', this.args.app, '" "', outputPath, '"'].join('');637 exec(getLaunchActivity, { maxBuffer: 524288 }, function (err, stdout, stderr) {638 if (err || stderr) {639 logger.warn(stderr);640 return cb(new Error("Cannot parse launchActivity from manifest." + err));641 }642 var apkActivity = new RegExp(/Launch activity parsed:([^']+)/g).exec(stdout);643 if (apkActivity && apkActivity.length >= 2) {644 act = apkActivity[1];645 } else {646 act = null;647 }648 if (act && !this.args.appActivity) this.args.appActivity = act;649 if (!this.args.appWaitActivity) this.args.appWaitActivity = this.args.appActivity;650 logger.debug("Parsed package and activity are: " + pkg + "/" + act);651 cb();652 }.bind(this));653 }654 else {655 if (act && !this.args.appActivity) this.args.appActivity = act;656 if (!this.args.appWaitActivity) this.args.appWaitActivity = this.args.appActivity;657 logger.debug("Parsed package and activity are: " + pkg + "/" + act);658 cb();659 }660 }.bind(this));661};662androidCommon.getLog = function (logType, cb) {663 // Check if passed logType is supported664 if (!_.has(logTypesSupported, logType)) {665 return cb(null, {666 status: status.codes.UnknownError.code667 , value: "Unsupported log type '" + logType + "', supported types : " + JSON.stringify(logTypesSupported)668 });669 }670 var logs;671 // Check that current logType and instance is compatible672 if (logType === 'logcat') {673 try {674 logs = this.adb.getLogcatLogs();675 } catch (e) {676 return cb(e);677 }678 }679 // If logs captured sucessfully send response with data, else send error680 if (logs) {681 return cb(null, {682 status: status.codes.Success.code683 , value: logs684 });685 } else {686 return cb(null, {687 status: status.codes.UnknownError.code688 , value: "Incompatible logType for this device"689 });690 }691};692androidCommon.getLogTypes = function (cb) {693 return cb(null, {694 status: status.codes.Success.code695 , value: _.keys(logTypesSupported)696 });697};698androidCommon.getCurrentActivity = function (cb) {699 this.adb.getFocusedPackageAndActivity(function (err, curPackage, activity) {700 if (err) {701 return cb(null, {702 status: status.codes.UnknownError.code703 , value: err.message704 });705 }706 cb(null, {707 status: status.codes.Success.code708 , value: activity709 });710 });711};712androidCommon.getDeviceProperty = function (property, cb) {713 this.adb.shell("getprop " + property, function (err, stdout) {...

Full Screen

Full Screen

general.js

Source:general.js Github

copy

Full Screen

...53 log.info("Keyboard has no UI; no closing necessary");54 }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) {74 if (!_.has(logTypesSupported, logType)) {75 throw new Error(`Unsupported log type ${logType}. ` +76 `Supported types are ${JSON.stringify(logTypesSupported)}`);77 }78 if (logType === 'logcat') {79 return this.adb.getLogcatLogs();80 }81};82commands.isAppInstalled = function (appPackage) {83 return this.adb.isAppInstalled(appPackage);84};85commands.removeApp = function (appPackage) {86 return this.adb.uninstallApk(appPackage);87};88commands.installApp = async function (appPath) {89 appPath = await this.helpers.configureApp(appPath, APP_EXTENSION);90 if (!(await fs.exists(appPath))) {91 log.errorAndThrow(`Could not find app apk at ${appPath}`);92 }93 let {apkPackage} = await this.adb.packageAndLaunchActivityFromManifest(appPath);94 let opts = {95 app: appPath,96 appPackage: apkPackage,97 fastReset: this.opts.fastReset98 };99 return androidHelpers.installApkRemotely(this.adb, opts);100};101commands.background = async function (seconds) {102 if (seconds < 0) {103 // if user passes in a negative seconds value, interpret that as the instruction104 // to not bring the app back at all105 await this.adb.goToHome();106 return true;107 }108 let {appPackage, appActivity} = await this.adb.getFocusedPackageAndActivity();109 await this.adb.goToHome();110 await B.delay(seconds * 1000);111 let args;112 if (this.opts.startActivityArgs && this.opts.startActivityArgs[`${appPackage}/${appActivity}`]) {113 // the activity was started with `startActivity`, so use those args to restart114 args = this.opts.startActivityArgs[`${appPackage}/${appActivity}`];115 } else if (appPackage === this.opts.appPackage && appActivity === this.opts.appActivity) {116 // the activity is the original session activity, so use the original args117 args = {118 pkg: appPackage,119 activity: appActivity,120 action: this.opts.intentAction,121 category: this.opts.intentCategory,122 flags: this.opts.intentFlags,...

Full Screen

Full Screen

network.js

Source:network.js Github

copy

Full Screen

...125 await this.openSettingsActivity(setting);126 for (let key of preKeySeq) {127 await this.doKey(key);128 }129 let {appPackage, appActivity} = await this.adb.getFocusedPackageAndActivity();130 /*131 * Click and handle potential ADB disconnect that occurs on official132 * emulator when the network connection is disabled133 */134 await this.wrapBootstrapDisconnect(async () => {135 await this.doKey(23);136 });137 /*138 * In one particular case (enable Location Services), a pop-up is139 * displayed on some platforms so the user accepts or refuses that Google140 * collects location data. So we wait for that pop-up to open, if it141 * doesn't then proceed142 */143 try {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = {4 chromeOptions: {5 }6};7var driver = wd.promiseChainRemote('localhost', 4723);8driver.init(desired).then(function() {9}).then(function() {10}).then(function() {11}).then(function() {12}).then(function() {13}).then(function() {14}).then(function() {15}).then(function() {16}).then(function() {17}).then(function() {18}).then(function() {19}).then(function() {20}).then(function() {21}).then(function() {22}).then(function() {23}).then(function() {24}).then(function() {25}).then(function() {26}).then(function() {27}).then(function() {28}).then(function() {29}).then(function() {30}).then(function() {31}).then(function() {32}).then(function()

Full Screen

Using AI Code Generation

copy

Full Screen

1'use strict';2var wd = require('wd'),3 assert = require('assert'),4 _ = require('underscore'),5 Q = require('q');6var desired = {

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', function() {2 it('should get package and activity', async function() {3 const {package, activity} = await this.adb.getFocusedPackageAndActivity();4 console.log(package, activity);5 });6});7Error: Error: Error executing adbExec. Original error: 'Command '/Users/username/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys window windows' exited with code 3221225477'; Stderr: ''; Code: '3221225477'8Error: Error: Error executing adbExec. Original error: 'Command '/Users/username/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys window windows' exited with code 3221225477'; Stderr: ''; Code: '3221225477'9Error: Error: Error executing adbExec. Original error: 'Command '/Users/username/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys window windows' exited with code 3221225477'; Stderr: ''; Code: '3221225477'

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var wd = require('wd');3 .init({deviceName: 'Android', platformName: 'Android', platformVersion: '4.4', app: 'com.android.calculator2'})4 .getFocusedPackageAndActivity()5 .then(function (activity) {6 console.log(activity);7 assert.equal(activity.appPackage, "com.android.calculator2");8 assert.equal(activity.appWaitActivity, "com.android.calculator2.Calculator");9 })10 .fin(function () { return driver.quit(); })11 .done();12{ appPackage: 'com.android.calculator2', appWaitActivity: 'com.android.calculator2.Calculator' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new webdriver.Builder()2 .forBrowser('chrome')3 .build();4driver.adb.getFocusedPackageAndActivity(function(err, res) {5 console.log(res);6});7{ package: 'com.android.chrome',8activity: 'com.google.android.apps.chrome.Main' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var _ = require('underscore');4var serverConfigs = {5};6var desired = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var driver = wd.promiseChainRemote('localhost', 4723);4var desiredCapabilities = {5};6 .init(desiredCapabilities)7 .then(function () {8 return driver.getFocusedPackageAndActivity();9 })10 .then(function (activity) {11 console.log("Activity: " + activity);12 })13 .fin(function () {14 return driver.quit();15 })16 .done();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var AppiumAndroidDriver = require('appium-android-driver');4var desiredCaps = {5};6var driver = wd.promiseChainRemote('localhost', 4723);7driver.init(desiredCaps).then(function() {8 driver.adb.getFocusedPackageAndActivity().then(function(focusedPackageAndActivity){9 console.log(focusedPackageAndActivity);10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var desiredCaps = {3};4driver.init(desiredCaps)5 .then(function () {6 return driver.getFocusedPackageAndActivity();7 })8 .then(function (focusedPackageAndActivity) {9 console.log('focusedPackageAndActivity: ', focusedPackageAndActivity);10 })11 .fin(function () {12 return driver.quit();13 })14 .done();

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