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.initChromedriverPath.bind(this),97 this.prepareDevice.bind(this),98 this.checkApiLevel.bind(this),99 this.pushStrings.bind(this),100 this.processFromManifest.bind(this),101 this.uninstallApp.bind(this),102 this.installAppForTest.bind(this),103 this.forwardPort.bind(this),104 this.pushAppium.bind(this),105 this.initUnicode.bind(this),106 this.pushSettingsApp.bind(this),107 this.pushUnlock.bind(this),108 function (cb) {this.uiautomator.start(cb);}.bind(this),109 this.wakeUp.bind(this),110 this.unlock.bind(this),111 this.getDataDir.bind(this),112 this.setupCompressedLayoutHierarchy.bind(this),113 this.startAppUnderTest.bind(this),114 this.initAutoWebview.bind(this),115 this.setActualCapabilities.bind(this)116 ], function (err) {117 if (err) {118 this.shutdown(function () {119 this.launchCb(err);120 }.bind(this));121 } else {122 this.didLaunch = true;123 this.launchCb(null, this.proxySessionId);124 }125 }.bind(this));126};127Android.prototype.initUiautomator = function (cb) {128 if (this.uiautomator === null) {129 this.uiautomator = new UiAutomator(this.adb, this.args);130 this.uiautomator.setExitHandler(this.onUiautomatorExit.bind(this));131 }132 return cb();133};134Android.prototype.onLaunch = function (err) {135 var readyToGo = function () {136 this.didLaunch = true;137 this.launchCb();138 }.bind(this);139 var giveUp = function (err) {140 this.shutdown(function () {141 this.launchCb(err);142 }.bind(this));143 }.bind(this);144 if (err) {145 if (this.checkShouldRelaunch(err)) {146 logger.error(err);147 logger.error("Above error isn't fatal, maybe relaunching adb will help....");148 this.adb.waitForDevice(function (err) {149 if (err) return giveUp(err);150 readyToGo();151 });152 } else {153 giveUp(err);154 }155 } else {156 readyToGo();157 }158};159Android.prototype.restartUiautomator = function (cb) {160 async.series([161 this.forwardPort.bind(this)162 , this.uiautomator.start.bind(this.uiautomator)163 , this.setupCompressedLayoutHierarchy.bind(this)164 ], cb);165};166/*167 * Execute an arbitrary function and handle potential ADB disconnection before168 * proceeding169 */170Android.prototype.wrapActionAndHandleADBDisconnect = function (action, ocb) {171 async.series([172 function (cb) {173 this.uiautomatorIgnoreExit = true;174 action(cb);175 }.bind(this)176 , this.adb.restart.bind(this.adb)177 , this.restartUiautomator.bind(this)178 ], function (err) {179 this.uiautomatorIgnoreExit = false;180 ocb(err);181 }.bind(this));182};183Android.prototype.onUiautomatorExit = function () {184 logger.debug("UiAutomator exited");185 var respondToClient = function () {186 this.stopChromedriverProxies(function () {187 this.cleanup();188 if (!this.didLaunch) {189 var msg = "UiAutomator quit before it successfully launched";190 logger.error(msg);191 this.launchCb(new Error(msg));192 return;193 } else if (typeof this.cbForCurrentCmd === "function") {194 var error = new UnknownError("UiAutomator died while responding to " +195 "command, please check appium logs!");196 this.cbForCurrentCmd(error, null);197 }198 // make sure appium.js knows we crashed so it can clean up199 this.uiautomatorExitCb();200 }.bind(this));201 }.bind(this);202 if (this.adb) {203 var uninstall = function () {204 logger.debug("Attempting to uninstall app");205 this.uninstallApp(function () {206 this.shuttingDown = false;207 respondToClient();208 }.bind(this));209 }.bind(this);210 if (!this.uiautomatorIgnoreExit) {211 this.adb.ping(function (err, ok) {212 if (ok) {213 uninstall();214 } else {215 logger.debug(err);216 this.adb.restart(function (err) {217 if (err) {218 logger.debug(err);219 }220 if (this.uiautomatorRestartOnExit) {221 this.uiautomatorRestartOnExit = false;222 this.restartUiautomator(function (err) {223 if (err) {224 logger.debug(err);225 uninstall();226 }227 }.bind(this));228 } else {229 uninstall();230 }231 }.bind(this));232 }233 }.bind(this));234 } else {235 this.uiautomatorIgnoreExit = false;236 }237 } else {238 logger.debug("We're in uiautomator's exit callback but adb is gone already");239 respondToClient();240 }241};242Android.prototype.checkShouldRelaunch = function (launchErr) {243 if (launchErr.message === null || typeof launchErr.message === 'undefined') {244 logger.error("We're checking if we should relaunch based on something " +245 "which isn't an error object. Check the codez!");246 return false;247 }248 var msg = launchErr.message.toString();249 var relaunchOn = [250 'Could not find a connected Android device'251 , 'Device did not become ready'252 ];253 var relaunch = false;254 _.each(relaunchOn, function (relaunchMsg) {255 relaunch = relaunch || msg.indexOf(relaunchMsg) !== -1;256 });257 return relaunch;258};259Android.prototype.checkApiLevel = function (cb) {260 this.adb.getApiLevel(function (err, apiLevel) {261 if (err) return cb(err);262 logger.info('Device API level is:', parseInt(apiLevel, 10));263 if (parseInt(apiLevel) < 17) {264 var msg = "Android devices must be of API level 17 or higher. Please change your device to Selendroid or upgrade Android on your device.";265 logger.error(msg); // logs the error when we encounter it266 return cb(new Error(msg)); // send the error up the chain267 }268 cb();269 });270};271Android.prototype.decorateChromeOptions = function (caps) {272 // add options from appium session caps273 if (this.args.chromeOptions) {274 _.each(this.args.chromeOptions, function (val, option) {275 if (typeof caps.chromeOptions[option] === "undefined") {276 caps.chromeOptions[option] = val;277 } else {278 logger.warn("Cannot pass option " + caps.chromeOptions[option] + " because Appium needs it to make chromeDriver work");279 }280 });281 }282 // add device id from adb283 caps.chromeOptions.androidDeviceSerial = this.adb.curDeviceId;284 return caps;285};286Android.prototype.processFromManifest = function (cb) {287 if (!this.args.app) {288 return cb();289 } else { // apk must be local to process the manifest.290 this.adb.processFromManifest(this.args.app, function (err, process) {291 var value = process || this.args.appPackage;292 this.appProcess = value;293 logger.debug("Set app process to: " + this.appProcess);294 cb();295 }.bind(this));296 }297};298Android.prototype.pushStrings = function (cb, language) {299 var outputPath = path.resolve(this.args.tmpDir, this.args.appPackage);300 var remotePath = '/data/local/tmp';301 var stringsJson = 'strings.json';302 this.extractStrings(function (err) {303 if (err) {304 if (!fs.existsSync(this.args.app)) {305 // apk doesn't exist locally so remove old strings.json306 return this.adb.rimraf(remotePath + '/' + stringsJson, function (err) {307 if (err) return cb(new Error("Could not remove old strings"));308 cb();309 });310 } else {311 // if we can't get strings, just dump an empty json and continue312 var remoteFile = remotePath + '/' + stringsJson;313 return this.adb.shell("echo '{}' > " + remoteFile, cb);314 }315 }316 var jsonFile = path.resolve(outputPath, stringsJson);317 this.adb.push(jsonFile, remotePath, function (err) {318 if (err) return cb(new Error("Could not push strings.json"));319 cb();320 });321 }.bind(this), language);322};323Android.prototype.getStrings = function (language, stringFile, cb) {324 if (this.language && this.language === language) {325 // Return last strings326 return cb(null, {327 status: status.codes.Success.code,328 value: this.apkStrings329 });330 }331 // Extract, push and return strings332 return this.pushStrings(function () {333 this.proxy(["updateStrings", {}], function (err, res) {334 if (err || res.status !== status.codes.Success.code) return cb(err, res);335 cb(null, {336 status: status.codes.Success.code,337 value: this.apkStrings338 });339 }.bind(this));340 }.bind(this), language);341};342Android.prototype.pushAppium = function (cb) {343 logger.debug("Pushing appium bootstrap to device...");344 var binPath = path.resolve(__dirname, "..", "..", "..", "build",345 "android_bootstrap", "AppiumBootstrap.jar");346 fs.stat(binPath, function (err) {347 if (err) {348 cb(new Error("Could not find AppiumBootstrap.jar; please run " +349 "'grunt buildAndroidBootstrap'"));350 } else {351 this.adb.push(binPath, this.remoteTempPath(), cb);352 }353 }.bind(this));354};355Android.prototype.startAppUnderTest = function (cb) {356 this.startApp(this.args, cb);357};358Android.prototype.startApp = function (args, cb) {359 if (args.androidCoverage) {360 this.adb.androidCoverage(args.androidCoverage, args.appWaitPackage,361 args.appWaitActivity, cb);362 } else {363 this.adb.startApp({364 pkg: args.appPackage,365 activity: args.appActivity,366 action: args.intentAction,367 category: args.intentCategory,368 flags: args.intentFlags,369 waitPkg: args.appWaitPackage,370 waitActivity: args.appWaitActivity,371 optionalIntentArguments: args.optionalIntentArguments,372 stopApp: args.stopAppOnReset373 }, cb);374 }375};376Android.prototype.stop = function (cb) {377 if (this.shuttingDown) {378 logger.debug("Already in process of shutting down.");379 return cb();380 }381 this.shuttingDown = true;382 var completeShutdown = function (cb) {383 if (this.adb) {384 this.adb.goToHome(function () {385 this.shutdown(cb);386 }.bind(this));387 } else {388 this.shutdown(cb);389 }390 }.bind(this);391 if (this.args.fullReset) {392 logger.debug("Removing app from device");393 this.uninstallApp(function (err) {394 if (err) {395 // simply warn on error here, because we don't want to stop the shutdown396 // process397 logger.warn(err);398 }399 completeShutdown(cb);400 });401 } else {402 completeShutdown(cb);403 }404};405Android.prototype.cleanup = function () {406 logger.debug("Cleaning up android objects");407 this.adb = null;408 this.uiautomator = null;409 this.shuttingDown = false;410};411Android.prototype.shutdown = function (cb) {412 var next = function () {413 this.stopChromedriverProxies(function () {414 if (this.uiautomator) {415 this.uiautomator.shutdown(function () {416 this.cleanup();417 cb();418 }.bind(this));419 } else {420 this.cleanup();421 cb();422 }423 }.bind(this));424 }.bind(this);425 if (this.adb) {426 this.adb.endAndroidCoverage();427 if (this.args.unicodeKeyboard && this.args.resetKeyboard && this.defaultIME) {428 logger.debug('Resetting IME to \'' + this.defaultIME + '\'');429 this.adb.setIME(this.defaultIME, function (err) {430 if (err) {431 // simply warn on error here, because we don't want to stop the shutdown432 // process433 logger.warn(err);434 }435 if (this.adb) {436 this.adb.stopLogcat(function () {437 next();438 }.bind(this));439 }440 }.bind(this));441 } else {442 this.adb.stopLogcat(function () {443 next();444 }.bind(this));445 }446 } else {447 next();448 }449};450Android.prototype.proxy = deviceCommon.proxy;451Android.prototype.respond = deviceCommon.respond;452Android.prototype.initQueue = function () {453 this.queue = async.queue(function (task, cb) {454 var action = task.action,455 params = task.params;456 this.cbForCurrentCmd = cb;457 if (this.adb && !this.shuttingDown) {458 this.uiautomator.sendAction(action, params, function (response) {459 this.cbForCurrentCmd = null;460 if (typeof cb === 'function') {461 this.respond(response, cb);462 }463 }.bind(this));464 } else {465 this.cbForCurrentCmd = null;466 var msg = "Tried to send command to non-existent Android device, " +467 "maybe it shut down?";468 if (this.shuttingDown) {469 msg = "We're in the middle of shutting down the Android device, " +470 "so your request won't be executed. Sorry!";471 }472 this.respond({473 status: status.codes.UnknownError.code474 , value: msg475 }, cb);476 }477 }.bind(this), 1);478};479Android.prototype.push = function (elem) {480 this.queue.push({action: elem[0][0], params: elem[0][1] || {}}, elem[1]);481};482Android.prototype.wakeUp = function (cb) {483 // requires an appium bootstrap connection loaded484 logger.debug("Waking up device if it's not alive");485 this.proxy(["wake", {}], cb);486};487Android.prototype.getDataDir = function (cb) {488 this.proxy(["getDataDir", {}], function (err, res) {489 if (err) return cb(err);490 this.dataDir = res.value;491 logger.debug("dataDir set to: " + this.dataDir);492 cb();493 }.bind(this));494};495// Set CompressedLayoutHierarchy on the device based on current settings object496Android.prototype.setupCompressedLayoutHierarchy = function (cb) {497 // setup using cap498 if (_.has(this.args, 'ignoreUnimportantViews')) {499 // set the setting directly on the internal _settings object, this way we don't trigger an update event500 this.settings._settings.ignoreUnimportantViews = this.args.ignoreUnimportantViews;501 }502 if (_.isUndefined(this.getSetting("ignoreUnimportantViews"))) {503 return cb();504 }505 this.setCompressedLayoutHierarchy(this.getSetting("ignoreUnimportantViews"), cb);506};507// Set CompressedLayoutHierarchy on the device508Android.prototype.setCompressedLayoutHierarchy = function (compress, cb) {509 this.proxy(["compressedLayoutHierarchy", {compressLayout: compress}], cb);510};511Android.prototype.waitForActivityToStop = function (cb) {512 this.adb.waitForNotActivity(this.args.appWaitPackage, this.args.appWaitActivity, cb);513};514Android.prototype.setActualCapabilities = function (cb) {515 this.capabilities.deviceName = this.adb.udid || this.adb.curDeviceId;516 this.adb.shell("getprop ro.build.version.release", function (err, version) {517 if (err) {518 logger.warn(err);519 } else {520 logger.debug("Device is at release version " + version);521 this.capabilities.platformVersion = version;522 }523 }.bind(this));524 cb();525};526Android.prototype.resetTimeout = deviceCommon.resetTimeout;527Android.prototype.waitForCondition = deviceCommon.waitForCondition;528Android.prototype.implicitWaitForCondition = deviceCommon.implicitWaitForCondition;529Android.prototype.getSettings = deviceCommon.getSettings;530Android.prototype.updateSettings = deviceCommon.updateSettings;531_.extend(Android.prototype, androidController);532_.extend(Android.prototype, androidContextController);533_.extend(Android.prototype, androidCommon);534_.extend(Android.prototype, androidHybrid);...
chrome.js
Source:chrome.js
1"use strict";2var Android = require('./android.js')3 , Chromedriver = require('appium-chromedriver').default4 , _ = require('underscore')5 , logger = require('../../server/logger.js').get('appium')6 , status = require('../../server/status.js')7 , deviceCommon = require('../common.js')8 , jwpSuccess = deviceCommon.jwpSuccess9 , async = require('async')10 , ADB = require('./adb.js')11 , UiAutomator = require('./uiautomator.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.onDieCb = 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.shell";50 this.args.androidActivity = ".ChromeShellActivity";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.startAutomation = function (cb) {70 // this wrapper is required because uiautomator is not instantiated71 // at the beginning of the async#series call72 this.uiautomator.start(cb);73};74ChromeAndroid.prototype.start = function (cb, onDie) {75 this.adb = new ADB(this.args);76 this.uiautomator = new UiAutomator(this.adb, this.args);77 this.uiautomator.setExitHandler(this.onUiautomatorExit.bind(this));78 this.onDieCb = onDie;79 async.series([80 this.initAdb.bind(this),81 this.initUiautomator.bind(this),82 this.prepareDevice.bind(this),83 this.initChromedriverPath.bind(this),84 this.prepareChromedriver.bind(this),85 this.pushAndUnlock.bind(this),86 this.forwardPort.bind(this),87 this.pushAppium.bind(this),88 this.startAutomation.bind(this),89 this.getDataDir.bind(this),90 this.createSession.bind(this)91 ], function (err, results) {92 if (err) return cb(err);93 this.didLaunch = true;94 var sessionId = results[results.length - 1];95 cb(null, sessionId);96 }.bind(this));97};98ChromeAndroid.prototype.prepareChromedriver = function (cb) {99 var chromeArgs = {100 port: this.args.proxyPort,101 executable: this.args.chromedriverExecutable102 };103 this.chromedriver = new Chromedriver(chromeArgs);104 this.proxyReqRes = this.chromedriver.proxyReq.bind(this.chromedriver);105 cb();106};107ChromeAndroid.prototype.pushAndUnlock = function (cb) {108 this.pushUnlock(function (err) {109 if (err) return cb(err);110 this.unlock(cb);111 }.bind(this));112};113ChromeAndroid.prototype.createSession = function (cb) {114 var caps = {115 chromeOptions: {116 androidPackage: this.args.appPackage117 }118 };119 if (this.args.enablePerformanceLogging) {120 caps.loggingPrefs = {performance: 'ALL'};121 }122 var knownPackages = ["org.chromium.chrome.shell",123 "com.android.chrome",124 "com.chrome.beta"];125 if (!_.contains(knownPackages, this.args.appPackage)) {126 caps.chromeOptions.androidActivity = this.args.appActivity;127 }128 caps = this.decorateChromeOptions(caps);129 this.chromedriver.on(Chromedriver.EVENT_CHANGED, function (msg) {130 if (msg.state === Chromedriver.STATE_STOPPED) {131 logger.info("Chromedriver stopped unexpectedly on us, shutting down " +132 "then calling back up with the on-die callback");133 this.onChromedriverStop(this.onDieCb);134 }135 }.bind(this));136 this.chromedriver.start(caps).nodeify(cb);137};138ChromeAndroid.prototype.stop = function (cb) {139 // stop listening for the stopped state event140 this.chromedriver.removeAllListeners(Chromedriver.EVENT_CHANGED);141 // now we can handle the stop on our own142 this.chromedriver.stop().nodeify(function (err) {143 if (err) logger.warn("Error stopping Chromedriver: " + err.message);144 this.onChromedriverStop(cb);145 }.bind(this));146};147ChromeAndroid.prototype.onChromedriverStop = function (cb) {148 if (this.adb) {149 this.uiautomator.shutdown(function () {150 this.adb.forceStop(this.args.appPackage, function (err) {151 if (err) return cb(err);152 this.adb.stopLogcat(cb);153 }.bind(this));154 }.bind(this));155 } else {156 cb();157 }158};159// since we're in chrome, our default context is not the native mode, but web160ChromeAndroid.prototype.defaultContext = function () {161 return WEBVIEW_BASE + "1";162};163// write a new getContexts function that hard-codes the two available contexts164ChromeAndroid.prototype.getContexts = function (cb) {165 this.contexts = [NATIVE_WIN, this.defaultContext()];166 logger.info("Available contexts: " + this.contexts);167 cb(null, {168 status: status.codes.Success.code169 , value: this.contexts170 });171};172// write a new setContext function that handles starting and stopping of173// chrome mode; the default android context controller method won't work here174// because here we don't need to worry about starting/stopping chromedriver175// itself; it's already on176ChromeAndroid.prototype.setContext = function (name, cb) {177 if (name === null) {178 name = this.defaultContext();179 } else if (name === WEBVIEW_WIN) {180 name = this.defaultContext();181 }182 this.getContexts(function () {183 if (!_.contains(this.contexts, name)) {184 return cb(null, {185 status: status.codes.NoSuchContext.code186 , value: "Context '" + name + "' does not exist"187 });188 }189 if (name === this.curContext) {190 return jwpSuccess(cb);191 }192 if (name.indexOf(WEBVIEW_WIN) !== -1) {193 this.setChromedriverMode();194 } else {195 this.setNativeMode();196 }197 this.curContext = name;198 jwpSuccess(cb);199 }.bind(this));200};...
Using AI Code Generation
1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();10driver.uiAutomator.shutdown();11The method is not a function. (WARNING: The server did not provide any stacktrace information)12driver.uiAutomator.shutdown();13var webdriver = require('selenium-webdriver'),14 until = webdriver.until;15var driver = new webdriver.Builder()16 .forBrowser('chrome')17 .build();18driver.findElement(By.name('q')).sendKeys('webdriver');19driver.findElement(By.name('btnG')).click();20driver.wait(until.titleIs('webdriver - Google Search'), 1000);21driver.quit();22var webdriver = require('selenium-webdriver'),23 until = webdriver.until;24var driver = new webdriver.Builder()25 .forBrowser('chrome')26 .build();
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');3driver.findElement(webdriver.By.name('btnG')).click();4driver.wait(function() {5 return driver.getTitle().then(function(title) {6 return title === 'webdriver - Google Search';7 });8}, 1000);9driver.quit();10driver.uiAutomator.shutdown();11driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');12driver.findElement(webdriver.By.name('btnG')).click();13driver.wait(function() {14 return driver.getTitle().then(function(title) {15 return title === 'webdriver - Google Search';16 });17}, 1000);18driver.quit();
Using AI Code Generation
1var driver = require('appium-android-driver');2var uiautomator = new driver.UiAutomator();3uiautomator.shutdown();4var driver = require('appium-android-driver');5var uiautomator = new driver.UiAutomator();6uiautomator.start();7var driver = require('appium-android-driver');8var uiautomator = new driver.UiAutomator();9uiautomator.sendAction();10var driver = require('appium-android-driver');11var uiautomator = new driver.UiAutomator();12uiautomator.sendAction();13var driver = require('appium-android-driver');14var uiautomator = new driver.UiAutomator();15uiautomator.sendAction();16var driver = require('appium-android-driver');17var uiautomator = new driver.UiAutomator();18uiautomator.sendAction();19var driver = require('appium-android-driver');20var uiautomator = new driver.UiAutomator();21uiautomator.sendAction();22var driver = require('appium-android-driver');23var uiautomator = new driver.UiAutomator();24uiautomator.sendAction();25var driver = require('appium-android-driver');26var uiautomator = new driver.UiAutomator();27uiautomator.sendAction();28var driver = require('appium-android-driver');29var uiautomator = new driver.UiAutomator();30uiautomator.sendAction();31var driver = require('appium-android-driver');32var uiautomator = new driver.UiAutomator();33uiautomator.sendAction();
Using AI Code Generation
1describe('Appium Android Driver', function() {2 it('should close the app under test', function(done) {3 this.uiAutomator.shutdown(done);4 });5});61 passing (9s)7describe('Appium Android Driver', function() {8 it('should close the app under test', function(done) {9 this.uiAutomator.driver.quit(done);10 });11});121 passing (9s)13describe('Appium Android Driver', function() {14 it('should close the app under test', function(done) {15 this.uiAutomator.driver.resetApp(done);16 });
Using AI Code Generation
1var driver = new webdriver.Builder() .withCapabilities(webdriver.Capabilities.android()) .build();2driver.quit();3driver.uiAutomator.shutdown();4driver.quit();5driver.quit();6var driver = new webdriver.Builder() .withCapabilities(webdriver.Capabilities.android()) .build();7driver.quit();8driver.uiAutomator.shutdown();9driver.quit();10driver.quit();11var driver = new webdriver.Builder() .withCapabilities(webdriver.Capabilities.android()) .build();12But when I try to close the app using driver.quit(), it is throwing an error:13Uncaught Error: Error: Error response status: 13, UnknownError - An unknown server-side error occurred while processing the command. Selenium error: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 2 milliseconds Build info: version: '2.44.0', revision: '8a71439', time: '2014-12-03 17:33:17' System info: host: 'SeleniumGrid', ip: '
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .forBrowser('chrome')4 .build();5driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');6driver.findElement(webdriver.By.name('btnG')).click();7driver.wait(function() {8 return driver.getTitle().then(function(title) {9 return title === 'webdriver - Google Search';10 });11}, 1000);12driver.quit();13driver.uiAutomator("new UiSelector().text(\"Settings\")").click();14driver.uiAutomator("new UiSelector().text(\"Apps\")").click();15driver.uiAutomator("new UiSelector().text(\"Appium\")").click();16driver.uiAutomator("new UiSelector().text(\"Force stop\")").click();17driver.uiAutomator("new UiSelector().text(\"OK\")").click();18driver.uiAutomator("new UiSelector().text(\"Clear data\")").click();19driver.uiAutomator("new UiSelector().text(\"OK\")").click();20driver.uiAutomator("new UiSelector().text(\"OK\")").click();21driver.uiAutomator("new UiSelector().text(\"Apps\")").click();22driver.uiAutomator("new UiSelector().text(\"Settings\")").click();23driver.uiAutomator("new UiSelector().text(\"Developer options\")").click();24driver.uiAutomator("new UiSelector().text(\"Stay awake\")").click();25driver.uiAutomator("new UiSelector().text(\"OK\")").click();26driver.uiAutomator("new UiSelector().text(\"Apps\")").click();27driver.uiAutomator("new UiSelector().text(\"Appium\")").click();28driver.uiAutomator("new UiSelector().text(\"Clear cache\")").click();29driver.uiAutomator("new UiSelector().text(\"OK\")").click();30driver.uiAutomator("new UiSelector().text(\"OK\")").click();31driver.uiAutomator("new UiSelector().text(\"Apps\")").click();32driver.uiAutomator("new UiSelector().text(\"Settings\")").click();33driver.uiAutomator("new
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!!