Best JavaScript code snippet using appium-android-driver
basic-specs.js
Source:basic-specs.js
...251 let specialCaps = Object.assign({enablePerformanceLogging: true}, desired);252 const driver = setup(this, specialCaps).driver;253 before(async function () { return await loadWebView(specialCaps, driver); });254 it('should be able to get the performance logs', async function () {255 let logTypes = await driver.getLogTypes();256 logTypes.should.include('performance');257 let logs = await driver.getLog('performance');258 logs.should.be.an.instanceof(Array);259 logs.length.should.be.above(0);260 });261 });...
js-wd.js
Source:js-wd.js
...205 codeFor_setGeoLocation (varNameIgnore, varIndexIgnore, latitude, longitude, altitude) {206 return `await driver.setGeoLocation(${latitude}, ${longitude}, ${altitude});`;207 }208 codeFor_getLogTypes () {209 return `let getLogTypes = await driver.getLogTypes();`;210 }211 codeFor_getLogs (varNameIgnore, varIndexIgnore, logType) {212 return `let logs = await driver.log('${logType}');`;213 }214 codeFor_updateSettings (varNameIgnore, varIndexIgnore, settingsJson) {215 return `await driver.updateSettings(${settingsJson});`;216 }217 codeFor_getSettings () {218 return `let settings = await driver.settings();`;219 }220 // Web221 codeFor_navigateTo (url) {222 return `driver.get('${url}');`;223 }...
js-oxygen.js
Source:js-oxygen.js
1import Framework from './framework';2class JsOxygenFramework extends Framework {3 get language () {4 return 'js';5 }6 wrapWithBoilerplate (code) {7 let caps = JSON.stringify(this.caps);8 let url = JSON.stringify(`${this.scheme}://${this.host}:${this.port}${this.path}`);9 return `// Requires the Oxygen HQ client library10// (npm install oxygen-cli -g)11// Then paste this into a .js file and run with:12// oxygen <file>.js13mob.init(${caps}, ${url});14${code}15`;16 }17 codeFor_findAndAssign (strategy, locator, localVar, isArray) {18 // wdio has its own way of indicating the strategy in the locator string19 switch (strategy) {20 case 'xpath': break; // xpath does not need to be updated21 case 'accessibility id': locator = `~${locator}`; break;22 case 'id': locator = `id=${locator}`; break;23 case 'name': locator = `name=${locator}`; break;24 case 'class name': locator = `css=${locator}`; break;25 case '-android uiautomator': locator = `android=${locator}`; break;26 case '-android datamatcher': locator = `android=${locator}`; break;27 case '-ios predicate string': locator = `ios=${locator}`; break;28 case '-ios class chain': locator = `ios=${locator}`; break; // TODO: Handle IOS class chain properly. Not all libs support it. Or take it out29 default: throw new Error(`Can't handle strategy ${strategy}`);30 }31 if (isArray) {32 return `let ${localVar} = mob.findElements(${JSON.stringify(locator)});`;33 } else {34 return `let ${localVar} = mob.findElement(${JSON.stringify(locator)});`;35 }36 }37 codeFor_click (varName, varIndex) {38 return `mob.click(${this.getVarName(varName, varIndex)});`;39 }40 codeFor_clear (varName, varIndex) {41 return `mob.clear(${this.getVarName(varName, varIndex)});`;42 }43 codeFor_sendKeys (varName, varIndex, text) {44 return `mob.type(${this.getVarName(varName, varIndex)}, ${JSON.stringify(text)});`;45 }46 codeFor_back () {47 return `mob.back();`;48 }49 codeFor_tap (varNameIgnore, varIndexIgnore, x, y) {50 return `mob.tap(${x}, ${y});`;51 }52 codeFor_swipe (varNameIgnore, varIndexIgnore, x1, y1, x2, y2) {53 return `mob.swipeScreen(${x1}, ${y1}, ${x2}, ${y2});`;54 }55 codeFor_getCurrentActivity () {56 return `let activityName = mob.getCurrentActivity();`;57 }58 codeFor_getCurrentPackage () {59 return `let packageName = mob.getCurrentPackage();`;60 }61 codeFor_installAppOnDevice (varNameIgnore, varIndexIgnore, app) {62 return `mob.installApp('${app}');`;63 }64 codeFor_isAppInstalledOnDevice (varNameIgnore, varIndexIgnore, app) {65 return `let isAppInstalled = mob.isAppInstalled("${app}");`;66 }67 codeFor_launchApp () {68 return `mob.launchApp();`;69 }70 codeFor_backgroundApp (varNameIgnore, varIndexIgnore, timeout) {71 return `mob.driver().background(${timeout});`;72 }73 codeFor_closeApp () {74 return `mob.closeApp();`;75 }76 codeFor_resetApp () {77 return `mob.resetApp();`;78 }79 codeFor_removeAppFromDevice (varNameIgnore, varIndexIgnore, app) {80 return `mob.removeApp('${app}')`;81 }82 codeFor_getAppStrings (varNameIgnore, varIndexIgnore, language, stringFile) {83 return `let appStrings = mob.driver().getAppStrings(${language ? `${language}, ` : ''}${stringFile ? `"${stringFile}` : ''});`;84 }85 codeFor_getClipboard () {86 return `let clipboardText = mob.driver().getClipboard();`;87 }88 codeFor_setClipboard (varNameIgnore, varIndexIgnore, clipboardText) {89 return `mob.driver().setClipboard('${clipboardText}')`;90 }91 codeFor_pressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {92 return `mob.driver().longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;93 }94 codeFor_longPressKeycode (varNameIgnore, varIndexIgnore, keyCode, metaState, flags) {95 return `mob.driver().longPressKeyCode(${keyCode}, ${metaState}, ${flags});`;96 }97 codeFor_hideDeviceKeyboard () {98 return `mob.driver().hideKeyboard();`;99 }100 codeFor_isKeyboardShown () {101 return `//isKeyboardShown not supported`;102 }103 codeFor_pushFileToDevice (varNameIgnore, varIndexIgnore, pathToInstallTo, fileContentString) {104 return `mob.driver().pushFile('${pathToInstallTo}', '${fileContentString}');`;105 }106 codeFor_pullFile (varNameIgnore, varIndexIgnore, pathToPullFrom) {107 return `let data = mob.driver().pullFile('${pathToPullFrom}');`;108 }109 codeFor_pullFolder (varNameIgnore, varIndexIgnore, folderToPullFrom) {110 return `let data = mob.driver().pullFolder('${folderToPullFrom}');`;111 }112 codeFor_toggleAirplaneMode () {113 return `mob.driver().toggleAirplaneMode();`;114 }115 codeFor_toggleData () {116 return `mob.driver().toggleData();`;117 }118 codeFor_toggleWiFi () {119 return `mob.driver().toggleWiFi();`;120 }121 codeFor_toggleLocationServices () {122 return `mob.driver().toggleLocationServices();`;123 }124 codeFor_sendSMS () {125 return `// Not supported: sendSms;`;126 }127 codeFor_gsmCall () {128 return `// Not supported: gsmCall`;129 }130 codeFor_gsmSignal () {131 return `// Not supported: gsmSignal`;132 }133 codeFor_gsmVoice () {134 return `// Not supported: gsmVoice`;135 }136 codeFor_shake () {137 return `mob.shake();`;138 }139 codeFor_lock (varNameIgnore, varIndexIgnore, seconds) {140 return `mob.driver().lock(${seconds});`;141 }142 codeFor_unlock () {143 return `mob.driver().unlock();`;144 }145 codeFor_isLocked () {146 return `let isLocked = mob.driver().isLocked();`;147 }148 codeFor_rotateDevice (varNameIgnore, varIndexIgnore, x, y, radius, rotation, touchCount, duration) {149 return `mob.driver().rotateDevice(${x}, ${y}, ${radius}, ${rotation}, ${touchCount}, ${duration});`;150 }151 codeFor_getPerformanceData () {152 return `// Not supported: getPerformanceData`;153 }154 codeFor_getSupportedPerformanceDataTypes () {155 return `// Not supported: getSupportedPerformanceDataTypes`;156 }157 codeFor_performTouchId (varNameIgnore, varIndexIgnore, match) {158 return `mob.driver().touchId(${match});`;159 }160 codeFor_toggleTouchIdEnrollment (varNameIgnore, varIndexIgnore, enroll) {161 return `mob.driver().toggleEnrollTouchId(${enroll});`;162 }163 codeFor_openNotifications () {164 return `mob.driver().openNotifications();`;165 }166 codeFor_getDeviceTime () {167 return `let time = mob.getDeviceTime();`;168 }169 codeFor_fingerprint (varNameIgnore, varIndexIgnore, fingerprintId) {170 return `mob.driver().fingerPrint(${fingerprintId});`;171 }172 codeFor_sessionCapabilities () {173 return `let caps = mob.driver().capabilities;`;174 }175 codeFor_setPageLoadTimeout (varNameIgnore, varIndexIgnore, ms) {176 return `mob.driver().setTimeout({'pageLoad': ${ms}});`;177 }178 codeFor_setAsyncScriptTimeout (varNameIgnore, varIndexIgnore, ms) {179 return `mob.driver().setTimeout({'script': ${ms}});`;180 }181 codeFor_setImplicitWaitTimeout (varNameIgnore, varIndexIgnore, ms) {182 return `mob.driver().setTimeout({'implicit': ${ms}});`;183 }184 codeFor_setCommandTimeout () {185 return `// Not supported: setCommandTimeout`;186 }187 codeFor_getOrientation () {188 return `let orientation = mob.driver().getOrientation();`;189 }190 codeFor_setOrientation (varNameIgnore, varIndexIgnore, orientation) {191 return `mob.driver().setOrientation("${orientation}");`;192 }193 codeFor_getGeoLocation () {194 return `let location = mob.driver().getGeoLocation();`;195 }196 codeFor_setGeoLocation (varNameIgnore, varIndexIgnore, latitude, longitude, altitude) {197 return `mob.driver().setGeoLocation({latitude: ${latitude}, longitude: ${longitude}, altitude: ${altitude}});`;198 }199 codeFor_logTypes () {200 return `let logTypes = mob.driver().getLogTypes();`;201 }202 codeFor_log (varNameIgnore, varIndexIgnore, logType) {203 return `let logs = mob.driver().getLogs('${logType}');`;204 }205 codeFor_updateSettings (varNameIgnore, varIndexIgnore, settingsJson) {206 return `mob.driver().updateSettings(${settingsJson});`;207 }208 codeFor_settings () {209 return `let settings = mob.driver().getSettings();`;210 }211}212JsOxygenFramework.readableName = 'JS - Oxygen HQ';...
wd-connector.js
Source:wd-connector.js
...146 const isLogLevelLowerThanRequired = pipe(147 propOr(Infinity, 'level'),148 gt(level)149 );150 return () => this._driver.getLogTypes().then(151 (types = []) =>152 (containsBrowser(types) ?153 this._driver.getLogs('browser') :154 Promise.resolve([])155 ),156 () => [] // supress error157 )158 .then((logs = []) => {159 this._browserLogs.push(...logs);160 const notGot = this._browserLogs.slice(this._browserLogsGot);161 this._browserLogsGot = this._browserLogs.length;162 return notGot;163 })164 .then(...
calc-app-2-specs.js
Source:calc-app-2-specs.js
...30 .catch(throwMatchableError)31 .should.be.rejectedWith(/jsonwpCode: 9/);32 });33 it('should be able to get syslog log type', async function () {34 let logTypes = await driver.getLogTypes();35 logTypes.should.include('syslog');36 logTypes.should.include('crashlog');37 logTypes.should.not.include('logcat');38 });39 // TODO: Fails on sauce, investigate40 // TODO: Fails with 8.4 or Appium 1.5, investigate cause41 it.skip('should be able to get syslog logs @skip-ios8 @skip-ci', async function () {42 await driver.implicitWait(4000);43 await B.resolve(driver.findElement('accessibility id', 'SumLabelz'))44 .catch(throwMatchableError)45 .should.be.rejectedWith(/jsonwpCode: 7/);46 let logs = await driver.getLog();47 logs.length.should.be.above(0);48 logs[0].message.should.not.include('\n');...
log-specs.js
Source:log-specs.js
...17 it('should respond to the command', function () {18 driver.getLogTypes.should.an.instanceof(Function);19 });20 it('should get log types', async function () {21 const types = await driver.getLogTypes();22 // all the types should be returned23 _.xor(['logcat', 'bugreport', 'server'], types).should.eql([]);24 });25 });26 describe('getLog', function () {27 it('should respond to the command', function () {28 driver.getLog.should.be.an.instanceof(Function);29 });30 it('should get logcat logs', async function () {31 sinon.stub(driver.adb, 'getLogcatLogs').returns(['logs']);32 (await driver.getLog('logcat')).should.be.deep.equal(['logs']);33 driver.adb.getLogcatLogs.called.should.be.true;34 driver.adb.getLogcatLogs.restore();35 });...
Edition053_ADB_Logcat.js
Source:Edition053_ADB_Logcat.js
...20 await driver.deleteSession()21})22test('capture logcat', async t => {23 // inspect available log types24 let logtypes = await driver.getLogTypes()25 console.log('supported log types: ', logtypes) // [ 'logcat', 'bugreport', 'server' ]26 // print first and last 10 lines of logs27 let logs = await driver.getLogs('logcat')28 console.log('First and last ten lines of logs:')29 console.log(logs.slice(0, 10).map(entry => entry.message).join('\n'))30 console.log('...')31 console.log(logs.slice(-10).map(entry => entry.message).join('\n'))32 // wait for more logs33 await B.delay(5000)34 // demonstrate that each time get logs, we only get new logs35 // which were generated since the last time we got logs36 let secondCallToLogs = await driver.getLogs('logcat')37 console.log('First ten lines of next log call: ')38 console.log(secondCallToLogs.slice(0, 10).map(entry => entry.message).join('\n'))...
logging-specs.js
Source:logging-specs.js
...11 it('should respond to the command', function () {12 driver.getLogTypes.should.an.instanceof(Function);13 });14 it('should get the list of available logs', async function () {15 const types = await driver.getLogTypes();16 _.xor(['syslog', 'crashlog', 'performance', 'server'], types).should.eql([]);17 });18 });19 describe('getLog', function () {20 it('should respond to the command', function () {21 driver.getLog.should.be.an.instanceof(Function);22 });23 // unit tests of getLog are in `appium-base-driver`24 });...
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desired = {4};5var browser = wd.promiseChainRemote("localhost", 4723);6 .init(desired)7 .then(function () {8 return browser.getLogTypes();9 })10 .then(function (logTypes) {11 console.log('logTypes: ' + logTypes);12 })13 .fin(function () { return browser.quit(); })14 .done();15var wd = require('wd');16var assert = require('assert');17var desired = {18};19var browser = wd.promiseChainRemote("localhost", 4723);20 .init(desired)21 .then(function () {22 return browser.getLog('logcat');23 })24 .then(function (logs) {25 console.log('logs: ' + logs);26 })27 .fin(function () { return browser.quit(); })28 .done();29var wd = require('wd');30var assert = require('assert');31var desired = {
Using AI Code Generation
1const { Builder } = require('selenium-webdriver');2const { AndroidDriver } = require('appium-android-driver');3async function test() {4 let driver = await new Builder()5 .forBrowser('chrome')6 .build();7 let androidDriver = new AndroidDriver();8 androidDriver.attach(driver);9 let logTypes = await androidDriver.getLogTypes();10 console.log(logTypes);11 driver.quit();12}13test();14const { Builder } = require('selenium-webdriver');15const { AndroidDriver } = require('appium-android-driver');16async function test() {17 let driver = await new Builder()18 .forBrowser('chrome')19 .build();20 let androidDriver = new AndroidDriver();21 androidDriver.attach(driver);22 let logTypes = await androidDriver.getLogTypes();23 let log = await androidDriver.getLog(logTypes[0]);24 console.log(log);25 driver.quit();26}27test();28const { Builder } = require('selenium-webdriver');29const { AndroidDriver } = require('appium-android-driver');30async function test() {31 let driver = await new Builder()32 .forBrowser('chrome')33 .build();34 let androidDriver = new AndroidDriver();35 androidDriver.attach(driver);36 let supportedPerformanceDataTypes = await androidDriver.getSupportedPerformanceDataTypes();37 console.log(supportedPerformanceDataTypes);38 driver.quit();39}40test();41const { Builder } = require('selenium-webdriver');42const { AndroidDriver } = require('appium-android-driver');43async function test() {44 let driver = await new Builder()45 .forBrowser('chrome')46 .build();47 let androidDriver = new AndroidDriver();48 androidDriver.attach(driver);49 let supportedPerformanceDataTypes = await androidDriver.getSupportedPerformanceDataTypes();50 let performanceData = await androidDriver.getPerformanceData(51 );52 console.log(performanceData);53 driver.quit();54}55test();56const {
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.getLogTypes().then(function(types) {7 console.log('Available log types:');8 types.forEach(function(type) {9 console.log(' ' + type);10 });11});12driver.quit();13var webdriver = require('selenium-webdriver');14var driver = new webdriver.Builder()15 .withCapabilities({16 })17 .build();18driver.getLog('logcat', webdriver.logging.Level.ALL).then(function(logs) {19 console.log('Logs:');20 logs.forEach(function(log) {21 console.log('[' + log.level.name + '] ' + log.message);22 });23});24driver.quit();
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!!