Best JavaScript code snippet using appium-android-driver
actions-specs.js
Source:actions-specs.js
1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import sinon from 'sinon';4import Bootstrap from '../../../lib/bootstrap';5import path from 'path';6import AndroidDriver from '../../..';7import * as support from 'appium-support';8import ADB from 'appium-adb';9import jimp from 'jimp';10import helpers from '../../../lib/commands/actions';11import * as teen_process from 'teen_process';12let driver;13let sandbox = sinon.createSandbox();14chai.should();15chai.use(chaiAsPromised);16describe('Actions', function () {17 beforeEach(function () {18 driver = new AndroidDriver();19 driver.adb = new ADB();20 driver.bootstrap = new Bootstrap();21 sandbox.stub(driver.bootstrap, 'sendAction');22 });23 afterEach(function () {24 sandbox.restore();25 });26 describe('keyevent', function () {27 it('shoudle be able to execute keyevent via pressKeyCode', async function () {28 sandbox.stub(driver, 'pressKeyCode');29 await driver.keyevent('66', 'meta');30 driver.pressKeyCode.calledWithExactly('66', 'meta').should.be.true;31 });32 it('should set metastate to null by default', async function () {33 sandbox.stub(driver, 'pressKeyCode');34 await driver.keyevent('66');35 driver.pressKeyCode.calledWithExactly('66', null).should.be.true;36 });37 });38 describe('pressKeyCode', function () {39 it('shoudle be able to press key code', async function () {40 await driver.pressKeyCode('66', 'meta');41 driver.bootstrap.sendAction42 .calledWithExactly('pressKeyCode', {keycode: '66', metastate: 'meta'})43 .should.be.true;44 });45 it('should set metastate to null by default', async function () {46 await driver.pressKeyCode('66');47 driver.bootstrap.sendAction48 .calledWithExactly('pressKeyCode', {keycode: '66', metastate: null})49 .should.be.true;50 });51 });52 describe('longPressKeyCode', function () {53 it('shoudle be able to press key code', async function () {54 await driver.longPressKeyCode('66', 'meta');55 driver.bootstrap.sendAction56 .calledWithExactly('longPressKeyCode', {keycode: '66', metastate: 'meta'})57 .should.be.true;58 });59 it('should set metastate to null by default', async function () {60 await driver.longPressKeyCode('66');61 driver.bootstrap.sendAction62 .calledWithExactly('longPressKeyCode', {keycode: '66', metastate: null})63 .should.be.true;64 });65 });66 describe('getOrientation', function () {67 it('shoudle be able to get orientation', async function () {68 driver.bootstrap.sendAction.withArgs('orientation', {naturalOrientation: false})69 .returns('landscape');70 await driver.getOrientation().should.become('LANDSCAPE');71 driver.bootstrap.sendAction72 .calledWithExactly('orientation', {naturalOrientation: false})73 .should.be.true;74 });75 });76 describe('setOrientation', function () {77 it('shoudle be able to set orientation', async function () {78 let opts = {orientation: 'SOMESCAPE', naturalOrientation: false};79 await driver.setOrientation('somescape');80 driver.bootstrap.sendAction.calledWithExactly('orientation', opts)81 .should.be.true;82 });83 });84 describe('fakeFlick', function () {85 it('shoudle be able to do fake flick', async function () {86 await driver.fakeFlick(12, 34);87 driver.bootstrap.sendAction88 .calledWithExactly('flick', {xSpeed: 12, ySpeed: 34}).should.be.true;89 });90 });91 describe('fakeFlickElement', function () {92 it('shoudle be able to do fake flick on element', async function () {93 await driver.fakeFlickElement(5000, 56, 78, 1.32);94 driver.bootstrap.sendAction95 .calledWithExactly('element:flick',96 {xoffset: 56, yoffset: 78, speed: 1.32, elementId: 5000})97 .should.be.true;98 });99 });100 describe('swipe', function () {101 it('should swipe an element', function () {102 let swipeOpts = {startX: 10, startY: 11, endX: 20, endY: 22,103 steps: 3, elementId: 'someElementId'};104 driver.swipe(10, 11, 20, 22, 0.1, null, 'someElementId');105 driver.bootstrap.sendAction.calledWithExactly('element:swipe', swipeOpts)106 .should.be.true;107 });108 it('should swipe without an element', function () {109 driver.swipe(0, 0, 1, 1, 0, 1);110 driver.bootstrap.sendAction.calledWith('swipe').should.be.true;111 });112 it('should set start point to (0.5;0.5) if startX and startY are "null"', function () {113 let swipeOpts = {startX: 0.5, startY: 0.5, endX: 0, endY: 0, steps: 0};114 sandbox.stub(driver, 'doSwipe');115 driver.swipe('null', 'null', 0, 0, 0);116 driver.doSwipe.calledWithExactly(swipeOpts).should.be.true;117 });118 });119 describe('pinchClose', function () {120 it('should be able to pinch in element', async function () {121 let pinchOpts = {direction: 'in', elementId: 'el01', percent: 0.5, steps: 5};122 await driver.pinchClose(null, null, null, null, null, 0.5, 5, 'el01');123 driver.bootstrap.sendAction.calledWithExactly('element:pinch', pinchOpts)124 .should.be.true;125 });126 });127 describe('pinchOpen', function () {128 it('should be able to pinch out element', async function () {129 let pinchOpts = {direction: 'out', elementId: 'el01', percent: 0.5, steps: 5};130 await driver.pinchOpen(null, null, null, null, null, 0.5, 5, 'el01');131 driver.bootstrap.sendAction.calledWithExactly('element:pinch', pinchOpts)132 .should.be.true;133 });134 });135 describe('flick', function () {136 it('should call fakeFlickElement if element is passed', async function () {137 sandbox.stub(driver, 'fakeFlickElement');138 await driver.flick('elem', null, null, 1, 2, 3);139 driver.fakeFlickElement.calledWith('elem', 1, 2, 3).should.be.true;140 });141 it('should call fakeFlick if element is not passed', async function () {142 sandbox.stub(driver, 'fakeFlick');143 await driver.flick(null, 1, 2);144 driver.fakeFlick.calledWith(1, 2).should.be.true;145 });146 });147 describe('drag', function () {148 let dragOpts = {149 elementId: 'elem1', destElId: 'elem2',150 startX: 1, startY: 2, endX: 3, endY: 4, steps: 1151 };152 it('should drag an element', function () {153 driver.drag(1, 2, 3, 4, 0.02, null, 'elem1', 'elem2');154 driver.bootstrap.sendAction.calledWithExactly('element:drag', dragOpts)155 .should.be.true;156 });157 it('should drag without an element', function () {158 dragOpts.elementId = null;159 driver.drag(1, 2, 3, 4, 0.02, null, null, 'elem2');160 driver.bootstrap.sendAction.calledWithExactly('drag', dragOpts)161 .should.be.true;162 });163 });164 describe('lock', function () {165 it('should call adb.lock()', async function () {166 sandbox.stub(driver.adb, 'lock');167 await driver.lock();168 driver.adb.lock.calledOnce.should.be.true;169 });170 });171 describe('isLocked', function () {172 it('should call adb.isScreenLocked()', async function () {173 sandbox.stub(driver.adb, 'isScreenLocked').returns('lock_status');174 await driver.isLocked().should.become('lock_status');175 driver.adb.isScreenLocked.calledOnce.should.be.true;176 });177 });178 describe('openNotifications', function () {179 it('should be able to open notifications', async function () {180 await driver.openNotifications();181 driver.bootstrap.sendAction.calledWithExactly('openNotification')182 .should.be.true;183 });184 });185 describe('setLocation', function () {186 it('should be able to set location', async function () {187 sandbox.stub(driver.adb, 'sendTelnetCommand');188 await driver.setLocation('lat', 'long');189 driver.adb.sendTelnetCommand.calledWithExactly('geo fix long lat')190 .should.be.true;191 });192 });193 describe('fingerprint', function () {194 it('should call fingerprint adb command for emulator', async function () {195 sandbox.stub(driver.adb, 'fingerprint');196 sandbox.stub(driver, 'isEmulator').returns(true);197 await driver.fingerprint(1111);198 driver.adb.fingerprint.calledWithExactly(1111).should.be.true;199 });200 it('should throw exception for real device', async function () {201 sandbox.stub(driver.adb, 'fingerprint');202 sandbox.stub(driver, 'isEmulator').returns(false);203 await driver.fingerprint(1111).should.be204 .rejectedWith('fingerprint method is only available for emulators');205 driver.adb.fingerprint.notCalled.should.be.true;206 });207 });208 describe('sendSMS', function () {209 it('should call sendSMS adb command for emulator', async function () {210 sandbox.stub(driver.adb, 'sendSMS');211 sandbox.stub(driver, 'isEmulator').returns(true);212 await driver.sendSMS(4509, 'Hello Appium');213 driver.adb.sendSMS.calledWithExactly(4509, 'Hello Appium')214 .should.be.true;215 });216 it('should throw exception for real device', async function () {217 sandbox.stub(driver.adb, 'sendSMS');218 sandbox.stub(driver, 'isEmulator').returns(false);219 await driver.sendSMS(4509, 'Hello Appium')220 .should.be.rejectedWith('sendSMS method is only available for emulators');221 driver.adb.sendSMS.notCalled.should.be.true;222 });223 });224 describe('sensorSet', function () {225 it('should call sensor adb command for emulator', async function () {226 sandbox.stub(driver.adb, 'sensorSet');227 sandbox.stub(driver, 'isEmulator').returns(true);228 await driver.sensorSet({sensorType: 'light', value: 0});229 driver.adb.sensorSet.calledWithExactly('light', 0)230 .should.be.true;231 });232 it('should throw exception for real device', async function () {233 sandbox.stub(driver.adb, 'sensorSet');234 sandbox.stub(driver, 'isEmulator').returns(false);235 await driver.sensorSet({sensorType: 'light', value: 0})236 .should.be.rejectedWith('sensorSet method is only available for emulators');237 driver.adb.sensorSet.notCalled.should.be.true;238 });239 });240 describe('gsmCall', function () {241 it('should call gsmCall adb command for emulator', async function () {242 sandbox.stub(driver.adb, 'gsmCall');243 sandbox.stub(driver, 'isEmulator').returns(true);244 await driver.gsmCall(4509, 'call');245 driver.adb.gsmCall.calledWithExactly(4509, 'call').should.be.true;246 });247 it('should throw exception for real device', async function () {248 sandbox.stub(driver.adb, 'gsmCall');249 sandbox.stub(driver, 'isEmulator').returns(false);250 await driver.gsmCall(4509, 'call')251 .should.be.rejectedWith('gsmCall method is only available for emulators');252 driver.adb.gsmCall.notCalled.should.be.true;253 });254 });255 describe('gsmSignal', function () {256 it('should call gsmSignal adb command for emulator', async function () {257 sandbox.stub(driver.adb, 'gsmSignal');258 sandbox.stub(driver, 'isEmulator').returns(true);259 await driver.gsmSignal(3);260 driver.adb.gsmSignal.calledWithExactly(3)261 .should.be.true;262 });263 it('should throw exception for real device', async function () {264 sandbox.stub(driver.adb, 'gsmSignal');265 sandbox.stub(driver, 'isEmulator').returns(false);266 await driver.gsmSignal(3)267 .should.be.rejectedWith('gsmSignal method is only available for emulators');268 driver.adb.gsmSignal.notCalled.should.be.true;269 });270 });271 describe('gsmVoice', function () {272 it('should call gsmVoice adb command for emulator', async function () {273 sandbox.stub(driver.adb, 'gsmVoice');274 sandbox.stub(driver, 'isEmulator').returns(true);275 await driver.gsmVoice('roaming');276 driver.adb.gsmVoice.calledWithExactly('roaming')277 .should.be.true;278 });279 it('should throw exception for real device', async function () {280 sandbox.stub(driver.adb, 'gsmVoice');281 sandbox.stub(driver, 'isEmulator').returns(false);282 await driver.gsmVoice('roaming')283 .should.be.rejectedWith('gsmVoice method is only available for emulators');284 driver.adb.gsmVoice.notCalled.should.be.true;285 });286 });287 describe('powerAC', function () {288 it('should call powerAC adb command for emulator', async function () {289 sandbox.stub(driver.adb, 'powerAC');290 sandbox.stub(driver, 'isEmulator').returns(true);291 await driver.powerAC('off');292 driver.adb.powerAC.calledWithExactly('off')293 .should.be.true;294 });295 it('should throw exception for real device', async function () {296 sandbox.stub(driver.adb, 'powerAC');297 sandbox.stub(driver, 'isEmulator').returns(false);298 await driver.powerAC('roaming')299 .should.be.rejectedWith('powerAC method is only available for emulators');300 driver.adb.powerAC.notCalled.should.be.true;301 });302 });303 describe('powerCapacity', function () {304 it('should call powerCapacity adb command for emulator', async function () {305 sandbox.stub(driver.adb, 'powerCapacity');306 sandbox.stub(driver, 'isEmulator').returns(true);307 await driver.powerCapacity(5);308 driver.adb.powerCapacity.calledWithExactly(5)309 .should.be.true;310 });311 it('should throw exception for real device', async function () {312 sandbox.stub(driver.adb, 'powerCapacity');313 sandbox.stub(driver, 'isEmulator').returns(false);314 await driver.powerCapacity(5)315 .should.be.rejectedWith('powerCapacity method is only available for emulators');316 driver.adb.powerCapacity.notCalled.should.be.true;317 });318 });319 describe('networkSpeed', function () {320 it('should call networkSpeed adb command for emulator', async function () {321 sandbox.stub(driver.adb, 'networkSpeed');322 sandbox.stub(driver, 'isEmulator').returns(true);323 await driver.networkSpeed('gsm');324 driver.adb.networkSpeed.calledWithExactly('gsm')325 .should.be.true;326 });327 it('should throw exception for real device', async function () {328 sandbox.stub(driver.adb, 'networkSpeed');329 sandbox.stub(driver, 'isEmulator').returns(false);330 await driver.networkSpeed('gsm')331 .should.be.rejectedWith('networkSpeed method is only available for emulators');332 driver.adb.networkSpeed.notCalled.should.be.true;333 });334 });335 describe('getScreenshotDataWithAdbShell', function () {336 const defaultDir = '/data/local/tmp/';337 const png = '/path/sc.png';338 const localFile = 'local_file';339 beforeEach(function () {340 sandbox.stub(support.tempDir, 'path');341 sandbox.stub(support.fs, 'exists');342 sandbox.stub(support.fs, 'unlink');343 sandbox.stub(driver.adb, 'shell');344 sandbox.stub(driver.adb, 'pull');345 sandbox.stub(path.posix, 'resolve');346 sandbox.stub(jimp, 'read');347 sandbox.stub(driver.adb, 'fileSize');348 support.tempDir.path.returns(localFile);349 support.fs.exists.withArgs(localFile).returns(true);350 support.fs.unlink.withArgs(localFile).returns(true);351 path.posix.resolve.withArgs(defaultDir, 'screenshot.png').returns(png);352 driver.adb.fileSize.withArgs(png).returns(1);353 jimp.read.withArgs(localFile).returns('screenshoot_context');354 });355 it('should be able to get screenshot via adb shell', async function () {356 await helpers.getScreenshotDataWithAdbShell(driver.adb, {})357 .should.become('screenshoot_context');358 driver.adb.shell.calledWithExactly(['/system/bin/rm', `${png};`359 , '/system/bin/screencap', '-p', png]).should.be.true;360 driver.adb.pull.calledWithExactly(png, localFile).should.be.true;361 jimp.read.calledWithExactly(localFile).should.be.true;362 support.fs.exists.calledTwice.should.be.true;363 support.fs.unlink.calledTwice.should.be.true;364 });365 it('should be possible to change default png dir', async function () {366 path.posix.resolve.withArgs('/custom/path/tmp/', 'screenshot.png').returns(png);367 await helpers.getScreenshotDataWithAdbShell(driver.adb368 , {androidScreenshotPath: '/custom/path/tmp/'})369 .should.become('screenshoot_context');370 });371 it('should throw error if size of the screenshot is zero', async function () {372 driver.adb.fileSize.withArgs(png).returns(0);373 await helpers.getScreenshotDataWithAdbShell(driver.adb, {})374 .should.be.rejectedWith('equals to zero');375 });376 });377 describe('getScreenshotDataWithAdbExecOut', function () {378 it('should be able to take screenshot via exec-out', async function () {379 sandbox.stub(teen_process, 'exec');380 sandbox.stub(jimp, 'read');381 teen_process.exec.returns({stdout: 'stdout', stderr: ''});382 driver.adb.executable.path = 'path/to/adb';383 await helpers.getScreenshotDataWithAdbExecOut(driver.adb);384 teen_process.exec.calledWithExactly(driver.adb.executable.path,385 driver.adb.executable.defaultArgs386 .concat(['exec-out', '/system/bin/screencap', '-p']),387 {encoding: 'binary', isBuffer: true}).should.be.true;388 jimp.read.calledWithExactly('stdout').should.be.true;389 });390 it('should throw error if size of the screenshot is zero', async function () {391 sandbox.stub(teen_process, 'exec');392 teen_process.exec.returns({stdout: '', stderr: ''});393 await helpers.getScreenshotDataWithAdbExecOut(driver.adb)394 .should.be.rejectedWith('Screenshot returned no data');395 });396 it('should throw error if code is not 0', async function () {397 sandbox.stub(teen_process, 'exec');398 teen_process.exec.returns({code: 1, stdout: '', stderr: ''});399 await helpers.getScreenshotDataWithAdbExecOut(driver.adb)400 .should.be.rejectedWith(`Screenshot returned error, code: '1', stderr: ''`);401 });402 it('should throw error if stderr is not empty', async function () {403 sandbox.stub(teen_process, 'exec');404 teen_process.exec.returns({code: 0, stdout: '', stderr: 'Oops'});405 await helpers.getScreenshotDataWithAdbExecOut(driver.adb)406 .should.be.rejectedWith(`Screenshot returned error, code: '0', stderr: 'Oops'`);407 });408 });409 describe('getScreenshot', function () {410 let image;411 beforeEach(function () {412 image = new jimp(1, 1);413 sandbox.stub(driver.adb, 'getApiLevel');414 sandbox.stub(driver.adb, 'getScreenOrientation');415 sandbox.stub(driver, 'getScreenshotDataWithAdbExecOut');416 sandbox.stub(driver, 'getScreenshotDataWithAdbShell');417 sandbox.stub(image, 'getBuffer').callsFake(function (mime, cb) { // eslint-disable-line promise/prefer-await-to-callbacks418 return cb.call(this, null, Buffer.from('appium'));419 });420 sandbox.stub(image, 'rotate');421 driver.adb.getScreenOrientation.returns(2);422 image.rotate.withArgs(-180).returns(image);423 });424 it('should be able to take screenshot via exec-out (API level > 20)', async function () {425 driver.adb.getApiLevel.returns(24);426 driver.getScreenshotDataWithAdbExecOut.withArgs(driver.adb).returns(image);427 await driver.getScreenshot().should.become('YXBwaXVt');428 driver.getScreenshotDataWithAdbExecOut.calledOnce.should.be.true;429 driver.getScreenshotDataWithAdbShell.notCalled.should.be.true;430 image.getBuffer.calledWith(jimp.MIME_PNG).should.be.true;431 });432 it('should be able to take screenshot via adb shell (API level <= 20)', async function () {433 driver.adb.getApiLevel.returns(20);434 driver.getScreenshotDataWithAdbShell.withArgs(driver.adb, driver.opts).returns(image);435 await driver.getScreenshot().should.become('YXBwaXVt');436 driver.getScreenshotDataWithAdbShell.calledOnce.should.be.true;437 driver.getScreenshotDataWithAdbExecOut.notCalled.should.be.true;438 image.getBuffer.calledWith(jimp.MIME_PNG).should.be.true;439 });440 it('should tries to take screenshot via adb shell if exec-out failed (API level > 20)', async function () {441 driver.adb.getApiLevel.returns(24);442 driver.getScreenshotDataWithAdbExecOut.throws();443 driver.getScreenshotDataWithAdbShell.withArgs(driver.adb, driver.opts).returns(image);444 await driver.getScreenshot().should.become('YXBwaXVt');445 driver.getScreenshotDataWithAdbShell.calledOnce.should.be.true;446 driver.getScreenshotDataWithAdbShell.calledOnce.should.be.true;447 });448 it('should throw error if adb shell failed', async function () {449 driver.adb.getApiLevel.returns(20);450 driver.getScreenshotDataWithAdbShell.throws();451 await driver.getScreenshot().should.be.rejectedWith('Cannot get screenshot');452 });453 it('should rotate image if API level < 23', async function () {454 driver.adb.getApiLevel.returns(22);455 driver.getScreenshotDataWithAdbExecOut.withArgs(driver.adb).returns(image);456 await driver.getScreenshot();457 driver.adb.getScreenOrientation.calledOnce.should.be.true;458 image.rotate.calledOnce.should.be.true;459 });460 it('should not rotate image if API level >= 23', async function () {461 driver.adb.getApiLevel.returns(23);462 driver.getScreenshotDataWithAdbExecOut.withArgs(driver.adb).returns(image);463 await driver.getScreenshot();464 driver.adb.getScreenOrientation.notCalled.should.be.true;465 image.rotate.notCalled.should.be.true;466 });467 it('should not throws error if rotate image failed', async function () {468 image.rotate.resetBehavior();469 image.rotate.throws();470 driver.adb.getApiLevel.returns(22);471 driver.getScreenshotDataWithAdbExecOut.withArgs(driver.adb).returns(image);472 await driver.getScreenshot().should.be.fulfilled;473 image.rotate.threw().should.be.true;474 });475 });...
by-uiautomator-e2e-specs.js
Source:by-uiautomator-e2e-specs.js
...65 await driver.getText(el.ELEMENT).should.eventually.equal('Accessibility');66 });67 it('should find an element with recursive UiSelectors', async function () {68 // TODO: figure out why this fails with 7.1.169 if (await driver.adb.getApiLevel() >= 24) return this.skip(); //eslint-disable-line curly70 await driver.findElements('-android uiautomator', 'new UiSelector().childSelector(new UiSelector().clickable(true)).clickable(true)')71 .should.eventually.have.length(1);72 });73 it('should not find an element with bad syntax', async function () {74 await driver.findElements('-android uiautomator', 'new UiSelector().clickable((true)')75 .should.eventually.be.rejectedWith(/unclosed paren in expression/);76 });77 it('should not find an element with bad syntax', async function () {78 await driver.findElements('-android uiautomator', 'new UiSelector().drinkable(true)')79 .should.eventually.be.rejectedWith(/UiSelector has no drinkable method/);80 });81 it('should not find an element which does not exist', async function () {82 await driver.findElements('-android uiautomator', 'new UiSelector().description("chuckwudi")')83 .should.eventually.have.length(0);...
driver-specs.js
Source:driver-specs.js
1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import sinon from 'sinon';4import { ADB } from 'appium-adb';5import { androidHelpers } from 'appium-android-driver';6import EspressoDriver from '../../lib/driver';7import EspressoRunner from '../../lib/espresso-runner';8chai.should();9chai.use(chaiAsPromised);10let sandbox = sinon.createSandbox();11describe('driver', function () {12 describe('startEspressoSession', function () {13 let driver;14 beforeEach(function () {15 driver = new EspressoDriver({}, false);16 driver.caps = { appPackage: 'io.appium.package', appActivity: '.MainActivity'};17 driver.opts = { autoLaunch: false, skipUnlock: true };18 sandbox.stub(driver, 'initEspressoServer');19 sandbox.stub(driver, 'addDeviceInfoToCaps');20 sandbox.stub(androidHelpers, 'getDeviceInfoFromCaps').callsFake(function () {21 return {udid: 1, emPort: 8888};22 });23 driver.espresso = new EspressoRunner({24 adb: ADB.createADB(), tmpDir: 'tmp', systemPort: 4724, host: 'localhost', devicePort: 6790, appPackage: driver.caps.appPackage, forceEspressoRebuild: false25 });26 sandbox.stub(driver.espresso, 'startSession');27 });28 afterEach(function () {29 sandbox.restore();30 });31 it('should call setHiddenApiPolicy', async function () {32 sandbox.stub(androidHelpers, 'createADB').callsFake(function () {33 let calledCount = 0;34 return {35 getDevicesWithRetry: () => [{udid: 'emulator-1234'}],36 getPortFromEmulatorString: () => 1234,37 setDeviceId: () => {},38 setEmulatorPort: () => {},39 networkSpeed: () => {},40 getApiLevel: () => 28,41 setHiddenApiPolicy: () => {42 calledCount += 1;43 return calledCount;44 },45 waitForDevice: () => {},46 processExists: () => true, // skip launching avd47 startLogcat: () => {},48 forwardPort: () => {},49 isAnimationOn: () => false,50 installOrUpgrade: () => {},51 };52 });53 await driver.startEspressoSession();54 driver.adb.setHiddenApiPolicy().should.eql(2);55 });56 it('should not call setHiddenApiPolicy', async function () {57 sandbox.stub(androidHelpers, 'createADB').callsFake(function () {58 let calledCount = 0;59 return {60 getDevicesWithRetry: () => [{udid: 'emulator-1234'}],61 getPortFromEmulatorString: () => 1234,62 setDeviceId: () => {},63 setEmulatorPort: () => {},64 networkSpeed: () => {},65 getApiLevel: () => 27,66 setHiddenApiPolicy: () => {67 calledCount += 1;68 return calledCount;69 },70 waitForDevice: () => {},71 processExists: () => true, // skip launching avd72 startLogcat: () => {},73 forwardPort: () => {},74 isAnimationOn: () => false,75 };76 });77 await driver.startEspressoSession();78 driver.adb.setHiddenApiPolicy().should.eql(1);79 });80 });81 describe('deleteSession', function () {82 let driver;83 beforeEach(function () {84 driver = new EspressoDriver({}, false);85 driver.adb = new ADB();86 driver.caps = {};87 sandbox.stub(driver.adb, 'stopLogcat');88 });89 afterEach(function () {90 sandbox.restore();91 });92 it('should call setDefaultHiddenApiPolicy', async function () {93 sandbox.stub(driver.adb, 'getApiLevel').returns(28);94 sandbox.stub(driver.adb, 'setDefaultHiddenApiPolicy');95 await driver.deleteSession();96 driver.adb.setDefaultHiddenApiPolicy.calledOnce.should.be.true;97 });98 it('should not call setDefaultHiddenApiPolicy', async function () {99 sandbox.stub(driver.adb, 'getApiLevel').returns(27);100 sandbox.stub(driver.adb, 'setDefaultHiddenApiPolicy');101 await driver.deleteSession();102 driver.adb.setDefaultHiddenApiPolicy.calledOnce.should.be.false;103 });104 });105 describe('#getProxyAvoidList', function () {106 let driver;107 describe('nativeWebScreenshot', function () {108 let proxyAvoidList;109 let nativeWebScreenshotFilter = (item) => item[0] === 'GET' && item[1].test('/session/xxx/screenshot/');110 beforeEach(function () {111 driver = new EspressoDriver({}, false);112 driver.caps = { appPackage: 'io.appium.package', appActivity: '.MainActivity'};113 driver.opts = { autoLaunch: false, skipUnlock: true };114 driver.chromedriver = true;115 sandbox.stub(driver, 'initEspressoServer');116 sandbox.stub(driver, 'initAUT');117 sandbox.stub(driver, 'startEspressoSession');118 });119 it('should proxy screenshot if nativeWebScreenshot is off on chromedriver mode', async function () {120 await driver.createSession({platformName: 'Android', deviceName: 'device', appPackage: driver.caps.appPackage, nativeWebScreenshot: false});121 proxyAvoidList = driver.getProxyAvoidList().filter(nativeWebScreenshotFilter);122 proxyAvoidList.should.be.empty;123 });124 it('should not proxy screenshot if nativeWebScreenshot is on on chromedriver mode', async function () {125 await driver.createSession({platformName: 'Android', deviceName: 'device', appPackage: driver.caps.appPackage, nativeWebScreenshot: true});126 proxyAvoidList = driver.getProxyAvoidList().filter(nativeWebScreenshotFilter);127 proxyAvoidList.should.not.be.empty;128 });129 });130 });...
performance-e2e-specs.js
Source:performance-e2e-specs.js
...28 await driver.getPerformanceData(caps.appPackage, 'randominfo', 2).should.be.rejected;29 });30 it('should get the amount of cpu by user and kernel process', async function () {31 // TODO: why does this fail?32 let apiLevel = await driver.adb.getApiLevel();33 if ([21, 24, 25].indexOf(apiLevel) >= 0) {34 return this.skip();35 }36 let cpu = await driver.getPerformanceData(caps.appPackage, 'cpuinfo', 50);37 Array.isArray(cpu).should.be.true;38 cpu.length.should.be.above(1);39 cpu[0].should.eql(CPU_KEYS);40 if (cpu.length > 1) {41 for (let i = 1; i < cpu.length; i++) {42 cpu[0].length.should.equal(cpu[i].length);43 }44 }45 });46 it('should get the amount of memory used by the process', async () => {47 let memory = await driver.getPerformanceData(caps.appPackage, 'memoryinfo', 2);48 Array.isArray(memory).should.be.true;49 memory.length.should.be.above(1);50 memory[0].should.eql(MEMORY_KEYS);51 if (memory.length > 1) {52 for (let i = 1; i < memory.length; i++) {53 memory[0].length.should.equal(memory[i].length);54 }55 }56 });57 it('should get the remaining battery power', async () => {58 let battery = await driver.getPerformanceData(caps.appPackage, 'batteryinfo', 2);59 Array.isArray(battery).should.be.true;60 battery.length.should.be.above(1);61 battery[0].should.eql(BATTERY_KEYS);62 if (battery.length > 1) {63 for (let i = 1; i < battery.length; i++) {64 battery[0].length.should.equal(battery[i].length);65 }66 }67 });68 it('should get the network statistics', async function () {69 // TODO: why does adb fail with a null pointer exception on 5.170 if (await driver.adb.getApiLevel() === 22) {71 return this.skip();72 }73 let network = await driver.getPerformanceData(caps.appPackage, 'networkinfo', 2);74 Array.isArray(network).should.be.true;75 network.length.should.be.above(1);76 let compare = false;77 for (let j = 0; j < NETWORK_KEYS.length; ++j) {78 if (_.isEqual(NETWORK_KEYS[j], network[0])) {79 compare = true;80 }81 }82 compare.should.equal(true);83 if (network.length > 1) {84 for (let i = 1; i < network.length; ++i) {...
recordscreen-e2e-specs.js
Source:recordscreen-e2e-specs.js
...18 after(async function () {19 await driver.deleteSession();20 });21 it('should start and stop recording the screen', async function () {22 if (await driver.isEmulator() || await driver.adb.getApiLevel() < 19) {23 return this.skip();24 }25 await driver.startRecordingScreen();26 // do some interacting, to take some time27 let el = await driver.findElement('class name', 'android.widget.EditText');28 el = el.ELEMENT;29 await driver.setValue('Recording the screen!', el);30 let text = await driver.getText(el);31 text.should.eql('Recording the screen!');32 (await driver.stopRecordingScreen()).should.not.be.empty;33 });...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').build();3driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');4driver.findElement(webdriver.By.name('btnG')).click();5driver.wait(function() {6 return driver.getTitle().then(function(title) {7 return title === 'webdriver - Google Search';8 });9}, 1000);10driver.quit();11var webdriver = require('selenium-webdriver');12var driver = new webdriver.Builder().forBrowser('chrome').build();13driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');14driver.findElement(webdriver.By.name('btnG')).click();15driver.wait(function() {16 return driver.getTitle().then(function(title) {17 return title === 'webdriver - Google Search';18 });19}, 1000);20driver.quit();21var webdriver = require('selenium-webdriver');22var driver = new webdriver.Builder().forBrowser('chrome').build();23driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');24driver.findElement(webdriver.By.name('btnG')).click();25driver.wait(function() {26 return driver.getTitle().then(function(title) {27 return title === 'webdriver - Google Search';28 });29}, 1000);30driver.quit();31var webdriver = require('selenium-webdriver');32var driver = new webdriver.Builder().forBrowser('chrome').build();33driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');34driver.findElement(webdriver.By.name('btnG')).click();35driver.wait(function() {36 return driver.getTitle().then(function(title) {37 return title === 'webdriver - Google Search';38 });39}, 1000);40driver.quit();41var webdriver = require('selenium-webdriver');42var driver = new webdriver.Builder().forBrowser('chrome').build();43driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');44driver.findElement(webdriver.By.name('btnG')).click();45driver.wait(function() {46 return driver.getTitle().then(function(title) {47 return title === 'webdriver - Google Search';48 });49}, 100
Using AI Code Generation
1console.log(await driver.adb.getApiLevel());2console.log(await driver.adb.getApiLevel());3console.log(await driver.adb.getApiLevel());4console.log(await driver.adb.getApiLevel());5console.log(await driver.adb.getApiLevel());6console.log(await driver.adb.getApiLevel());7console.log(await driver.adb.getApiLevel());8console.log(await driver.adb.getApiLevel());9console.log(await driver.adb.getApiLevel());10console.log(await driver.adb.getApiLevel());11console.log(await driver.adb.getApiLevel());12console.log(await driver.adb.getApiLevel());13console.log(await driver.adb.getApiLevel());14console.log(await driver.adb.getApiLevel());
Using AI Code Generation
1const wd = require('wd');2const { androidConfig } = require('./helpers/caps');3const { APPIUM_HOST, APPIUM_PORT } = require('./helpers/constants');4const driver = wd.promiseChainRemote(APPIUM_HOST, APPIUM_PORT);5describe('Android Driver', function () {6 before(async function () {7 await driver.init(androidConfig);8 });9 it('should get Android API level', async function () {10 const apiLevel = await driver.adb.getApiLevel();11 console.log(`Android API level: ${apiLevel}`);12 });13 after(async function () {14 await driver.quit();15 });16});17const { APPIUM_HOST, APPIUM_PORT } = require('./constants');18const androidConfig = {
Using AI Code Generation
1var driver = new AndroidDriver();2driver.adb.getApiLevel().then(function(apiLevel) {3 console.log("apiLevel: " + apiLevel);4});5AndroidDriver.prototype.getApiLevel = function() {6 return this.adb.getApiLevel();7}8Android.prototype.getApiLevel = function() {9 return this.shell("getprop ro.build.version.sdk");10}11ADB.prototype.shell = function(cmd, cb) {12 var args = ["shell", cmd];13 return this.exec(args, {timeout: 0}).nodeify(cb);14}15systemCallMethods.exec = async function(args, opts) {16 let {stdout} = await exec(this.executable.path, args, opts);17 return stdout;18}19systemCallMethods.exec = async function(args, opts) {20 let {stdout} = await exec(this.executable.path, args, opts);21 return stdout;22}23systemCallMethods.exec = async function(args, opts) {24 let {stdout} = await exec(this.executable.path, args, opts);25 return stdout;26}27systemCallMethods.exec = async function(args, opts) {28 let {stdout} = await exec(this.executable.path, args, opts);29 return stdout;30}31systemCallMethods.exec = async function(args, opts) {32 let {stdout} = await exec(this.executable.path, args, opts);33 return stdout;34}
Using AI Code Generation
1var driver = new AndroidDriver();2driver.adb.getApiLevel().then(function (apiLevel) {3 console.log("API Level: " + apiLevel);4});5var driver = new AndroidDriver();6driver.adb.getEmulatorPort().then(function (port) {7 console.log("Emulator Port: " + port);8});9var driver = new AndroidDriver();10driver.adb.getConnectedEmulators().then(function (emulators) {11 console.log("
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!!