Best JavaScript code snippet using appium-android-driver
android.js
Source:android.js
1"use strict";2var errors = require('../../server/errors.js')3 , path = require('path')4 , fs = require('fs')5 , Device = require('../device.js')6 , _ = require('underscore')7 , logger = require('../../server/logger.js').get('appium')8 , deviceCommon = require('../common.js')9 , status = require("../../server/status.js")10 , async = require('async')11 , androidController = require('./android-controller.js')12 , androidContextController = require('./android-context-controller.js')13 , androidCommon = require('./android-common.js')14 , androidHybrid = require('./android-hybrid.js')15 , UiAutomator = require('./uiautomator.js')16 , UnknownError = errors.UnknownError;17var Android = function () {18 this.init();19};20_.extend(Android.prototype, Device.prototype);21Android.prototype._deviceInit = Device.prototype.init;22Android.prototype.init = function () {23 this._deviceInit();24 this.appExt = ".apk";25 this.capabilities = {26 platform: 'LINUX'27 , browserName: 'Android'28 , platformVersion: '4.1'29 , webStorageEnabled: false30 , takesScreenshot: true31 , javascriptEnabled: true32 , databaseEnabled: false33 , networkConnectionEnabled: true34 , locationContextEnabled: false35 };36 this.args.devicePort = 4724;37 this.appMd5Hash = null;38 this.args.avd = null;39 this.args.language = null;40 this.args.locale = null;41 this.args.javaVersion = null;42 this.initQueue();43 this.implicitWaitMs = 0;44 this.shuttingDown = false;45 this.adb = null;46 this.uiautomator = null;47 this.uiautomatorRestartOnExit = false;48 this.uiautomatorIgnoreExit = false;49 this.swipeStepsPerSec = 28;50 this.dragStepsPerSec = 40;51 this.asyncWaitMs = 0;52 this.remote = null;53 this.contexts = [];54 this.curContext = this.defaultContext();55 this.didLaunch = false;56 this.launchCb = function () {};57 this.uiautomatorExitCb = function () {};58 this.dataDir = null;59 this.isProxy = false;60 this.proxyHost = null;61 this.proxyPort = null;62 this.proxySessionId = null;63 this.avoidProxy = [64 ['POST', new RegExp('^/wd/hub/session/[^/]+/context')]65 , ['GET', new RegExp('^/wd/hub/session/[^/]+/context')]66 , ['GET', new RegExp('^/wd/hub/session/[^/]+/contexts')]67 , ['POST', new RegExp('^/wd/hub/session/[^/]+/appium')]68 , ['GET', new RegExp('^/wd/hub/session/[^/]+/appium')]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 {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;529Android.prototype.waitForCondition = deviceCommon.waitForCondition;530Android.prototype.implicitWaitForCondition = deviceCommon.implicitWaitForCondition;531Android.prototype.getSettings = deviceCommon.getSettings;532Android.prototype.updateSettings = deviceCommon.updateSettings;533_.extend(Android.prototype, androidController);534_.extend(Android.prototype, androidContextController);535_.extend(Android.prototype, androidCommon);536_.extend(Android.prototype, androidHybrid);...
chrome.js
Source:chrome.js
1"use strict";2var Android = require('./android.js')3 , _ = require('underscore')4 , logger = require('../../server/logger.js').get('appium')5 , status = require('../../server/status.js')6 , deviceCommon = require('../common.js')7 , jwpSuccess = deviceCommon.jwpSuccess8 , async = require('async')9 , ADB = require('./adb.js')10 , UiAutomator = require('./uiautomator.js')11 , Chromedriver = require('./chromedriver.js');12var NATIVE_WIN = "NATIVE_APP";13var WEBVIEW_WIN = "WEBVIEW";14var WEBVIEW_BASE = WEBVIEW_WIN + "_";15var ChromeAndroid = function () {16 this.init();17};18_.extend(ChromeAndroid.prototype, Android.prototype);19ChromeAndroid.prototype._androidInit = Android.prototype.init;20ChromeAndroid.prototype.init = function () {21 this._androidInit();22 this.adb = null;23 this.onDie = null;24 this.setChromedriverMode();25};26ChromeAndroid.prototype.setChromedriverMode = function () {27 logger.info("Set mode: Proxying straight through to Chromedriver");28 this.isProxy = true;29 // when proxying to chromedriver, we need to make sure the context endpoints30 // are trapped by appium for its own purposes31 this.avoidProxy = [32 ['POST', new RegExp('^/wd/hub/session/[^/]+/context')],33 ['GET', new RegExp('^/wd/hub/session/[^/]+/context')],34 ['POST', new RegExp('^/wd/hub/session/[^/]+/touch/perform')],35 ['POST', new RegExp('^/wd/hub/session/[^/]+/touch/multi/perform')]36 ];37};38ChromeAndroid.prototype.setNativeMode = function () {39 logger.info("Set mode: Proxying to Appium Bootstrap");40 this.isProxy = false;41};42ChromeAndroid.prototype.configure = function (args, caps, cb) {43 logger.debug("Looks like we want chrome on android");44 this._deviceConfigure(args, caps);45 var bName = this.args.browserName || "";46 var app = this.appString().toLowerCase() ||47 bName.toString().toLowerCase();48 if (app === "chromium") {49 this.args.androidPackage = "org.chromium.chrome.testshell";50 this.args.androidActivity = "org.chromium.chrome.testshell.Main";51 } else if (app === "chromebeta") {52 this.args.androidPackage = "com.chrome.beta";53 this.args.androidActivity = "com.google.android.apps.chrome.Main";54 } else if (app === "browser") {55 this.args.androidPackage = "com.android.browser";56 this.args.androidActivity = "com.android.browser.BrowserActivity";57 } else {58 this.args.androidPackage = "com.android.chrome";59 this.args.androidActivity = "com.google.android.apps.chrome.Main";60 }61 // don't allow setAndroidArgs to reclobber our androidPackage/activity62 delete this.capabilities.appPackage;63 delete this.capabilities.appActivity;64 this.setAndroidArgs();65 this.args.app = null;66 this.args.proxyPort = this.args.chromeDriverPort;67 cb();68};69ChromeAndroid.prototype.start = function (cb, onDie) {70 this.adb = new ADB(this.args);71 this.uiautomator = new UiAutomator(this.adb, this.args);72 this.uiautomator.setExitHandler(this.onUiautomatorExit.bind(this));73 this.onDie = onDie;74 async.series([75 this.prepareDevice.bind(this),76 this.prepareChromedriver.bind(this),77 this.pushAndUnlock.bind(this),78 this.forwardPort.bind(this),79 this.pushAppium.bind(this),80 this.uiautomator.start.bind(this.uiautomator),81 this.getDataDir.bind(this),82 this.createSession.bind(this)83 ], function (err, results) {84 if (err) return cb(err);85 var sessionId = results[results.length - 1];86 cb(null, sessionId);87 });88};89ChromeAndroid.prototype.prepareChromedriver = function (cb) {90 var chromeArgs = {91 port: this.args.proxyPort92 , executable: this.args.chromedriverExecutable93 , deviceId: this.adb.curDeviceId94 , enablePerformanceLogging: this.args.enablePerformanceLogging95 };96 this.chromedriver = new Chromedriver(chromeArgs,97 this.onChromedriverExit.bind(this));98 this.proxyTo = this.chromedriver.proxyTo.bind(this.chromedriver);99 this.proxyHost = this.chromedriver.proxyHost;100 this.proxyPort = this.chromedriver.proxyPort;101 this.deleteSession = this.chromedriver.deleteSession.bind(this.chromedriver);102 cb();103};104ChromeAndroid.prototype.pushAndUnlock = function (cb) {105 this.pushUnlock(function (err) {106 if (err) return cb(err);107 this.unlock(cb);108 }.bind(this));109};110ChromeAndroid.prototype.createSession = function (cb) {111 var caps = {112 chromeOptions: {113 androidPackage: this.args.appPackage,114 androidActivity: this.args.appActivity115 }116 };117 var knownPackages = ["org.chromium.chrome.testshell", "com.android.chrome",118 "com.chrome.beta"];119 if (_.contains(knownPackages, this.args.appPackage)) {120 delete caps.chromeOptions.androidActivity;121 }122 this.chromedriver.createSession(caps, cb);123};124ChromeAndroid.prototype.stop = function (cb) {125 this.uiautomator.shutdown(function () {126 this.chromedriver.stop(function (err) {127 if (err) return cb(err);128 this.adb.forceStop(this.args.appPackage, function (err) {129 if (err) return cb(err);130 this.adb.stopLogcat(cb);131 }.bind(this));132 }.bind(this));133 }.bind(this));134};135ChromeAndroid.prototype.onChromedriverExit = function () {136 async.series([137 this.adb.getConnectedDevices.bind(this.adb),138 _.partial(this.adb.forceStop.bind(this.adb), this.args.appPackage)139 ], function (err) {140 if (err) logger.error(err.message);141 this.adb.stopLogcat(this.onDie.bind(this));142 }.bind(this));143};144// since we're in chrome, our default context is not the native mode, but web145ChromeAndroid.prototype.defaultContext = function () {146 return WEBVIEW_BASE + "1";147};148// write a new getContexts function that hard-codes the two available contexts149ChromeAndroid.prototype.getContexts = function (cb) {150 this.contexts = [NATIVE_WIN, this.defaultContext()];151 logger.info("Available contexts: " + this.contexts);152 cb(null, {153 status: status.codes.Success.code154 , value: this.contexts155 });156};157// write a new setContext function that handles starting and stopping of158// chrome mode; the default android context controller method won't work here159// because here we don't need to worry about starting/stopping chromedriver160// itself; it's already on161ChromeAndroid.prototype.setContext = function (name, cb) {162 if (name === null) {163 name = this.defaultContext();164 } else if (name === WEBVIEW_WIN) {165 name = this.defaultContext();166 }167 this.getContexts(function () {168 if (!_.contains(this.contexts, name)) {169 return cb(null, {170 status: status.codes.NoSuchContext.code171 , value: "Context '" + name + "' does not exist"172 });173 }174 if (name === this.curContext) {175 return jwpSuccess(cb);176 }177 if (name.indexOf(WEBVIEW_WIN) !== -1) {178 this.setChromedriverMode();179 } else {180 this.setNativeMode();181 }182 this.curContext = name;183 jwpSuccess(cb);184 }.bind(this));185};...
Using AI Code Generation
1var androidDriver = require('appium-android-driver');2var driver = new androidDriver.AndroidDriver();3driver.uiAutomator.shutdown();4var androidDriver = require('appium-android-driver');5var driver = new androidDriver.AndroidDriver();6driver.uiAutomator.start();7var androidDriver = require('appium-android-driver');8var driver = new androidDriver.AndroidDriver();9driver.uiAutomator.reset();10var androidDriver = require('appium-android-driver');11var driver = new androidDriver.AndroidDriver();12driver.uiAutomator.isRunning();13var androidDriver = require('appium-android-driver');14var driver = new androidDriver.AndroidDriver();15driver.uiAutomator.isStopped();16var androidDriver = require('appium-android-driver');17var driver = new androidDriver.AndroidDriver();18driver.uiAutomator.isReset();19var androidDriver = require('appium-android-driver');20var driver = new androidDriver.AndroidDriver();21driver.uiAutomator.isShutDown();22var androidDriver = require('appium-android-driver');23var driver = new androidDriver.AndroidDriver();24driver.uiAutomator.isShuttingDown();25var androidDriver = require('appium-android-driver');26var driver = new androidDriver.AndroidDriver();27driver.uiAutomator.isStarting();28var androidDriver = require('appium-android-driver');29var driver = new androidDriver.AndroidDriver();30driver.uiAutomator.isResetting();31var androidDriver = require('appium-android-driver');32var driver = new androidDriver.AndroidDriver();33driver.uiAutomator.isStarting();34var androidDriver = require('appium-android-driver');
Using AI Code Generation
1var driver = wd.remote("localhost", 4723);2driver.init({3}, function () {4 driver.sleep(2000);5 driver.quit();6});7driver.on('quit', function () {8 console.log('Appium session is closed');9 driver.shutdown();10});11driver.on('shutdown', function () {12 console.log('Appium server is closed');13});
Using AI Code Generation
1var driver = require('./driver');2driver.shutdown().then(function() {3 console.log('shutdown success');4}, function(err) {5 console.log('shutdown failed');6});7var wd = require('wd');8var Q = require('q');9var driver = wd.promiseChainRemote('localhost', 4723);10var desiredCaps = {11};12var shutdown = function() {13 .init(desiredCaps)14 .then(function() {15 return driver.execute('mobile: shutdown', {});16 })17 .then(function() {18 return driver.quit();19 });20};21exports.shutdown = shutdown;
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5var driver = wd.promiseChainRemote("localhost", 4723);6 .init(desiredCaps)7 .elementByAccessibilityId('App').click()8 .elementByAccessibilityId('Activity').click()
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var should = require('should');4var appium = require('appium');5var server = appium.main;6var serverConfig = {7 appium: {8 appium: {9 }10 }11};12server(serverConfig, function (err, appiumServer) {13 if (err) {14 throw err;15 }16 var desiredCaps = {17 };18 var driver = wd.promiseChainRemote('localhost', 4723);19 driver.init(desiredCaps).then(function () {20 driver.uiAutomator('new UiSelector().text("Close")').click();21 console.log("Appium session closed");22 appiumServer.close();23 console.log("Appium server closed");24 });25});
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!!