How to use adb.getApiLevel method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

actions-specs.js

Source:actions-specs.js Github

copy

Full Screen

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 });...

Full Screen

Full Screen

chromedriver-specs.js

Source:chromedriver-specs.js Github

copy

Full Screen

1import { Chromedriver, getMostRecentChromedriver } from '../lib/chromedriver';2import * as utils from '../lib/utils';3import sinon from 'sinon';4import chai from 'chai';5import { fs } from 'appium-support';6import * as tp from 'teen_process';7import path from 'path';8import _ from 'lodash';9chai.should();10describe('chromedriver', function () {11 let sandbox;12 beforeEach(function () {13 sandbox = sinon.createSandbox();14 });15 afterEach(function () {16 sandbox.restore();17 });18 describe('getCompatibleChromedriver', function () {19 describe('desktop', function () {20 it('should find generic binary', async function () {21 sandbox.stub(utils, 'getChromedriverBinaryPath')22 .returns('/path/to/chromedriver');23 const cd = new Chromedriver({});24 const binPath = await cd.getCompatibleChromedriver();25 binPath.should.eql('/path/to/chromedriver');26 });27 });28 describe('Android', function () {29 let cd;30 let getChromedriverBinaryPathSpy;31 before(function () {32 cd = new Chromedriver({33 adb: {34 getApiLevel: () => 25,35 },36 });37 });38 beforeEach(function () {39 getChromedriverBinaryPathSpy = sandbox.spy(utils, 'getChromedriverBinaryPath');40 });41 afterEach(function () {42 getChromedriverBinaryPathSpy.called.should.be.false;43 });44 it('should find a compatible binary if only one binary exists', async function () {45 sandbox.stub(utils, 'getChromeVersion')46 .returns('63.0.3239.99');47 sandbox.stub(fs, 'glob')48 .returns([49 '/path/to/chromedriver',50 ]);51 sandbox.stub(tp, 'exec')52 .returns({53 stdout: 'ChromeDriver 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',54 });55 const binPath = await cd.getCompatibleChromedriver();56 binPath.should.eql('/path/to/chromedriver');57 });58 it('should find most recent compatible binary from a number of possibilities', async function () {59 sandbox.stub(utils, 'getChromeVersion')60 .returns('59.0.3029.42');61 sandbox.stub(fs, 'glob')62 .returns([63 '/path/to/chromedriver-36',64 '/path/to/chromedriver-35',65 '/path/to/chromedriver-34',66 '/path/to/chromedriver-33',67 '/path/to/chromedriver-32',68 '/path/to/chromedriver-31',69 '/path/to/chromedriver-30',70 ]);71 sandbox.stub(tp, 'exec')72 .onCall(0)73 .returns({74 stdout: 'ChromeDriver 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',75 })76 .onCall(0)77 .returns({78 stdout: 'ChromeDriver 2.35.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',79 })80 .onCall(0)81 .returns({82 stdout: 'ChromeDriver 2.34.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',83 })84 .onCall(0)85 .returns({86 stdout: 'ChromeDriver 2.33.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',87 })88 .onCall(0)89 .returns({90 stdout: 'ChromeDriver 2.32.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',91 })92 .onCall(0)93 .returns({94 stdout: 'ChromeDriver 2.31.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',95 })96 .onCall(0)97 .returns({98 stdout: 'ChromeDriver 2.30.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',99 });100 const binPath = await cd.getCompatibleChromedriver();101 binPath.should.eql('/path/to/chromedriver-36');102 });103 it('should correctly determine Chromedriver versions', async function () {104 sandbox.stub(fs, 'glob')105 .returns([106 '/path/to/chromedriver-36',107 '/path/to/chromedriver-35',108 '/path/to/chromedriver-34',109 '/path/to/chromedriver-33',110 '/path/to/chromedriver-32',111 '/path/to/chromedriver-31',112 '/path/to/chromedriver-30',113 ]);114 sandbox.stub(tp, 'exec')115 .onCall(0)116 .returns({117 stdout: 'ChromeDriver 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',118 })119 .onCall(1)120 .returns({121 stdout: 'ChromeDriver 2.35.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',122 })123 .onCall(2)124 .returns({125 stdout: 'ChromeDriver 2.34.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',126 })127 .onCall(3)128 .returns({129 stdout: 'ChromeDriver 2.33.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',130 })131 .onCall(4)132 .returns({133 stdout: 'ChromeDriver 2.32.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',134 })135 .onCall(5)136 .returns({137 stdout: 'ChromeDriver 2.31.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',138 })139 .onCall(6)140 .returns({141 stdout: 'ChromeDriver 2.30.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',142 });143 const chromedrivers = await cd.getChromedrivers({});144 for (const [cd, expectedVersion] of _.zip(chromedrivers, ['2.36', '2.35', '2.34', '2.33', '2.32', '2.31', '2.30'])) {145 cd.version.should.eql(expectedVersion);146 }147 });148 it('should find most recent binary from a number of possibilities when chrome is too new', async function () {149 sandbox.stub(utils, 'getChromeVersion')150 .returns('70.0.0.42');151 sandbox.stub(fs, 'glob')152 .returns([153 '/path/to/chromedriver-9000',154 '/path/to/chromedriver-8999',155 '/path/to/chromedriver-36',156 '/path/to/chromedriver-35',157 ]);158 sandbox.stub(tp, 'exec')159 .onCall(0)160 .returns({161 stdout: 'ChromeDriver 2.9000.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',162 })163 .onCall(0)164 .returns({165 stdout: 'ChromeDriver 2.8999.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',166 })167 .onCall(0)168 .returns({169 stdout: 'ChromeDriver 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',170 })171 .onCall(0)172 .returns({173 stdout: 'ChromeDriver 2.35.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',174 });175 const binPath = await cd.getCompatibleChromedriver();176 binPath.should.eql('/path/to/chromedriver-9000');177 });178 it('should search specified directory if provided', async function () {179 const cd = new Chromedriver({180 adb: {181 getApiLevel: () => 25,182 },183 executableDir: '/some/local/dir/for/chromedrivers',184 });185 sandbox.stub(utils, 'getChromeVersion')186 .returns('63.0.3239.99');187 sandbox.stub(fs, 'glob')188 .withArgs('/some/local/dir/for/chromedrivers/*')189 .returns([190 '/some/local/dir/for/chromedrivers/chromedriver',191 ]);192 sandbox.stub(tp, 'exec')193 .returns({194 stdout: 'ChromeDriver 2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',195 });196 const binPath = await cd.getCompatibleChromedriver();197 binPath.should.eql('/some/local/dir/for/chromedrivers/chromedriver');198 });199 it('should use alternative mapping if provided', async function () {200 const cd = new Chromedriver({201 adb: {202 getApiLevel: () => 25,203 },204 mappingPath: path.resolve(__dirname, '..', '..', 'test', 'fixtures', 'alt-mapping.json'),205 });206 sandbox.stub(utils, 'getChromeVersion')207 .returns('63.0.3239.99');208 sandbox.stub(fs, 'glob')209 .returns([210 '/path/to/chromedriver-42',211 ]);212 sandbox.stub(tp, 'exec')213 .returns({214 stdout: 'ChromeDriver 2.42.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',215 });216 const binPath = await cd.getCompatibleChromedriver();217 binPath.should.eql('/path/to/chromedriver-42');218 });219 it('should use alternative mapping if provided even if semver is broken', async function () {220 const cd = new Chromedriver({221 adb: {222 getApiLevel: () => 25,223 },224 mappingPath: path.resolve(__dirname, '..', '..', 'test', 'fixtures', 'alt-mapping-nonsemver.json'),225 });226 sandbox.stub(utils, 'getChromeVersion')227 .returns('63.0.3239.99');228 sandbox.stub(fs, 'glob')229 .returns([230 '/path/to/chromedriver-42',231 ]);232 sandbox.stub(tp, 'exec')233 .returns({234 stdout: 'ChromeDriver 2.42.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8)',235 });236 const binPath = await cd.getCompatibleChromedriver();237 binPath.should.eql('/path/to/chromedriver-42');238 });239 });240 });241 describe('getMostRecentChromedriver', function () {242 it('should get a value by default', function () {243 getMostRecentChromedriver().should.be.a.string;244 });245 it('should get the most recent version', function () {246 const mapping = {247 '2.12': '36.0.1985',248 '2.11': '36.0.1985',249 '2.10': '33.0.1751',250 '2.9': '31.0.1650',251 '2.8': '30.0.1573',252 '2.7': '30.0.1573',253 '2.6': '29.0.1545',254 };255 getMostRecentChromedriver(mapping).should.eql('2.12');256 });257 it('should handle broken semver', function () {258 const mapping = {259 '2.12': '36.0.1985',260 'v2.11': '36.0.1985',261 '2.10.0.0': '33.0.1751',262 '2.9-beta': '31.0.1650',263 '2.8': '30.0.1573',264 '2.7': '30.0.1573',265 '2.6': '29.0.1545',266 };267 getMostRecentChromedriver(mapping).should.eql('2.12');268 });269 it('should fail for empty mapping', function () {270 (() => getMostRecentChromedriver({}))271 .should.throw('Unable to get most recent Chromedriver from empty mapping');272 });273 });...

Full Screen

Full Screen

network-specs.js

Source:network-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import sinon from 'sinon';4import ADB from 'appium-adb';5import AndroidDriver from '../../..';6import B from 'bluebird';7let driver;8let adb;9let sandbox = sinon.sandbox.create();10chai.should();11chai.use(chaiAsPromised);12describe('Network', () => {13 beforeEach(async () => {14 driver = new AndroidDriver();15 adb = new ADB();16 driver.adb = adb;17 sandbox.stub(adb);18 sandbox.stub(driver, 'isEmulator');19 sandbox.stub(driver, 'wrapBootstrapDisconnect', async (fn) => {20 await fn();21 });22 sandbox.stub(B, 'delay');23 });24 afterEach(() => {25 sandbox.restore();26 });27 describe('getNetworkConnection', () => {28 beforeEach(() => {29 adb.isAirplaneModeOn.returns(false);30 adb.isDataOn.returns(false);31 sandbox.stub(driver, 'isWifiOn').returns(false);32 });33 it('should determine nothing enabled', async () => {34 await driver.getNetworkConnection().should.eventually.equal(0);35 });36 it('should determine airplane mode is on', async () => {37 adb.isAirplaneModeOn.returns(true);38 await driver.getNetworkConnection().should.eventually.equal(1);39 });40 it('should determine wifi is on', async () => {41 driver.isWifiOn.returns(true);42 await driver.getNetworkConnection().should.eventually.equal(2);43 });44 it('should determine data is on', async () => {45 adb.isDataOn.returns(true);46 await driver.getNetworkConnection().should.eventually.equal(4);47 });48 it('should determine wifi and data are on', async () => {49 driver.isWifiOn.returns(true);50 adb.isDataOn.returns(true);51 await driver.getNetworkConnection().should.eventually.equal(6);52 });53 });54 describe('isWifiOn', () => {55 it('should return wifi state', async () => {56 adb.isWifiOn.returns('wifi_state');57 await driver.isWifiOn().should.become('wifi_state');58 });59 });60 describe('setNetworkConnection', () => {61 beforeEach(async () => {62 sandbox.stub(driver, 'getNetworkConnection').returns('res');63 sandbox.stub(driver, 'setWifiState');64 driver.isEmulator.returns(false);65 });66 it('should turn off wifi and data', async () => {67 await driver.setNetworkConnection(0).should.become('res');68 adb.setAirplaneMode.calledWithExactly(0).should.be.true;69 adb.broadcastAirplaneMode.calledWithExactly(0).should.be.true;70 driver.setWifiState.calledWithExactly(0).should.be.true;71 adb.setDataState.calledWithExactly(0, false).should.be.true;72 });73 it('should turn on and broadcast airplane mode', async () => {74 await driver.setNetworkConnection(1);75 adb.setAirplaneMode.calledWithExactly(1).should.be.true;76 adb.broadcastAirplaneMode.calledWithExactly(1).should.be.true;77 driver.setWifiState.called.should.be.false;78 adb.setDataState.called.should.be.false;79 });80 it('should turn on wifi', async () => {81 await driver.setNetworkConnection(2);82 adb.setAirplaneMode.calledWithExactly(0).should.be.true;83 adb.broadcastAirplaneMode.calledWithExactly(0).should.be.true;84 driver.setWifiState.calledWithExactly(1).should.be.true;85 adb.setDataState.calledWithExactly(0, false).should.be.true;86 });87 it('should turn on data', async () => {88 await driver.setNetworkConnection(4);89 adb.setAirplaneMode.calledWithExactly(0).should.be.true;90 adb.broadcastAirplaneMode.calledWithExactly(0).should.be.true;91 driver.setWifiState.calledWithExactly(0).should.be.true;92 adb.setDataState.calledWithExactly(1, false).should.be.true;93 });94 it('should turn on data and wifi', async () => {95 await driver.setNetworkConnection(6);96 adb.setAirplaneMode.calledWithExactly(0).should.be.true;97 adb.broadcastAirplaneMode.calledWithExactly(0).should.be.true;98 driver.setWifiState.calledWithExactly(1).should.be.true;99 adb.setDataState.calledWithExactly(1, false).should.be.true;100 });101 });102 describe('setWifiState', () => {103 it('should set wifi state', async () => {104 driver.isEmulator.returns('is_emu');105 await driver.setWifiState('wifi_state');106 adb.setWifiState.calledWithExactly('wifi_state', 'is_emu').should.be.true;107 });108 });109 describe('toggleData', () => {110 it('should toggle data', async () => {111 adb.isDataOn.returns(false);112 driver.isEmulator.returns('is_emu');113 adb.setWifiAndData.returns('');114 await driver.toggleData();115 adb.setWifiAndData.calledWithExactly({data: true}, 'is_emu')116 .should.be.true;117 });118 });119 describe('toggleWiFi', () => {120 it('should toggle wifi', async () => {121 adb.isWifiOn.returns(false);122 driver.isEmulator.returns('is_emu');123 adb.setWifiAndData.returns('');124 await driver.toggleWiFi();125 adb.setWifiAndData.calledWithExactly({wifi: true}, 'is_emu')126 .should.be.true;127 });128 });129 describe('toggleFlightMode', () => {130 it('should toggle flight mode', async () => {131 adb.isAirplaneModeOn.returns(false);132 adb.setAirplaneMode.returns('');133 adb.broadcastAirplaneMode.returns('');134 await driver.toggleFlightMode();135 adb.setAirplaneMode.calledWithExactly(true).should.be.true;136 adb.broadcastAirplaneMode.calledWithExactly(true).should.be.true;137 });138 });139 describe('setGeoLocation', () => {140 it('should set location', async () => {141 adb.setGeoLocation.withArgs('location', 'is_emu').returns('res');142 driver.isEmulator.returns('is_emu');143 await driver.setGeoLocation('location').should.become('res');144 });145 });146 describe('toggleLocationSettings', () => {147 beforeEach(async () => {148 sandbox.stub(driver, 'toggleSetting');149 });150 it('should throw an error for API<16', async () => {151 adb.getApiLevel.returns(15);152 driver.isEmulator.returns(false);153 await driver.toggleLocationServices().should.eventually.be.rejectedWith(/implemented/);154 });155 it('should generate the correct sequence of keys for API 16', async () => {156 let sequence = [19, 19, 20];157 adb.getApiLevel.returns(16);158 driver.isEmulator.returns(false);159 await driver.toggleLocationServices();160 driver.toggleSetting.calledWith('LOCATION_SOURCE_SETTINGS', sequence).should.be.true;161 });162 it('should generate the correct sequence of keys for API >= 19', async () => {163 let sequence = [22, 22, 19];164 adb.getApiLevel.returns(19);165 driver.isEmulator.returns(false);166 await driver.toggleLocationServices();167 adb.keyevent.calledWithExactly(19).should.be.true;168 driver.toggleSetting.calledWith('LOCATION_SOURCE_SETTINGS', sequence)169 .should.be.true;170 });171 it('should set gps for emulators', async () => {172 adb.getApiLevel.returns(19);173 driver.isEmulator.returns(true);174 adb.getLocationProviders.returns(['wifi']);175 await driver.toggleLocationServices();176 adb.toggleGPSLocationProvider.calledWithExactly(true).should.be.true;177 });178 });179 describe('toggleSetting', () => {180 beforeEach(() => {181 sandbox.stub(driver, 'doKey').returns('');182 sandbox.stub(driver, 'openSettingsActivity').returns('');183 adb.getFocusedPackageAndActivity184 .returns({appPackage: 'fpkg', appActivity:'fact'});185 });186 it('should toggle setting', async () => {187 await driver.toggleSetting('set', [61, 72]);188 driver.doKey.getCall(0).args[0].should.be.equal(61);189 driver.doKey.getCall(1).args[0].should.be.equal(72);190 driver.doKey.getCall(2).args[0].should.be.equal(23);191 driver.doKey.getCall(3).args[0].should.be.equal(22);192 driver.doKey.getCall(4).args[0].should.be.equal(23);193 driver.openSettingsActivity.calledWithExactly('set').should.be.true;194 adb.waitForNotActivity.calledTwice.should.be.true;195 adb.waitForNotActivity.alwaysCalledWith('fpkg', 'fact').should.be.true;196 adb.back.calledOnce.should.be.true;197 });198 it('should use default key sequence', async () => {199 await driver.toggleSetting('set', null);200 driver.doKey.getCall(0).args[0].should.be.equal(19);201 driver.doKey.getCall(1).args[0].should.be.equal(19);202 driver.doKey.getCall(2).args[0].should.be.equal(20);203 });204 it('should skip errors from adb.waitForNotActivity', async () => {205 adb.waitForNotActivity.throws();206 await driver.toggleSetting('set', null).should.be.fulfilled;207 });208 });209 describe('doKey', () => {210 it('should send key event', async () => {211 await driver.doKey(55);212 adb.keyevent.calledWithExactly(55).should.be.true;213 });214 });215 describe('wrapBootstrapDisconnect', () => {216 it('should restart adb and start bootstrap', async () => {217 driver.wrapBootstrapDisconnect.restore();218 let fn = sandbox.stub();219 driver.bootstrap = sandbox.stub();220 driver.bootstrap.start = sandbox.stub();221 driver.opts = {appPackage: 'pkg', disableAndroidWatchers: 'daw', acceptSslCerts: 'acert'};222 await driver.wrapBootstrapDisconnect(fn);223 sinon.assert.callOrder(fn, adb.restart, driver.bootstrap.start);224 driver.bootstrap.calledWithExactly('pkg', 'daw', 'acert');225 driver.bootstrap.ignoreUnexpectedShutdown.should.be.false;226 });227 });...

Full Screen

Full Screen

unlock-helpers.js

Source:unlock-helpers.js Github

copy

Full Screen

...52 // dismiss notifications53 logger.info('Dismiss notifications from unlock view');54 await adb.shell(['service', 'call', 'notification', '1']);55 await adb.back();56 if (await adb.getApiLevel() > 21) {57 logger.info('Trying to dismiss keyguard');58 await adb.shell(['wm', 'dismiss-keyguard']);59 return;60 }61 logger.info('Swiping up to dismiss keyguard');62 await helpers.swipeUp(driver);63};64helpers.swipeUp = async function swipeUp (driver) {65 let windowSize = await driver.getWindowSize();66 let x0 = parseInt(windowSize.x / 2, 10);67 let y0 = windowSize.y - 10;68 let yP = 100;69 let actions = [70 {action: 'press', options: {element: null, x: x0, y: y0}},71 {action: 'moveTo', options: {element: null, x: x0, y: yP}},72 {action: 'release'}73 ];74 await driver.performTouch(actions);75};76helpers.encodePassword = function encodePassword (key) {77 return key.replace(/\s/ig, '%s');78};79helpers.stringKeyToArr = function stringKeyToArr (key) {80 return key.trim().replace(/\s+/g, '').split(/\s*/);81};82helpers.fingerprintUnlock = async function fingerprintUnlock (adb, driver, capabilities) {83 if (await adb.getApiLevel() < 23) {84 throw new Error('Fingerprint unlock only works for Android 6+ emulators');85 }86 await adb.fingerprint(capabilities.unlockKey);87 await sleep(UNLOCK_WAIT_TIME);88};89helpers.pinUnlock = async function pinUnlock (adb, driver, capabilities) {90 logger.info(`Trying to unlock device using pin ${capabilities.unlockKey}`);91 await helpers.dismissKeyguard(driver, adb);92 let keys = helpers.stringKeyToArr(capabilities.unlockKey);93 if (await adb.getApiLevel() >= 21) {94 let els = await driver.findElOrEls('id', 'com.android.systemui:id/digit_text', true);95 if (_.isEmpty(els)) {96 throw new Error('Error finding unlock pin buttons!');97 }98 let pins = {};99 for (let el of els) {100 let text = await driver.getAttribute('text', util.unwrapElement(el));101 pins[text] = el;102 }103 for (let pin of keys) {104 let el = pins[pin];105 await driver.click(util.unwrapElement(el));106 }107 } else {108 for (let pin of keys) {109 let el = await driver.findElOrEls('id', `com.android.keyguard:id/key${pin}`, false);110 if (el === null) {111 throw new Error(`Error finding unlock pin '${pin}' button!`);112 }113 await driver.click(util.unwrapElement(el));114 }115 }116 // Some devices accept entering the code without pressing the Enter key117 // When I rushed commands without this wait before pressKeyCode, rarely UI2 sever crashed118 await sleep(UNLOCK_WAIT_TIME);119 if (await adb.isScreenLocked()) {120 await driver.pressKeyCode(KEYCODE_NUMPAD_ENTER);121 await sleep(UNLOCK_WAIT_TIME);122 }123};124helpers.passwordUnlock = async function passwordUnlock (adb, driver, capabilities) {125 logger.info(`Trying to unlock device using password ${capabilities.unlockKey}`);126 await helpers.dismissKeyguard(driver, adb);127 let key = capabilities.unlockKey;128 // Replace blank spaces with %s129 key = helpers.encodePassword(key);130 // Why adb ? It was less flaky131 await adb.shell(['input', 'text', key]);132 // Why sleeps ? Avoid some flakyness waiting for the input to receive the keys133 await sleep(INPUT_KEYS_WAIT_TIME);134 await adb.shell(['input', 'keyevent', KEYCODE_NUMPAD_ENTER]);135 // Waits a bit for the device to be unlocked136 await sleep(UNLOCK_WAIT_TIME);137};138helpers.getPatternKeyPosition = function getPatternKeyPosition (key, initPos, piece) {139 /*140 How the math works:141 We have 9 buttons divided in 3 columns and 3 rows inside the lockPatternView,142 every button has a position on the screen corresponding to the lockPatternView since143 it is the parent view right at the middle of each column or row.144 */145 const cols = 3;146 const pins = 9;147 const xPos = (key, x, piece) => Math.round(x + ((key % cols) || cols) * piece - piece / 2);148 const yPos = (key, y, piece) => Math.round(y + (Math.ceil(((key % pins) || pins) / cols) * piece - piece / 2));149 return {x: xPos(key, initPos.x, piece), y: yPos(key, initPos.y, piece)};150};151helpers.getPatternActions = function getPatternActions (keys, initPos, piece) {152 let actions = [];153 let lastPos;154 for (let key of keys) {155 let keyPos = helpers.getPatternKeyPosition(key, initPos, piece);156 if (key === keys[0]) {157 actions.push({action: 'press', options: {element: null, x: keyPos.x, y: keyPos.y}});158 lastPos = keyPos;159 continue;160 }161 let moveTo = {x: 0, y: 0};162 let diffX = keyPos.x - lastPos.x;163 if (diffX > 0) {164 moveTo.x = piece;165 if (Math.abs(diffX) > piece) {166 moveTo.x += piece;167 }168 } else if (diffX < 0) {169 moveTo.x = -1 * piece;170 if (Math.abs(diffX) > piece) {171 moveTo.x -= piece;172 }173 }174 let diffY = keyPos.y - lastPos.y;175 if (diffY > 0) {176 moveTo.y = piece;177 if (Math.abs(diffY) > piece) {178 moveTo.y += piece;179 }180 } else if (diffY < 0) {181 moveTo.y = -1 * piece;182 if (Math.abs(diffY) > piece) {183 moveTo.y -= piece;184 }185 }186 actions.push({action: 'moveTo', options: {element: null, x: moveTo.x + lastPos.x, y: moveTo.y + lastPos.y}});187 lastPos = keyPos;188 }189 actions.push({action: 'release'});190 return actions;191};192helpers.patternUnlock = async function patternUnlock (adb, driver, capabilities) {193 logger.info(`Trying to unlock device using pattern ${capabilities.unlockKey}`);194 await helpers.dismissKeyguard(driver, adb);195 let keys = helpers.stringKeyToArr(capabilities.unlockKey);196 /* We set the device pattern buttons as number of a regular phone197 * | • • • | | 1 2 3 |198 * | • • • | --> | 4 5 6 |199 * | • • • | | 7 8 9 |200 The pattern view buttons are not seeing by the uiautomator since they are201 included inside a FrameLayout, so we are going to try clicking on the buttons202 using the parent view bounds and math.203 */204 let apiLevel = await adb.getApiLevel();205 let el = await driver.findElOrEls('id',206 `com.android.${apiLevel >= 21 ? 'systemui' : 'keyguard'}:id/lockPatternView`,207 false208 );209 let initPos = await driver.getLocation(util.unwrapElement(el));210 let size = await driver.getSize(util.unwrapElement(el));211 // Get actions to perform212 let actions = helpers.getPatternActions(keys, initPos, size.width / 3);213 // Perform gesture214 await driver.performTouch(actions);215 // Waits a bit for the device to be unlocked216 await sleep(UNLOCK_WAIT_TIME);217};218helpers.PIN_UNLOCK = PIN_UNLOCK;...

Full Screen

Full Screen

performance-e2e-specs.js

Source:performance-e2e-specs.js Github

copy

Full Screen

...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) {...

Full Screen

Full Screen

android-helper-e2e-specs.js

Source:android-helper-e2e-specs.js Github

copy

Full Screen

...38 await helpers.ensureDeviceLocale(adb, 'en', 'US');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 enter...

Full Screen

Full Screen

language-e2e-specs.js

Source:language-e2e-specs.js Github

copy

Full Screen

...16 this.skip();17 }18 // restarting doesn't work on Android 7+19 let adb = new ADB();20 if (await adb.getApiLevel() > 23) return this.skip(); //eslint-disable-line curly21 initialLocale = await getLocale(adb);22 });23 let driver;24 after(async function () {25 if (driver) {26 if (await adb.getApiLevel() > 23) {27 let [language, country] = initialLocale.split('-');28 await androidHelpers.ensureDeviceLocale(driver.adb, language, country);29 } else {30 await androidHelpers.ensureDeviceLocale(driver.adb, null, initialLocale);31 }32 await deleteSession();33 }34 });35 it('should start as FR', async function () {36 let frCaps = Object.assign({}, APIDEMOS_CAPS, {37 language: 'fr',38 locale: 'FR',39 });40 driver = await initSession(frCaps);...

Full Screen

Full Screen

helpers.js

Source:helpers.js Github

copy

Full Screen

1import { exec } from 'teen_process';2import ADB from 'appium-adb';3async function getLocale (adb = new ADB()) {4 if (await adb.getApiLevel() < 23) {5 return await adb.getDeviceCountry();6 } else {7 return await adb.getDeviceLocale();8 }9}10async function isArmEmu () {11 const archCmd = ['adb', 'shell getprop ro.product.cpu.abi'.split(' ')];12 const serialCmd = ['adb', ['get-serialno']];13 const {stdout: arch} = await exec(...archCmd);14 const {stdout: serial} = await exec(...serialCmd);15 if (arch.indexOf('arm') !== -1 && serial.indexOf('emulator') === 0) {16 return true;17 }18}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2 adb = require('appium-adb');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);9adb.getApiLevel().then(function(apiLevel) {10 console.log(apiLevel);11 driver.quit();12});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var appium = require('appium');3var assert = require('assert');4var desiredCaps = {5};6var driver = wd.promiseChainRemote("

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var chrome = require('selenium-webdriver/chrome');3var adb = require('appium-adb');4var driver = new webdriver.Builder().forBrowser('chrome').build();5var adb = new ADB();6adb.getApiLevel(function(err, apiLevel) {7 console.log(apiLevel);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = require('./desired');4describe("Android", function () {5 this.timeout(300000);6 var driver;7 before(function (done) {8 driver.init(desired).nodeify(done);9 });10 after(function (done) {11 driver.quit().nodeify(done);12 });13 it("should get the API level", function (done) {14 .getApiLevel()15 .then(function (apiLevel) {16 console.log("API Level is: " + apiLevel);17 done();18 })19 .catch(function (err) {20 console.log(err);21 done();22 });23 });24});25var desired = {26};27module.exports = desired;28 .getApiLevel()29 .then(function (apiLevel) {30 console.log("API Level is: " + apiLevel);31 assert.equal(apiLevel, 19, "API level is not 19");32 done();33 })34 .catch(function (err) {35 console.log(err);36 done();37 });38 .getApiLevel()39 .then(function (apiLevel) {40 console.log("API Level is: " + apiLevel);41 assert.equal(apiLevel, 19, "API level is not 19");42 done();43 })44 .catch(function (err) {45 console.log(err);46 done();47 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var getAppiumServer = require('./getAppiumServer');4var serverConfig = getAppiumServer();5var desired = require('./desired');6var driver = wd.promiseChainRemote(serverConfig);7var chai = require('chai');8var chaiAsPromised = require('chai-as-promised');9chai.use(chaiAsPromised);10chai.should();11chaiAsPromised.transferPromiseness = driver.transferPromiseness;12describe('Appium Android Driver', function () {13 this.timeout(300000);14 before(function (done) {15 driver.init(desired).nodeify(done);16 });17 after(function (done) {18 driver.quit().nodeify(done);19 });20 it('should get the api level of the device', function (done) {21 .getApiLevel()22 .then(function (level) {23 level.should.exist;24 level.should.be.a('number');25 }).nodeify(done);26 });27});28var desired = {29};30module.exports = desired;31var serverConfig = {

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Android Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful