Best JavaScript code snippet using appium-android-driver
apk-utils-specs.js
Source:apk-utils-specs.js
...362 mocks.adb.expects("getApiLevel").returns(18);363 mocks.adb.expects("shell")364 .once().withExactArgs(['getprop', 'persist.sys.language'])365 .returns(language);366 (await adb.getDeviceLanguage()).should.equal(language);367 mocks.adb.verify();368 });369 it('should call shell two times with correct args and return language when API < 23', async () => {370 mocks.adb.expects("getApiLevel").returns(18);371 mocks.adb.expects("shell")372 .once().withExactArgs(['getprop', 'persist.sys.language'])373 .returns('');374 mocks.adb.expects("shell")375 .once().withExactArgs(['getprop', 'ro.product.locale.language'])376 .returns(language);377 (await adb.getDeviceLanguage()).should.equal(language);378 mocks.adb.verify();379 });380 it('should call shell one time with correct args and return language when API = 23', async () => {381 mocks.adb.expects("getApiLevel").returns(23);382 mocks.adb.expects("shell")383 .once().withExactArgs(['getprop', 'persist.sys.locale'])384 .returns(locale);385 (await adb.getDeviceLanguage()).should.equal(language);386 mocks.adb.verify();387 });388 it('should call shell two times with correct args and return language when API = 23', async () => {389 mocks.adb.expects("getApiLevel").returns(23);390 mocks.adb.expects("shell")391 .once().withExactArgs(['getprop', 'persist.sys.locale'])392 .returns('');393 mocks.adb.expects("shell")394 .once().withExactArgs(['getprop', 'ro.product.locale'])395 .returns(locale);396 (await adb.getDeviceLanguage()).should.equal(language);397 mocks.adb.verify();398 });399 }));400 describe('setDeviceLanguage', withMocks({adb}, (mocks) => {401 it('should call shell one time with correct args when API < 23', async () => {402 mocks.adb.expects("getApiLevel")403 .once().returns(21);404 mocks.adb.expects("shell")405 .once().withExactArgs(['setprop', 'persist.sys.language', language])406 .returns("");407 await adb.setDeviceLanguage(language);408 mocks.adb.verify();409 });410 }));...
general-specs.js
Source:general-specs.js
1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import sinon from 'sinon';4import AndroidDriver from '../../..';5import { parseSurfaceLine, parseWindows } from '../../../lib/commands/general';6import helpers from '../../../lib/android-helpers';7import { withMocks } from 'appium-test-support';8import { fs } from 'appium-support';9import Bootstrap from 'appium-android-bootstrap';10import B from 'bluebird';11import ADB from 'appium-adb';12chai.should();13chai.use(chaiAsPromised);14let driver;15let sandbox = sinon.sandbox.create();16let expect = chai.expect;17describe('General', () => {18 beforeEach(() => {19 driver = new AndroidDriver();20 driver.bootstrap = new Bootstrap();21 driver.adb = new ADB();22 driver.caps = {};23 driver.opts = {};24 });25 afterEach(() => {26 sandbox.restore();27 });28 describe('keys', () => {29 it('should send keys via setText bootstrap command', async () => {30 sandbox.stub(driver.bootstrap, 'sendAction');31 driver.opts.unicodeKeyboard = true;32 await driver.keys('keys');33 driver.bootstrap.sendAction34 .calledWithExactly('setText',35 {text: 'keys', replace: false, unicodeKeyboard: true})36 .should.be.true;37 });38 it('should join keys if keys is array', async () => {39 sandbox.stub(driver.bootstrap, 'sendAction');40 driver.opts.unicodeKeyboard = false;41 await driver.keys(['k', 'e', 'y', 's']);42 driver.bootstrap.sendAction43 .calledWithExactly('setText', {text: 'keys', replace: false})44 .should.be.true;45 });46 });47 describe('getDeviceTime', () => {48 it('should return device time', async () => {49 sandbox.stub(driver.adb, 'shell');50 driver.adb.shell.returns(' 11:12 ');51 await driver.getDeviceTime().should.become('11:12');52 driver.adb.shell.calledWithExactly(['date']).should.be.true;53 });54 it('should thorws error if shell command failed', async () => {55 sandbox.stub(driver.adb, 'shell').throws();56 await driver.getDeviceTime().should.be.rejectedWith('Could not capture');57 });58 });59 describe('getPageSource', () => {60 it('should return page source', async () => {61 sandbox.stub(driver.bootstrap, 'sendAction').withArgs('source').returns('sources');62 await driver.getPageSource().should.be.equal('sources');63 });64 });65 describe('back', () => {66 it('should press back', async () => {67 sandbox.stub(driver.bootstrap, 'sendAction');68 await driver.back();69 driver.bootstrap.sendAction.calledWithExactly('pressBack').should.be.true;70 });71 });72 describe('isKeyboardShown', () => {73 it('should return true if the keyboard is shown', async () => {74 driver.adb.isSoftKeyboardPresent = () => { return {isKeyboardShown: true, canCloseKeyboard: true}; };75 (await driver.isKeyboardShown()).should.equal(true);76 });77 it('should return false if the keyboard is not shown', async () => {78 driver.adb.isSoftKeyboardPresent = () => { return {isKeyboardShown: false, canCloseKeyboard: true}; };79 (await driver.isKeyboardShown()).should.equal(false);80 });81 });82 describe('hideKeyboard', () => {83 it('should hide keyboard via back command', async () => {84 sandbox.stub(driver, 'back');85 driver.adb.isSoftKeyboardPresent = () => { return {isKeyboardShown: true, canCloseKeyboard: true}; };86 await driver.hideKeyboard();87 driver.back.calledOnce.should.be.true;88 });89 it('should not call back command if can\'t close keyboard', async () => {90 sandbox.stub(driver, 'back');91 driver.adb.isSoftKeyboardPresent = () => { return {isKeyboardShown: true, canCloseKeyboard: false}; };92 await driver.hideKeyboard();93 driver.back.notCalled.should.be.true;94 });95 it('should throw an error if no keyboard is present', async () => {96 driver.adb.isSoftKeyboardPresent = () => { return false; };97 await driver.hideKeyboard().should.be.rejectedWith(/not present/);98 });99 });100 describe('openSettingsActivity', () => {101 it('should open settings activity', async () => {102 sandbox.stub(driver.adb, 'getFocusedPackageAndActivity')103 .returns({appPackage: 'pkg', appActivity: 'act'});104 sandbox.stub(driver.adb, 'shell');105 sandbox.stub(driver.adb, 'waitForNotActivity');106 await driver.openSettingsActivity('set1');107 driver.adb.shell.calledWithExactly(['am', 'start', '-a', 'android.settings.set1'])108 .should.be.true;109 driver.adb.waitForNotActivity.calledWithExactly('pkg', 'act', 5000)110 .should.be.true;111 });112 });113 describe('getWindowSize', () => {114 it('should get window size', async () => {115 sandbox.stub(driver.bootstrap, 'sendAction')116 .withArgs('getDeviceSize').returns('size');117 await driver.getWindowSize().should.be.equal('size');118 });119 });120 describe('getCurrentActivity', () => {121 it('should get current activity', async () => {122 sandbox.stub(driver.adb, 'getFocusedPackageAndActivity')123 .returns({appActivity: 'act'});124 await driver.getCurrentActivity().should.eventually.be.equal('act');125 });126 });127 describe('getCurrentPackage', () => {128 it('should get current activity', async () => {129 sandbox.stub(driver.adb, 'getFocusedPackageAndActivity')130 .returns({appPackage: 'pkg'});131 await driver.getCurrentPackage().should.eventually.equal('pkg');132 });133 });134 describe('getLogTypes', () => {135 it('should get log types', async () => {136 await driver.getLogTypes().should.be.deep.equal(['logcat']);137 });138 });139 describe('getLog', () => {140 it('should get log types', async () => {141 sandbox.stub(driver.adb, 'getLogcatLogs').returns('logs');142 await driver.getLog('logcat').should.be.equal('logs');143 });144 it('should throws exception if log type is unsupported', async () => {145 expect(() => driver.getLog('unsupported_type'))146 .to.throw('Unsupported log type unsupported_type');147 });148 });149 describe('isAppInstalled', () => {150 it('should return true if app is installed', async () => {151 sandbox.stub(driver.adb, 'isAppInstalled').withArgs('pkg').returns(true);152 await driver.isAppInstalled('pkg').should.be.true;153 });154 });155 describe('removeApp', () => {156 it('should remove app', async () => {157 sandbox.stub(driver.adb, 'uninstallApk').withArgs('pkg').returns(true);158 await driver.removeApp('pkg').should.be.true;159 });160 });161 describe('installApp', () => {162 it('should install app', async () => {163 driver.opts.fastReset = 'fastReset';164 let app = 'app.apk';165 let opts = {app: 'app.apk', appPackage: 'pkg', fastReset: 'fastReset'};166 sandbox.stub(driver.helpers, 'configureApp').withArgs('app', '.apk')167 .returns(app);168 sandbox.stub(fs, 'exists').withArgs(app).returns(true);169 sandbox.stub(driver.adb, 'packageAndLaunchActivityFromManifest')170 .withArgs(app).returns({apkPackage: 'pkg'});171 sandbox.stub(helpers, 'installApkRemotely')172 .returns(true);173 await driver.installApp('app').should.eventually.be.true;174 driver.helpers.configureApp.calledOnce.should.be.true;175 fs.exists.calledOnce.should.be.true;176 driver.adb.packageAndLaunchActivityFromManifest.calledOnce.should.be.true;177 helpers.installApkRemotely.calledWithExactly(driver.adb, opts)178 .should.be.true;179 });180 it('should throw an error if APK does not exist', async () => {181 await driver.installApp('non/existent/app.apk').should.be.rejectedWith(/Could not find/);182 });183 });184 describe('background', function () {185 it('should bring app to background and back', async function () {186 const appPackage = 'wpkg';187 const appActivity = 'wacv';188 driver.opts = {appPackage, appActivity, intentAction: 'act',189 intentCategory: 'cat', intentFlags: 'flgs',190 optionalIntentArguments: 'opt'};191 let params = {pkg: appPackage, activity: appActivity, action: 'act', category: 'cat',192 flags: 'flgs',193 optionalIntentArguments: 'opt', stopApp: false};194 sandbox.stub(driver.adb, 'goToHome');195 sandbox.stub(driver.adb, 'getFocusedPackageAndActivity')196 .returns({appPackage, appActivity});197 sandbox.stub(B, 'delay');198 sandbox.stub(driver.adb, 'startApp');199 await driver.background(10);200 driver.adb.getFocusedPackageAndActivity.calledOnce.should.be.true;201 driver.adb.goToHome.calledOnce.should.be.true;202 B.delay.calledWithExactly(10000).should.be.true;203 driver.adb.startApp.calledWithExactly(params).should.be.true;204 });205 it('should bring app to background and back if started after session init', async function () {206 const appPackage = 'newpkg';207 const appActivity = 'newacv';208 driver.opts = {appPackage: 'pkg', appActivity: 'acv', intentAction: 'act',209 intentCategory: 'cat', intentFlags: 'flgs',210 optionalIntentArguments: 'opt'};211 let params = {pkg: appPackage, activity: appActivity, action: 'act', category: 'cat',212 flags: 'flgs', waitPkg: 'wpkg', waitActivity: 'wacv',213 optionalIntentArguments: 'opt', stopApp: false};214 driver.opts.startActivityArgs = {[`${appPackage}/${appActivity}`]: params};215 sandbox.stub(driver.adb, 'goToHome');216 sandbox.stub(driver.adb, 'getFocusedPackageAndActivity')217 .returns({appPackage, appActivity});218 sandbox.stub(B, 'delay');219 sandbox.stub(driver.adb, 'startApp');220 await driver.background(10);221 driver.adb.getFocusedPackageAndActivity.calledOnce.should.be.true;222 driver.adb.goToHome.calledOnce.should.be.true;223 B.delay.calledWithExactly(10000).should.be.true;224 driver.adb.startApp.calledWithExactly(params).should.be.true;225 });226 it('should not bring app back if seconds are negative', async function () {227 sandbox.stub(driver.adb, 'goToHome');228 sandbox.stub(driver.adb, 'startApp');229 await driver.background(-1);230 driver.adb.goToHome.calledOnce.should.be.true;231 driver.adb.startApp.notCalled.should.be.true;232 });233 });234 describe('getStrings', withMocks({helpers}, (mocks) => {235 it('should return app strings', async () => {236 driver.bootstrap.sendAction = () => { return ''; };237 mocks.helpers.expects("pushStrings")238 .returns({test: 'en_value'});239 let strings = await driver.getStrings('en');240 strings.test.should.equal('en_value');241 mocks.helpers.verify();242 });243 it('should return cached app strings for the specified language', async () => {244 driver.adb.getDeviceLanguage = () => { return 'en'; };245 driver.apkStrings.en = {test: 'en_value'};246 driver.apkStrings.fr = {test: 'fr_value'};247 let strings = await driver.getStrings('fr');248 strings.test.should.equal('fr_value');249 });250 it('should return cached app strings for the device language', async () => {251 driver.adb.getDeviceLanguage = () => { return 'en'; };252 driver.apkStrings.en = {test: 'en_value'};253 driver.apkStrings.fr = {test: 'fr_value'};254 let strings = await driver.getStrings();255 strings.test.should.equal('en_value');256 });257 }));258 describe('launchApp', () => {259 it('should init and start app', async () => {260 sandbox.stub(driver, 'initAUT');261 sandbox.stub(driver, 'startAUT');262 await driver.launchApp();263 driver.initAUT.calledOnce.should.be.true;264 driver.startAUT.calledOnce.should.be.true;265 });266 });267 describe('startActivity', () => {268 let params;269 beforeEach(() => {270 params = {pkg: 'pkg', activity: 'act', waitPkg: 'wpkg', waitActivity: 'wact',271 action: 'act', category: 'cat', flags: 'flgs', optionalIntentArguments: 'opt'};272 sandbox.stub(driver.adb, 'startApp');273 });274 it('should start activity', async () => {275 params.optionalIntentArguments = 'opt';276 params.stopApp = false;277 await driver.startActivity('pkg', 'act', 'wpkg', 'wact', 'act',278 'cat', 'flgs', 'opt', true);279 driver.adb.startApp.calledWithExactly(params).should.be.true;280 });281 it('should use dontStopAppOnReset from opts if it is not passed as param', async () => {282 driver.opts.dontStopAppOnReset = true;283 params.stopApp = false;284 await driver.startActivity('pkg', 'act', 'wpkg', 'wact', 'act', 'cat', 'flgs', 'opt');285 driver.adb.startApp.calledWithExactly(params).should.be.true;286 });287 it('should use appPackage and appActivity if appWaitPackage and appWaitActivity are undefined', async () => {288 params.waitPkg = 'pkg';289 params.waitActivity = 'act';290 params.stopApp = true;291 await driver.startActivity('pkg', 'act', null, null, 'act', 'cat', 'flgs', 'opt', false);292 driver.adb.startApp.calledWithExactly(params).should.be.true;293 });294 });295 describe('reset', () => {296 it('should reset app via reinstall if fullReset is true', async () => {297 driver.opts.fullReset = true;298 driver.opts.appPackage = 'pkg';299 sandbox.stub(driver.adb, 'stopAndClear');300 sandbox.stub(driver.adb, 'uninstallApk');301 sandbox.stub(helpers, 'installApkRemotely');302 sandbox.stub(driver, 'grantPermissions');303 sandbox.stub(driver, 'startAUT').returns('aut');304 await driver.reset().should.eventually.be.equal('aut');305 driver.adb.stopAndClear.calledWithExactly('pkg').should.be.true;306 driver.adb.uninstallApk.calledWithExactly('pkg').should.be.true;307 helpers.installApkRemotely.calledWithExactly(driver.adb, driver.opts)308 .should.be.true;309 driver.grantPermissions.calledOnce.should.be.true;310 driver.startAUT.calledOnce.should.be.true;311 });312 it('should do fast reset if fullReset is false', async () => {313 driver.opts.fullReset = false;314 driver.opts.appPackage = 'pkg';315 sandbox.stub(driver.adb, 'stopAndClear');316 sandbox.stub(driver, 'grantPermissions');317 sandbox.stub(driver, 'startAUT').returns('aut');318 await driver.reset().should.eventually.be.equal('aut');319 driver.adb.stopAndClear.calledWithExactly('pkg').should.be.true;320 driver.grantPermissions.calledOnce.should.be.true;321 driver.startAUT.calledOnce.should.be.true;322 });323 });324 describe('startAUT', () => {325 it('should start AUT', async () => {326 driver.opts = {appPackage: 'pkg', appActivity: 'act', intentAction: 'actn',327 intentCategory: 'cat', intentFlags: 'flgs', appWaitPackage: 'wpkg',328 appWaitActivity: 'wact', appWaitDuration: 'wdur',329 optionalIntentArguments: 'opt'};330 let params = {pkg: 'pkg', activity: 'act', action: 'actn', category: 'cat',331 flags: 'flgs', waitPkg: 'wpkg', waitActivity: 'wact',332 waitDuration: 'wdur', optionalIntentArguments: 'opt', stopApp: false};333 driver.opts.dontStopAppOnReset = true;334 params.stopApp = false;335 sandbox.stub(driver.adb, 'startApp');336 await driver.startAUT();337 driver.adb.startApp.calledWithExactly(params).should.be.true;338 });339 });340 describe('setUrl', () => {341 it('should set url', async () => {342 driver.opts = {appPackage: 'pkg'};343 sandbox.stub(driver.adb, 'startUri');344 await driver.setUrl('url');345 driver.adb.startUri.calledWithExactly('url', 'pkg').should.be.true;346 });347 });348 describe('closeApp', () => {349 it('should close app', async () => {350 driver.opts = {appPackage: 'pkg'};351 sandbox.stub(driver.adb, 'forceStop');352 await driver.closeApp();353 driver.adb.forceStop.calledWithExactly('pkg').should.be.true;354 });355 });356 describe('getDisplayDensity', () => {357 it('should return the display density of a device', async () => {358 driver.adb.shell = () => { return '123'; };359 (await driver.getDisplayDensity()).should.equal(123);360 });361 it('should return the display density of an emulator', async () => {362 driver.adb.shell = (cmd) => {363 let joinedCmd = cmd.join(' ');364 if (joinedCmd.indexOf('ro.sf') !== -1) {365 // device property look up366 return '';367 } else if (joinedCmd.indexOf('qemu.sf') !== -1) {368 // emulator property look up369 return '456';370 }371 return '';372 };373 (await driver.getDisplayDensity()).should.equal(456);374 });375 it('should throw an error if the display density property can\'t be found', async () => {376 driver.adb.shell = () => { return ''; };377 await driver.getDisplayDensity().should.be.rejectedWith(/Failed to get display density property/);378 });379 it('should throw and error if the display density is not a number', async () => {380 driver.adb.shell = () => { return 'abc'; };381 await driver.getDisplayDensity().should.be.rejectedWith(/Failed to get display density property/);382 });383 });384 describe('parseSurfaceLine', () => {385 it('should return visible true if the surface is visible', async () => {386 parseSurfaceLine('shown=true rect=1 1 1 1').should.be.eql({387 visible: true,388 x: 1,389 y: 1,390 width: 1,391 height: 1392 });393 });394 it('should return visible false if the surface is not visible', async () => {395 parseSurfaceLine('shown=false rect=1 1 1 1').should.be.eql({396 visible: false,397 x: 1,398 y: 1,399 width: 1,400 height: 1401 });402 });403 it('should return the parsed surface bounds', async () => {404 parseSurfaceLine('shown=true rect=(1.0,2.0) 3.0 x 4.0').should.be.eql({405 visible: true,406 x: 1,407 y: 2,408 width: 3,409 height: 4410 });411 });412 });413 // these are used for both parseWindows and getSystemBars tests414 let validWindowOutput = [415 ' Window #1 Derp',416 ' stuff',417 ' Surface: derp shown=false lalalala rect=(9.0,8.0) 7.0 x 6.0',418 ' more stuff',419 ' Window #2 StatusBar',420 ' blah blah blah',421 ' Surface: blah blah shown=true blah blah rect=(1.0,2.0) 3.0 x 4.0',422 ' blah blah blah',423 ' Window #3 NavigationBar',424 ' womp womp',425 ' Surface: blah blah shown=false womp womp rect=(5.0,6.0) 50.0 x 60.0',426 ' qwerty asd zxc'427 ].join('\n');428 let validSystemBars = {429 statusBar: {visible: true, x: 1, y: 2, width: 3, height: 4},430 navigationBar: {visible: false, x: 5, y: 6, width: 50, height: 60}431 };432 describe('parseWindows', () => {433 it('should throw an error if the status bar info wasn\'t found', async () => {434 expect(() => { parseWindows(''); })435 .to.throw(Error, /Failed to parse status bar information./);436 });437 it('should throw an error if the navigation bar info wasn\'t found', async () => {438 let windowOutput = [439 ' Window #1 StatusBar',440 ' blah blah blah',441 ' Surface: blah blah shown=true blah blah rect=(1.0,2.0) 3.0 x 4.0',442 ' blah blah blah'443 ].join('\n');444 expect(() => { parseWindows(windowOutput); })445 .to.throw(Error, /Failed to parse navigation bar information./);446 });447 it('should return status and navigation bar info when both are given', async () => {448 parseWindows(validWindowOutput).should.be.eql(validSystemBars);449 });450 });451 describe('getSystemBars', () => {452 it('should throw an error if there\'s no window manager output', async () => {453 driver = new AndroidDriver();454 driver.adb = {};455 driver.adb.shell = () => { return ''; };456 await driver.getSystemBars().should.be.rejectedWith(/Did not get window manager output./);457 });458 it('should return the parsed system bar info', async () => {459 driver = new AndroidDriver();460 driver.adb = {};461 driver.adb.shell = () => { return validWindowOutput; };462 (await driver.getSystemBars()).should.be.eql(validSystemBars);463 });464 });...
general.js
Source:general.js
...22 await this.adb.keyevent(4);23};24commands.getStrings = async function (language) {25 if (!language) {26 language = await this.adb.getDeviceLanguage();27 log.info(`No language specified, returning strings for: ${language}`);28 }29 if (this.apkStrings[language]) {30 // Return cached strings31 return this.apkStrings[language];32 }33 // TODO: This is mutating the current language, but it's how appium currently works34 this.apkStrings[language] = await androidHelpers.pushStrings(language, this.adb, this.opts);35 await this.uiautomator2.jwproxy.command(`/appium/app/strings`, 'POST', {});36 return this.apkStrings[language];37};38// memoized in constructor39commands.getWindowSize = async function () {40 return await this.uiautomator2.jwproxy.command('/window/current/size', 'GET', {});...
android-helper-e2e-specs.js
Source:android-helper-e2e-specs.js
...39 });40 it('should set device language and country', async function () {41 await helpers.ensureDeviceLocale(adb, 'fr', 'FR');42 if (await adb.getApiLevel() < 23) {43 await adb.getDeviceLanguage().should.eventually.equal('fr');44 await adb.getDeviceCountry().should.eventually.equal('FR');45 } else {46 await adb.getDeviceLocale().should.eventually.equal('fr-FR');47 }48 });49 it('should set device language and country with script', async function () {50 await helpers.ensureDeviceLocale(adb, 'zh', 'CN', 'Hans');51 if (await adb.getApiLevel() < 23) {52 await adb.getDeviceLanguage().should.eventually.equal('fr');53 await adb.getDeviceCountry().should.eventually.equal('FR');54 } else {55 await adb.getDeviceLocale().should.eventually.equal('fr-Hans-CN');56 }57 });58 });59 describe('pushSettingsApp', function () {60 const settingsPkg = 'io.appium.settings';61 it('should be able to upgrade from settings v1 to latest', async function () {62 await adb.uninstallApk(settingsPkg);63 // get and install old version of settings app64 await exec('npm', ['install', `${settingsPkg}@2.0.0`]);65 // old version has a different apk path, so manually enter66 // otherwise pushing the app will fail because import will have the old...
language-e2e-specs.js
Source:language-e2e-specs.js
...25 }26 });27 async function getLocale (adb) {28 if (await adb.getApiLevel() < 23) {29 const language = await adb.getDeviceLanguage();30 const country = await adb.getDeviceCountry();31 return `${language}-${country}`;32 } else {33 return await adb.getDeviceLocale();34 }35 }36 it('should start as FR', async function () {37 let frCaps = Object.assign({}, DEFAULT_CAPS, {language: 'fr', locale: 'FR'});38 await driver.createSession(frCaps);39 await getLocale(driver.adb).should.eventually.equal('fr-FR');40 });41 it('should start as US', async function () {42 let usCaps = Object.assign({}, DEFAULT_CAPS, {language: 'en', locale: 'US'});43 await driver.createSession(usCaps);...
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('btnK')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();10var webdriver = require('selenium-webdriver'),11 until = webdriver.until;12var driver = new webdriver.Builder()13 .forBrowser('chrome')14 .build();15driver.findElement(By.name('q')).sendKeys('webdriver');16driver.findElement(By.name('btnK')).click();17driver.wait(until.titleIs('webdriver - Google Search'), 1000);18driver.quit();19var webdriver = require('selenium-webdriver'),20 until = webdriver.until;21var driver = new webdriver.Builder()22 .forBrowser('chrome')23 .build();24driver.findElement(By.name('q')).sendKeys('webdriver');25driver.findElement(By.name('btnK')).click();26driver.wait(until.titleIs('webdriver - Google Search'), 1000);27driver.quit();28var webdriver = require('selenium-webdriver'),29 until = webdriver.until;30var driver = new webdriver.Builder()31 .forBrowser('chrome')32 .build();33driver.findElement(By.name('q')).sendKeys('webdriver');34driver.findElement(By.name('btnK')).click();35driver.wait(until.titleIs('webdriver - Google Search'), 1000);36driver.quit();37var webdriver = require('selenium-webdriver'),38 until = webdriver.until;39var driver = new webdriver.Builder()40 .forBrowser('chrome')41 .build();42driver.findElement(By.name('q')).sendKeys('webdriver');43driver.findElement(By.name('btnK
Using AI Code Generation
1var adb = require('appium-adb');2var language = adb.getDeviceLanguage();3console.log(language);4var adb = require('appium-adb');5var language = adb.setDeviceLanguage("en");6console.log(language);7var adb = require('appium-adb');8var country = adb.getDeviceCountry();9console.log(country);10var adb = require('appium-adb');11var country = adb.setDeviceCountry("US");12console.log(country);13var adb = require('appium-adb');14var time = adb.getDeviceTime();15console.log(time);16var adb = require('appium-adb');17var time = adb.setDeviceTime("2016-12-11T12:00:00");18console.log(time);19var adb = require('appium-adb');20var language = adb.getDeviceSysLanguage();21console.log(language);22var adb = require('appium-adb');23var country = adb.getDeviceSysCountry();24console.log(country);25var adb = require('appium-adb');26var locale = adb.getDeviceSysLocale();27console.log(locale);28var adb = require('appium-adb');29var platformVersion = adb.getDevicePlatformVersion();30console.log(platformVersion);31var adb = require('appium-adb');32var model = adb.getDeviceModel();33console.log(model);
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6chai.should();7var desiredCaps = {8};9var driver = wd.promiseChainRemote("
Using AI Code Generation
1var wd = require('wd'),2 _ = require('underscore'),3 Q = require('q'),4 assert = require('assert');5var desired = {6};7var driver = wd.promiseChainRemote("localhost", 4723);8 .init(desired)9 .getDeviceLanguage()10 .then(function(language) {11 console.log('Device Language: ' + language);12 })13 .fin(function() { return driver.quit(); })14 .done();15var wd = require('wd'),16 _ = require('underscore'),17 Q = require('q'),18 assert = require('assert');19var desired = {20};21var driver = wd.promiseChainRemote("localhost", 4723);22 .init(desired)23 .execute('mobile: getDeviceLanguage', [])24 .then(function(language) {25 console.log('Device Language: ' + language);26 })27 .fin(function() { return driver.quit(); })28 .done();29info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').build();3var adb = require('appium-android-driver').AndroidDriver.adb;4driver.getTitle().then(function(title) {5 console.log(title);6});7adb.getDeviceLanguage().then(function(language) {8 console.log(language);9});10driver.quit();11var webdriver = require('selenium-webdriver');12var driver = new webdriver.Builder().forBrowser('chrome').build();13var adb = require('appium-android-driver').AndroidDriver.adb;14driver.getTitle().then(function(title) {15 console.log(title);16});17adb.getDeviceCountry().then(function(country) {18 console.log(country);19});20driver.quit();21var webdriver = require('selenium-webdriver');22var driver = new webdriver.Builder().forBrowser('chrome').build();23var adb = require('appium-android-driver').AndroidDriver.adb;24driver.getTitle().then(function(title) {25 console.log(title);26});27adb.getDeviceTime().then(function(time) {28 console.log(time);29});30driver.quit();31var webdriver = require('selenium-webdriver');32var driver = new webdriver.Builder().forBrowser('chrome').build();33var adb = require('appium-android-driver').AndroidDriver.adb;34driver.getTitle().then(function(title) {35 console.log(title);36});37adb.getDeviceTimeZone().then(function(timeZone) {38 console.log(timeZone);39});40driver.quit();41var webdriver = require('selenium-webdriver');42var driver = new webdriver.Builder().forBrowser('chrome').build();43var adb = require('appium-android-driver').AndroidDriver.adb;44driver.getTitle().then(function(title) {45 console.log(title);46});47adb.getDeviceDensity().then(function(density) {
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .getDeviceLanguage()9 .then(function (language) {10 console.log(language);11 })12 .end();13var webdriverio = require('webdriverio');14var options = {15 desiredCapabilities: {16 }17};18 .remote(options)19 .init()20 .getDeviceTime()21 .then(function (time) {22 console.log(time);23 })24 .end();25var webdriverio = require('webdriverio');26var options = {27 desiredCapabilities: {28 }29};30 .remote(options)31 .init()32 .getNetworkConnection()33 .then(function (networkConnection) {34 console.log(networkConnection);35 })36 .end();37var webdriverio = require('webdriverio');38var options = {39 desiredCapabilities: {40 }41};42 .remote(options)43 .init()44 .getPerformanceData('com.example.android.apis', 'cpuinfo', 3)45 .then(function (performanceData) {46 console.log(performanceData);47 })48 .end();
Using AI Code Generation
1const adb = require('appium-adb');2const androidDriver = require('appium-android-driver');3const driver = new androidDriver.AndroidDriver();4const adbDriver = new adb.ADB();5const deviceLanguage = adbDriver.getDeviceLanguage();6console.log(deviceLanguage);7const adb = require('appium-adb');8const androidDriver = require('appium-android-driver');9const driver = new androidDriver.AndroidDriver();10const adbDriver = new adb.ADB();11const deviceLanguage = adbDriver.getDeviceLanguage();12console.log(deviceLanguage);13const adb = require('appium-adb');14const androidDriver = require('appium-android-driver');15const driver = new androidDriver.AndroidDriver();16const adbDriver = new adb.ADB();17const deviceLanguage = adbDriver.getDeviceLanguage();18console.log(deviceLanguage);19const adb = require('appium-adb');20const androidDriver = require('appium-android-driver');21const driver = new androidDriver.AndroidDriver();22const adbDriver = new adb.ADB();23const deviceLanguage = adbDriver.getDeviceLanguage();24console.log(deviceLanguage);25const adb = require('appium-adb');26const androidDriver = require('appium-android-driver');27const driver = new androidDriver.AndroidDriver();28const adbDriver = new adb.ADB();29const deviceLanguage = adbDriver.getDeviceLanguage();30console.log(deviceLanguage);31const adb = require('appium-adb');32const androidDriver = require('appium-android-driver');33const driver = new androidDriver.AndroidDriver();34const adbDriver = new adb.ADB();35const deviceLanguage = adbDriver.getDeviceLanguage();36console.log(deviceLanguage);37const adb = require('appium-adb');38const androidDriver = require('appium-android-driver');39const driver = new androidDriver.AndroidDriver();40const adbDriver = new adb.ADB();41const deviceLanguage = adbDriver.getDeviceLanguage();42console.log(deviceLanguage);43const adb = require('appium-adb');
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desired = require('./desired');4var _ = require('underscore');5var browser = wd.promiseChainRemote('localhost', 4723);6browser.on('status', function(info) {7 console.log(info.cyan);8});9browser.on('command', function(meth, path, data) {10 console.log(' > ' + meth.yellow, path.grey, data || '');11});12 .init(desired)13 .then(function() {14 return browser.getDeviceLanguage();15 })16 .then(function(language) {17 console.log('Language is: ' + language);18 return browser.setDeviceLanguage('en');19 })20 .then(function() {21 return browser.getDeviceLanguage();22 })23 .then(function(language) {24 console.log('Language is: ' + language);25 return browser.setDeviceLanguage('fr');26 })27 .then(function() {28 return browser.getDeviceLanguage();29 })30 .then(function(language) {31 console.log('Language is: ' + language);32 })33 .fin(function() { return browser.quit(); })34 .done();35module.exports = {36};37{38 "dependencies": {39 },40 "scripts": {41 }42}
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!!