Best JavaScript code snippet using appium-android-driver
driver.js
Source:driver.js
...326 disableWindowAnimation: !!this.opts.disableWindowAnimation,327 });328 this.proxyReqRes = this.uiautomator2.proxyReqRes.bind(this.uiautomator2);329 // killing any uiautomator existing processes330 await this.uiautomator2.killUiAutomatorOnDevice();331 await this.uiautomator2.installServerApk(this.opts.uiautomator2ServerInstallTimeout);332 }333 async initAUT () {334 // set the localized strings for the current language from the apk335 // TODO: incorporate changes from appium#5308 which fix a race cond-336 // ition bug in old appium and need to be replicated here337 this.apkStrings[this.opts.language] = await androidHelpers.pushStrings(338 this.opts.language, this.adb, this.opts);339 // Install any "otherApps" that were specified in caps340 if (this.opts.otherApps) {341 let otherApps;342 try {343 otherApps = helpers.parseArray(this.opts.otherApps);344 } catch (e) {...
uiautomator2.js
Source:uiautomator2.js
...89 return false;90 }91 async startSession (caps) {92 // kill any uiautomator existing processes93 await this.killUiAutomatorOnDevice();94 logger.info(`Starting uiautomator2 server ${serverVersion}`);95 logger.info(`Using UIAutomator2 server from '${apkPath}' and test from '${testApkPath}'`);96 // let cmd = ['am', 'instrument', '-w',97 // 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner'];98 // this.adb.shell(cmd);99 // using 3rd party module called 'adbKit' for time being as using 'appium-adb'100 // facing IllegalStateException: UiAutomation not connected exception101 // https://github.com/appium/appium-uiautomator2-driver/issues/19102 await this.startSessionUsingAdbKit(caps.deviceUDID);103 let retries = getRetries('Server launch', caps.uiautomator2ServerLaunchTimeout, SERVER_LAUNCH_RETRIES);104 logger.info(`Waiting up to ${retries * 1000}ms for UiAutomator2 to be online...`);105 // wait for UiAutomator2 to be online106 await retryInterval(retries, 1000, this.jwproxy.command.bind(this.jwproxy), '/status', 'GET');107 await this.jwproxy.command('/session', 'POST', {desiredCapabilities: caps});...
uiautomator.js
Source:uiautomator.js
...19 // expecting a path like /ads/ads/foo.jar or \asd\asd\foo.jar20 let jarName = this.parseJarNameFromPath(uiAutomatorBinaryPath);21 await this.adb.push(uiAutomatorBinaryPath, this.tempPath);22 // killing any uiautomator existing processes23 await this.killUiAutomatorOnDevice();24 log.debug('Starting UIAutomator');25 let args = ['shell', 'uiautomator', 'runtest', jarName, '-c', className, ...extraParams];26 this.proc = this.adb.createSubProcess(args);27 // handle out-of-bound exit by simply emitting a stopped state28 this.proc.on('exit', (code, signal) => {29 processIsAlive = false;30 // cleanup31 if (this.state !== UiAutomator.STATE_STOPPED &&32 this.state !== UiAutomator.STATE_STOPPING) {33 let msg = `UiAutomator exited unexpectedly with code ${code}, ` +34 `signal ${signal}`;35 log.error(msg);36 } else if (this.state === UiAutomator.STATE_STOPPING) {37 log.debug('UiAutomator shut down normally');38 }39 this.changeState(UiAutomator.STATE_STOPPED);40 });41 await this.proc.start(startDetector);42 processIsAlive = true;43 this.changeState(UiAutomator.STATE_ONLINE);44 return this.proc;45 } catch (e) {46 this.emit(UiAutomator.EVENT_ERROR, e);47 if (processIsAlive) {48 await this.killUiAutomatorOnDevice();49 await this.proc.stop();50 }51 log.errorAndThrow(e);52 }53 }54 async shutdown () {55 log.debug('Shutting down UiAutomator');56 if (this.state !== UiAutomator.STATE_STOPPED) {57 this.changeState(UiAutomator.STATE_STOPPING);58 await this.proc.stop();59 }60 await this.killUiAutomatorOnDevice();61 this.changeState(UiAutomator.STATE_STOPPED);62 }63 parseJarNameFromPath (binaryPath) {64 let reTest = /.*(\/|\\)(.*\.jar)/.exec(binaryPath);65 if (!reTest) {66 throw new Error(`Unable to parse jar name from ${binaryPath}`);67 }68 let jarName = reTest[2];69 log.debug(`Found jar name: '${jarName}'`);70 return jarName;71 }72 changeState (state) {73 log.debug(`Moving to state '${state}'`);74 this.state = state;...
Using AI Code Generation
1var wd = require('wd'),2 Q = require('q');3driver.init({4}).then(function () {5 return driver.killUiAutomatorOnDevice();6}).then(function () {7 console.log('UiAutomator killed');8}).fin(function () {9 driver.quit();10}).done();11var wd = require('wd'),12 Q = require('q');13driver.init({14}).then(function () {15 return driver.killUiAutomatorOnDevice();16}).then(function () {17 console.log('UiAutomator killed');18}).fin(function () {19 driver.quit();20}).done();21var wd = require('wd'),22 Q = require('q');23driver.init({24}).then(function () {25 return driver.killUiAutomatorOnDevice();26}).then(function () {27 console.log('UiAutomator killed');28}).fin(function () {29 driver.quit();30}).done();31var wd = require('wd'),32 Q = require('
Using AI Code Generation
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.startUiAutomatorOnDevice();9 })10 .then(function () {11 return driver.killUiAutomatorOnDevice();12 })13 .then(function () {14 return driver.quit();15 })16 .done();17info: Welcome to Appium v1.6.4 (REV 9f4e4e4c5f0c2d2a8e4b0f1b5e5c5b5d9dc5b5e5)
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!!