How to use adb.installOrUpgrade method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

android-helper-specs.js

Source:android-helper-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import sinon from 'sinon';4import helpers, { prepareAvdArgs, ensureNetworkSpeed } from '../../lib/android-helpers';5import ADB from 'appium-adb';6import { withMocks } from 'appium-test-support';7import { fs } from 'appium-support';8import unlocker from '../../lib/unlock-helpers';9import _ from 'lodash';10import B from 'bluebird';11const should = chai.should();12const REMOTE_TEMP_PATH = '/data/local/tmp';13chai.use(chaiAsPromised);14describe('Android Helpers', function () {15 let adb = new ADB();16 describe('isEmulator', function () {17 it('should be true if driver opts contain avd', async function () {18 (await helpers.isEmulator(null, {avd: 'yolo'})).should.be.true;19 });20 it('should be true if driver opts contain emulator udid', async function () {21 (await helpers.isEmulator({}, {udid: 'Emulator-5554'})).should.be.true;22 });23 it('should be false if driver opts do not contain emulator udid', async function () {24 (await helpers.isEmulator({}, {udid: 'ABCD1234'})).should.be.false;25 });26 it('should be true if device id in adb contains emulator', async function () {27 (await helpers.isEmulator({curDeviceId: 'emulator-5554'}, {})).should.be.true;28 });29 it('should be false if device id in adb does not contain emulator', async function () {30 (await helpers.isEmulator({curDeviceId: 'ABCD1234'}, {})).should.be.false;31 });32 });33 describe('prepareEmulator', withMocks({adb, helpers}, (mocks) => {34 const opts = {avd: 'foo@bar', avdArgs: '', language: 'en', locale: 'us'};35 it('should not launch avd if one is already running', async function () {36 mocks.adb.expects('getRunningAVD').withExactArgs('foobar')37 .returns('foo');38 mocks.adb.expects('launchAVD').never();39 mocks.adb.expects('killEmulator').never();40 await helpers.prepareEmulator(adb, opts);41 mocks.adb.verify();42 });43 it('should launch avd if one is already running', async function () {44 mocks.adb.expects('getRunningAVD').withExactArgs('foobar')45 .returns(null);46 mocks.adb.expects('launchAVD').withExactArgs('foo@bar', {47 args: [],48 env: undefined,49 language: 'en',50 country: 'us',51 launchTimeout: undefined,52 readyTimeout: undefined53 }).returns('');54 await helpers.prepareEmulator(adb, opts);55 mocks.adb.verify();56 });57 it('should parse avd string command line args', async function () {58 const opts = {59 avd: 'foobar',60 avdArgs: '--arg1 "value 1" --arg2 "value 2"',61 avdEnv: {62 k1: 'v1',63 k2: 'v2',64 }65 };66 mocks.adb.expects('getRunningAVD').withExactArgs('foobar')67 .returns(null);68 mocks.adb.expects('launchAVD').withExactArgs('foobar', {69 args: ['--arg1', 'value 1', '--arg2', 'value 2'],70 env: {71 k1: 'v1',72 k2: 'v2',73 },74 language: undefined,75 country: undefined,76 launchTimeout: undefined,77 readyTimeout: undefined78 }).returns('');79 await helpers.prepareEmulator(adb, opts);80 mocks.adb.verify();81 });82 it('should parse avd array command line args', async function () {83 const opts = {84 avd: 'foobar',85 avdArgs: ['--arg1', 'value 1', '--arg2', 'value 2'],86 };87 mocks.adb.expects('getRunningAVD').withExactArgs('foobar')88 .returns(null);89 mocks.adb.expects('launchAVD').withExactArgs('foobar', {90 args: ['--arg1', 'value 1', '--arg2', 'value 2'],91 env: undefined,92 language: undefined,93 country: undefined,94 launchTimeout: undefined,95 readyTimeout: undefined96 }).returns('');97 await helpers.prepareEmulator(adb, opts);98 mocks.adb.verify();99 });100 it('should kill emulator if avdArgs contains -wipe-data', async function () {101 const opts = {avd: 'foo@bar', avdArgs: '-wipe-data'};102 mocks.adb.expects('getRunningAVD').withExactArgs('foobar').returns('foo');103 mocks.adb.expects('killEmulator').withExactArgs('foobar').once();104 mocks.adb.expects('launchAVD').once();105 await helpers.prepareEmulator(adb, opts);106 mocks.adb.verify();107 });108 it('should fail if avd name is not specified', async function () {109 await helpers.prepareEmulator(adb, {}).should.eventually.be.rejected;110 });111 }));112 describe('prepareAvdArgs', withMocks({adb, helpers}, (mocks) => {113 it('should set the correct avdArgs', function () {114 let avdArgs = '-wipe-data';115 (prepareAvdArgs(adb, {avdArgs})).should.eql([avdArgs]);116 });117 it('should add headless arg', function () {118 let avdArgs = '-wipe-data';119 let args = prepareAvdArgs(adb, {isHeadless: true, avdArgs});120 args.should.eql(['-wipe-data', '-no-window']);121 });122 it('should add network speed arg', function () {123 let avdArgs = '-wipe-data';124 let args = prepareAvdArgs(adb, {networkSpeed: 'edge', avdArgs});125 args.should.eql(['-wipe-data', '-netspeed', 'edge']);126 mocks.adb.verify();127 });128 it('should not include empty avdArgs', function () {129 let avdArgs = '';130 let args = prepareAvdArgs(adb, {isHeadless: true, avdArgs});131 args.should.eql(['-no-window']);132 });133 }));134 describe('ensureNetworkSpeed', function () {135 it('should return value if network speed is valid', function () {136 adb.NETWORK_SPEED = {GSM: 'gsm'};137 ensureNetworkSpeed(adb, 'gsm').should.be.equal('gsm');138 });139 it('should return ADB.NETWORK_SPEED.FULL if network speed is invalid', function () {140 adb.NETWORK_SPEED = {FULL: 'full'};141 ensureNetworkSpeed(adb, 'invalid').should.be.equal('full');142 });143 });144 describe('ensureDeviceLocale', withMocks({adb}, (mocks) => {145 it('should call setDeviceLanguageCountry', async function () {146 mocks.adb.expects('setDeviceLanguageCountry').withExactArgs('en', 'US', null).once();147 mocks.adb.expects('ensureCurrentLocale').withExactArgs('en', 'US', null).once().returns(true);148 await helpers.ensureDeviceLocale(adb, 'en', 'US');149 mocks.adb.verify();150 });151 it('should call setDeviceLanguageCountry without script', async function () {152 mocks.adb.expects('setDeviceLanguageCountry').withExactArgs('en', 'US', null).once();153 mocks.adb.expects('ensureCurrentLocale').withExactArgs('en', 'US', null).once().returns(true);154 await helpers.ensureDeviceLocale(adb, 'en', 'US', undefined);155 mocks.adb.verify();156 });157 it('should call setDeviceLanguageCountry with script', async function () {158 mocks.adb.expects('setDeviceLanguageCountry').withExactArgs('zh', 'CN', 'Hans').once();159 mocks.adb.expects('ensureCurrentLocale').withExactArgs('zh', 'CN', 'Hans').once().returns(true);160 await helpers.ensureDeviceLocale(adb, 'zh', 'CN', 'Hans');161 mocks.adb.verify();162 });163 it('should never call setDeviceLanguageCountry', async function () {164 mocks.adb.expects('setDeviceLanguageCountry').never();165 mocks.adb.expects('getApiLevel').never();166 await helpers.ensureDeviceLocale(adb);167 mocks.adb.verify();168 });169 it('should call setDeviceLanguageCountry with throw', async function () {170 mocks.adb.expects('setDeviceLanguageCountry').withExactArgs('fr', 'FR', null).once();171 mocks.adb.expects('ensureCurrentLocale').withExactArgs('fr', 'FR', null).once().returns(false);172 await helpers.ensureDeviceLocale(adb, 'fr', 'FR').should.eventually.be.rejectedWith(Error, `Failed to set language: fr and country: FR`);173 mocks.adb.verify();174 });175 }));176 describe('getDeviceInfoFromCaps', function () {177 // list of device/emu udids to their os versions178 // using list instead of map to preserve order179 let devices = [180 {udid: 'emulator-1234', os: '4.9.2'},181 {udid: 'rotalume-1339', os: '5.1.5'},182 {udid: 'rotalume-1338', os: '5.0.1'},183 {udid: 'rotalume-1337', os: '5.0.1'},184 {udid: 'roamulet-9000', os: '6.0'},185 {udid: 'roamulet-0', os: '2.3'},186 {udid: 'roamulet-2019', os: '9'},187 {udid: '0123456789', os: 'wellhellothere'}188 ];189 let curDeviceId = '';190 before(function () {191 sinon.stub(ADB, 'createADB').callsFake(function () {192 return {193 getDevicesWithRetry () {194 return _.map(devices, function getDevice (device) { return {udid: device.udid}; });195 },196 getPortFromEmulatorString () {197 return 1234;198 },199 getRunningAVD () {200 return {udid: 'emulator-1234', port: 1234};201 },202 setDeviceId (udid) {203 curDeviceId = udid;204 },205 getPlatformVersion () {206 return _.filter(devices, {udid: curDeviceId})[0].os;207 },208 curDeviceId: 'emulator-1234',209 emulatorPort: 1234210 };211 });212 });213 after(function () {214 ADB.createADB.restore();215 });216 it('should throw error when udid not in list', async function () {217 let caps = {218 udid: 'foomulator'219 };220 await helpers.getDeviceInfoFromCaps(caps).should.be.rejectedWith('foomulator');221 });222 it('should get deviceId and emPort when udid is present', async function () {223 let caps = {224 udid: 'emulator-1234'225 };226 let {udid, emPort} = await helpers.getDeviceInfoFromCaps(caps);227 udid.should.equal('emulator-1234');228 emPort.should.equal(1234);229 });230 it('should get first deviceId and emPort if avd, platformVersion, and udid are not given', async function () {231 let {udid, emPort} = await helpers.getDeviceInfoFromCaps();232 udid.should.equal('emulator-1234');233 emPort.should.equal(1234);234 });235 it('should get deviceId and emPort when avd is present', async function () {236 let caps = {237 avd: 'AVD_NAME'238 };239 let {udid, emPort} = await helpers.getDeviceInfoFromCaps(caps);240 udid.should.equal('emulator-1234');241 emPort.should.equal(1234);242 });243 it('should fail if the given platformVersion is not found', async function () {244 let caps = {245 platformVersion: '1234567890'246 };247 await helpers.getDeviceInfoFromCaps(caps)248 .should.be.rejectedWith('Unable to find an active device or emulator with OS 1234567890');249 });250 it('should get deviceId and emPort if platformVersion is found and unique', async function () {251 let caps = {252 platformVersion: '6.0'253 };254 let {udid, emPort} = await helpers.getDeviceInfoFromCaps(caps);255 udid.should.equal('roamulet-9000');256 emPort.should.equal(1234);257 });258 it('should get deviceId and emPort if platformVersion is shorter than os version', async function () {259 let caps = {260 platformVersion: 9261 };262 let {udid, emPort} = await helpers.getDeviceInfoFromCaps(caps);263 udid.should.equal('roamulet-2019');264 emPort.should.equal(1234);265 });266 it('should get the first deviceId and emPort if platformVersion is found multiple times', async function () {267 let caps = {268 platformVersion: '5.0.1'269 };270 let {udid, emPort} = await helpers.getDeviceInfoFromCaps(caps);271 udid.should.equal('rotalume-1338');272 emPort.should.equal(1234);273 });274 it('should get the deviceId and emPort of most recent version if we have partial match', async function () {275 let caps = {276 platformVersion: '5.0'277 };278 let {udid, emPort} = await helpers.getDeviceInfoFromCaps(caps);279 udid.should.equal('rotalume-1338');280 emPort.should.equal(1234);281 });282 it('should get deviceId and emPort by udid if udid and platformVersion are given', async function () {283 let caps = {284 udid: '0123456789',285 platformVersion: '2.3'286 };287 let {udid, emPort} = await helpers.getDeviceInfoFromCaps(caps);288 udid.should.equal('0123456789');289 emPort.should.equal(1234);290 });291 });292 describe('createADB', function () {293 let curDeviceId = '';294 let emulatorPort = -1;295 before(function () {296 sinon.stub(ADB, 'createADB').callsFake(function () {297 return {298 setDeviceId: (udid) => { curDeviceId = udid; },299 setEmulatorPort: (emPort) => { emulatorPort = emPort; }300 };301 });302 });303 after(function () {304 ADB.createADB.restore();305 });306 it('should create adb and set device id and emulator port', async function () {307 await helpers.createADB({308 udid: '111222',309 emPort: '111',310 adbPort: '222',311 suppressKillServer: true,312 remoteAdbHost: 'remote_host',313 clearDeviceLogsOnStart: true,314 adbExecTimeout: 50,315 useKeystore: true,316 keystorePath: '/some/path',317 keystorePassword: '123456',318 keyAlias: 'keyAlias',319 keyPassword: 'keyPassword',320 remoteAppsCacheLimit: 5,321 buildToolsVersion: '1.2.3',322 allowOfflineDevices: true,323 });324 ADB.createADB.calledWithExactly({325 adbPort: '222',326 suppressKillServer: true,327 remoteAdbHost: 'remote_host',328 clearDeviceLogsOnStart: true,329 adbExecTimeout: 50,330 useKeystore: true,331 keystorePath: '/some/path',332 keystorePassword: '123456',333 keyAlias: 'keyAlias',334 keyPassword: 'keyPassword',335 remoteAppsCacheLimit: 5,336 buildToolsVersion: '1.2.3',337 allowOfflineDevices: true,338 }).should.be.true;339 curDeviceId.should.equal('111222');340 emulatorPort.should.equal('111');341 });342 it('should not set emulator port if emPort is undefined', async function () {343 emulatorPort = 5555;344 await helpers.createADB();345 emulatorPort.should.equal(5555);346 });347 });348 describe('getLaunchInfoFromManifest', withMocks({adb}, (mocks) => {349 it('should return when no app present', async function () {350 mocks.adb.expects('packageAndLaunchActivityFromManifest').never();351 await helpers.getLaunchInfo(adb, {});352 mocks.adb.verify();353 });354 it('should return when appPackage & appActivity are already present', async function () {355 mocks.adb.expects('packageAndLaunchActivityFromManifest').never();356 await helpers.getLaunchInfo(adb, {357 app: 'foo',358 appPackage: 'bar',359 appActivity: 'act',360 });361 mocks.adb.verify();362 });363 it('should return when all parameters are already present', async function () {364 mocks.adb.expects('packageAndLaunchActivityFromManifest').never();365 await helpers.getLaunchInfo(adb, {app: 'foo', appPackage: 'bar', appWaitPackage: '*', appActivity: 'app.activity', appWaitActivity: 'app.nameA,app.nameB'});366 mocks.adb.verify();367 });368 it('should print warn when all parameters are already present but the format is odd', async function () {369 // It only prints warn message370 mocks.adb.expects('packageAndLaunchActivityFromManifest').never();371 await helpers.getLaunchInfo(adb, {app: 'foo', appPackage: 'bar ', appWaitPackage: '*', appActivity: 'a_act', appWaitActivity: '. '});372 mocks.adb.verify();373 });374 it('should print warn when appPackage & appActivity are already present but the format is odd', async function () {375 // It only prints warn message376 mocks.adb.expects('packageAndLaunchActivityFromManifest').never();377 await helpers.getLaunchInfo(adb, {app: 'foo', appPackage: 'bar', appActivity: 'a_act '});378 mocks.adb.verify();379 });380 it('should return package and launch activity from manifest', async function () {381 mocks.adb.expects('packageAndLaunchActivityFromManifest').withExactArgs('foo')382 .returns({apkPackage: 'pkg', apkActivity: 'ack'});383 const result = {384 appPackage: 'pkg',385 appWaitPackage: 'pkg',386 appActivity: 'ack',387 appWaitActivity: 'ack',388 };389 (await helpers.getLaunchInfo(adb, {app: 'foo'})).should.deep390 .equal(result);391 mocks.adb.verify();392 });393 it('should not override appPackage, appWaitPackage, appActivity, appWaitActivity ' +394 'from manifest if they are allready defined in opts', async function () {395 let optsFromManifest = {apkPackage: 'mpkg', apkActivity: 'mack'};396 mocks.adb.expects('packageAndLaunchActivityFromManifest')397 .withExactArgs('foo').twice().returns(optsFromManifest);398 let inOpts = {app: 'foo', appActivity: 'ack', appWaitPackage: 'wpkg', appWaitActivity: 'wack' };399 let outOpts = {appPackage: 'mpkg', appActivity: 'ack', appWaitPackage: 'wpkg', appWaitActivity: 'wack'};400 (await helpers.getLaunchInfo(adb, inOpts)).should.deep.equal(outOpts);401 inOpts = {app: 'foo', appPackage: 'pkg', appWaitPackage: 'wpkg', appWaitActivity: 'wack'};402 outOpts = {appPackage: 'pkg', appActivity: 'mack', appWaitPackage: 'wpkg', appWaitActivity: 'wack'};403 (await helpers.getLaunchInfo(adb, inOpts)).should.deep.equal(outOpts);404 mocks.adb.verify();405 });406 }));407 describe('resetApp', withMocks({adb, helpers}, (mocks) => {408 const localApkPath = 'local';409 const pkg = 'pkg';410 it('should complain if opts arent passed correctly', async function () {411 await helpers.resetApp(adb, {})412 .should.eventually.be.rejectedWith(/appPackage/);413 });414 it('should be able to do full reset', async function () {415 mocks.adb.expects('install').once().withArgs(localApkPath);416 mocks.adb.expects('forceStop').withExactArgs(pkg).once();417 mocks.adb.expects('isAppInstalled').once().withExactArgs(pkg).returns(true);418 mocks.adb.expects('uninstallApk').once().withExactArgs(pkg);419 await helpers.resetApp(adb, {app: localApkPath, appPackage: pkg});420 mocks.adb.verify();421 });422 it('should be able to do fast reset', async function () {423 mocks.adb.expects('isAppInstalled').once().withExactArgs(pkg).returns(true);424 mocks.adb.expects('forceStop').withExactArgs(pkg).once();425 mocks.adb.expects('clear').withExactArgs(pkg).once().returns('Success');426 mocks.adb.expects('grantAllPermissions').once().withExactArgs(pkg);427 await helpers.resetApp(adb, {app: localApkPath, appPackage: pkg, fastReset: true, autoGrantPermissions: true});428 mocks.adb.verify();429 });430 it('should perform reinstall if app is not installed and fast reset is requested', async function () {431 mocks.adb.expects('isAppInstalled').once().withExactArgs(pkg).returns(false);432 mocks.adb.expects('forceStop').withExactArgs(pkg).never();433 mocks.adb.expects('clear').withExactArgs(pkg).never();434 mocks.adb.expects('uninstallApk').never();435 mocks.adb.expects('install').once().withArgs(localApkPath);436 await helpers.resetApp(adb, {app: localApkPath, appPackage: pkg, fastReset: true});437 mocks.adb.verify();438 });439 }));440 describe('installApk', withMocks({adb, fs, helpers}, function (mocks) {441 //use mock appium capabilities for this test442 const opts = {443 app: 'local',444 appPackage: 'pkg',445 androidInstallTimeout: 90000446 };447 it('should complain if appPackage is not passed', async function () {448 await helpers.installApk(adb, {})449 .should.eventually.be.rejectedWith(/appPackage/);450 });451 it('should install/upgrade and reset app if fast reset is set to true', async function () {452 mocks.adb.expects('installOrUpgrade').once()453 .withArgs(opts.app, opts.appPackage)454 .returns({wasUninstalled: false, appState: 'sameVersionInstalled'});455 mocks.helpers.expects('resetApp').once().withArgs(adb);456 await helpers.installApk(adb, Object.assign({}, opts, {fastReset: true}));457 mocks.adb.verify();458 mocks.helpers.verify();459 });460 it('should reinstall app if full reset is set to true', async function () {461 mocks.adb.expects('installOrUpgrade').never();462 mocks.helpers.expects('resetApp').once().withArgs(adb);463 await helpers.installApk(adb, Object.assign({}, opts, {fastReset: true, fullReset: true}));464 mocks.adb.verify();465 mocks.helpers.verify();466 });467 it('should not run reset if the corresponding option is not set', async function () {468 mocks.adb.expects('installOrUpgrade').once()469 .withArgs(opts.app, opts.appPackage)470 .returns({wasUninstalled: true, appState: 'sameVersionInstalled'});471 mocks.helpers.expects('resetApp').never();472 await helpers.installApk(adb, opts);473 mocks.adb.verify();474 mocks.helpers.verify();475 });476 it('should install/upgrade and skip fast resetting the app if this was the fresh install', async function () {477 mocks.adb.expects('installOrUpgrade').once()478 .withArgs(opts.app, opts.appPackage)479 .returns({wasUninstalled: false, appState: 'notInstalled'});480 mocks.helpers.expects('resetApp').never();481 await helpers.installApk(adb, Object.assign({}, opts, {fastReset: true}));482 mocks.adb.verify();483 mocks.helpers.verify();484 });485 }));486 describe('installOtherApks', withMocks({adb, fs, helpers}, function (mocks) {487 const opts = {488 app: 'local',489 appPackage: 'pkg',490 androidInstallTimeout: 90000491 };492 const fakeApk = '/path/to/fake/app.apk';493 const otherFakeApk = '/path/to/other/fake/app.apk';494 const expectedADBInstallOpts = {495 allowTestPackages: undefined,496 grantPermissions: undefined,497 timeout: opts.androidInstallTimeout,498 };499 it('should not call adb.installOrUpgrade if otherApps is empty', async function () {500 mocks.adb.expects('installOrUpgrade').never();501 await helpers.installOtherApks([], adb, opts);502 mocks.adb.verify();503 });504 it('should call adb.installOrUpgrade once if otherApps has one item', async function () {505 mocks.adb.expects('installOrUpgrade').once().withArgs(fakeApk, null, expectedADBInstallOpts);506 await helpers.installOtherApks([fakeApk], adb, opts);507 mocks.adb.verify();508 });509 it('should call adb.installOrUpgrade twice if otherApps has two item', async function () {510 mocks.adb.expects('installOrUpgrade').twice();511 await helpers.installOtherApks([fakeApk, otherFakeApk], adb, opts);512 mocks.adb.verify();513 });514 }));515 describe('initUnicodeKeyboard', withMocks({adb}, (mocks) => {516 it('should install and enable unicodeIME', async function () {517 mocks.adb.expects('defaultIME').once().returns('defaultIME');518 mocks.adb.expects('enableIME').once().returns('');519 mocks.adb.expects('setIME').once().returns('');520 await helpers.initUnicodeKeyboard(adb);521 mocks.adb.verify();522 });523 }));524 describe('pushSettingsApp', withMocks({adb}, (mocks) => {525 it('should skip granting permissions if the app is already running on over API level 23+ devices', async function () {526 mocks.adb.expects('installOrUpgrade').once()527 .returns(true);528 mocks.adb.expects('processExists')529 .withExactArgs('io.appium.settings').once()530 .returns(true);531 mocks.adb.expects('getApiLevel').never();532 mocks.adb.expects('grantPermissions').never();533 await helpers.pushSettingsApp(adb);534 mocks.adb.verify();535 });536 it('should not skip granting permissions if the app is already running on under API level 22 devices', async function () {537 mocks.adb.expects('installOrUpgrade').once()538 .returns(true);539 mocks.adb.expects('processExists').once()540 .returns(true);541 mocks.adb.expects('getApiLevel').never();542 mocks.adb.expects('grantPermissions').never();543 await helpers.pushSettingsApp(adb);544 mocks.adb.verify();545 });546 it('should launch settings app if it isnt running on over API level 24 devices', async function () {547 mocks.adb.expects('installOrUpgrade').once()548 .returns(true);549 mocks.adb.expects('processExists').once()550 .returns(false);551 mocks.adb.expects('getApiLevel').once()552 .returns(24);553 mocks.adb.expects('requireRunningSettingsApp').once();554 await helpers.pushSettingsApp(adb);555 mocks.adb.verify();556 });557 it('should launch settings app if it isnt running on under API level 23 devices', async function () {558 mocks.adb.expects('installOrUpgrade').once()559 .returns(true);560 mocks.adb.expects('processExists').once()561 .returns(false);562 mocks.adb.expects('getApiLevel').once()563 .returns(23);564 mocks.adb.expects('grantPermissions').once()565 .withExactArgs('io.appium.settings',566 ['android.permission.SET_ANIMATION_SCALE', 'android.permission.CHANGE_CONFIGURATION', 'android.permission.ACCESS_FINE_LOCATION'])567 .returns(true);568 mocks.adb.expects('requireRunningSettingsApp').once();569 await helpers.pushSettingsApp(adb);570 mocks.adb.verify();571 });572 }));573 describe('setMockLocationApp', withMocks({adb}, (mocks) => {574 it('should enable mock location for api level below 23', async function () {575 mocks.adb.expects('getApiLevel').returns(B.resolve(18));576 mocks.adb.expects('shell').withExactArgs(['settings', 'put', 'secure', 'mock_location', '1']).once()577 .returns('');578 await helpers.setMockLocationApp(adb, 'io.appium.settings');579 mocks.adb.verify();580 });581 it('should enable mock location for api level 23 and above', async function () {582 mocks.adb.expects('getApiLevel').returns(B.resolve(23));583 mocks.adb.expects('shell').withExactArgs(['appops', 'set', 'io.appium.settings', 'android:mock_location', 'allow']).once()584 .returns('');585 await helpers.setMockLocationApp(adb, 'io.appium.settings');586 mocks.adb.verify();587 });588 }));589 describe('pushStrings', withMocks({adb, fs}, (mocks) => {590 it('should return {} because of no app, no package and no app in the target device', async function () {591 const opts = {tmpDir: '/tmp_dir', appPackage: 'pkg'};592 mocks.adb.expects('rimraf').withExactArgs(`${REMOTE_TEMP_PATH}/strings.json`).once();593 mocks.adb.expects('pullApk').withExactArgs(opts.appPackage, opts.tmpDir)594 .throws(`adb: error: remote object ${opts.appPackage} does not exist`);595 (await helpers.pushStrings('en', adb, opts)).should.be.deep.equal({});596 mocks.adb.verify();597 mocks.fs.verify();598 });599 it('should extracts string.xml and converts it to string.json and pushes it', async function () {600 const opts = {app: 'app', tmpDir: '/tmp_dir', appPackage: 'pkg'};601 mocks.adb.expects('rimraf').withExactArgs(`${REMOTE_TEMP_PATH}/strings.json`).once();602 mocks.fs.expects('exists').withExactArgs(opts.app).returns(true);603 mocks.fs.expects('rimraf').once();604 mocks.adb.expects('extractStringsFromApk').withArgs(opts.app, 'en')605 .returns({apkStrings: {id: 'string'}, localPath: 'local_path'});606 mocks.adb.expects('push').withExactArgs('local_path', REMOTE_TEMP_PATH).once();607 (await helpers.pushStrings('en', adb, opts)).should.be.deep.equal({id: 'string'});608 mocks.adb.verify();609 });610 it('should delete remote strings.json if app is not present', async function () {611 const opts = {app: 'app', tmpDir: '/tmp_dir', appPackage: 'pkg'};612 mocks.adb.expects('rimraf').withExactArgs(`${REMOTE_TEMP_PATH}/strings.json`).once();613 mocks.fs.expects('exists').withExactArgs(opts.app).returns(false);614 (await helpers.pushStrings('en', adb, opts)).should.be.deep.equal({});615 mocks.adb.verify();616 mocks.fs.verify();617 });618 it('should push an empty json object if app does not have strings.xml', async function () {619 const opts = {app: 'app', tmpDir: '/tmp_dir', appPackage: 'pkg'};620 mocks.adb.expects('rimraf').withExactArgs(`${REMOTE_TEMP_PATH}/strings.json`).once();621 mocks.fs.expects('exists').withExactArgs(opts.app).returns(true);622 mocks.fs.expects('rimraf').once();623 mocks.adb.expects('extractStringsFromApk').throws();624 mocks.adb.expects('shell').withExactArgs('echo', [`'{}' > ${REMOTE_TEMP_PATH}/strings.json`]);625 (await helpers.pushStrings('en', adb, opts)).should.be.deep.equal({});626 mocks.adb.verify();627 mocks.fs.verify();628 });629 }));630 describe('unlock', withMocks({adb, helpers, unlocker}, (mocks) => {631 it('should return if screen is already unlocked', async function () {632 mocks.adb.expects('isScreenLocked').withExactArgs().once()633 .returns(false);634 mocks.adb.expects('getApiLevel').never();635 mocks.adb.expects('startApp').never();636 await helpers.unlock(helpers, adb, {});637 mocks.adb.verify();638 });639 it('should start unlock app', async function () {640 mocks.adb.expects('isScreenLocked').onCall(0).returns(true);641 mocks.adb.expects('shell').once().returns('');642 await helpers.unlock(helpers, adb, {});643 mocks.adb.verify();644 mocks.helpers.verify();645 });646 it('should raise an error on undefined unlockKey when unlockType is defined', async function () {647 mocks.adb.expects('isScreenLocked').once().returns(true);648 mocks.unlocker.expects('isValidKey').once();649 await helpers.unlock(helpers, adb, {unlockType: 'pin'}).should.be.rejectedWith('unlockKey');650 mocks.adb.verify();651 mocks.unlocker.verify();652 mocks.helpers.verify();653 });654 it('should call pinUnlock if unlockType is pin', async function () {655 mocks.adb.expects('isScreenLocked').onCall(0).returns(true);656 mocks.adb.expects('isScreenLocked').returns(false);657 mocks.unlocker.expects('pinUnlock').once();658 await helpers.unlock(helpers, adb, {unlockType: 'pin', unlockKey: '1111'});659 mocks.adb.verify();660 mocks.helpers.verify();661 });662 it('should call passwordUnlock if unlockType is password', async function () {663 mocks.adb.expects('isScreenLocked').onCall(0).returns(true);664 mocks.adb.expects('isScreenLocked').returns(false);665 mocks.unlocker.expects('passwordUnlock').once();666 await helpers.unlock(helpers, adb, {unlockType: 'password', unlockKey: 'appium'});667 mocks.adb.verify();668 mocks.helpers.verify();669 });670 it('should call patternUnlock if unlockType is pattern', async function () {671 mocks.adb.expects('isScreenLocked').onCall(0).returns(true);672 mocks.adb.expects('isScreenLocked').returns(false);673 mocks.unlocker.expects('patternUnlock').once();674 await helpers.unlock(helpers, adb, {unlockType: 'pattern', unlockKey: '123456789'});675 mocks.adb.verify();676 mocks.helpers.verify();677 });678 it('should call fingerprintUnlock if unlockType is fingerprint', async function () {679 mocks.adb.expects('isScreenLocked').onCall(0).returns(true);680 mocks.adb.expects('isScreenLocked').returns(false);681 mocks.unlocker.expects('fingerprintUnlock').once();682 await helpers.unlock(helpers, adb, {unlockType: 'fingerprint', unlockKey: '1111'});683 mocks.adb.verify();684 mocks.unlocker.verify();685 });686 it('should throw an error is api is lower than 23 and trying to use fingerprintUnlock', async function () {687 mocks.adb.expects('isScreenLocked').onCall(0).returns(true);688 mocks.adb.expects('isScreenLocked').returns(false);689 mocks.adb.expects('getApiLevel').once().returns(21);690 await helpers.unlock(helpers, adb, {unlockType: 'fingerprint', unlockKey: '1111'}).should.eventually691 .be.rejectedWith('Fingerprint');692 mocks.helpers.verify();693 });694 }));695 describe('initDevice', withMocks({helpers, adb}, (mocks) => {696 it('should init device', async function () {697 const opts = {language: 'en', locale: 'us', localeScript: 'Script'};698 mocks.adb.expects('waitForDevice').once();699 mocks.adb.expects('startLogcat').once();700 mocks.helpers.expects('pushSettingsApp').once();701 mocks.helpers.expects('ensureDeviceLocale').withExactArgs(adb, opts.language, opts.locale, opts.localeScript).once();702 mocks.helpers.expects('setMockLocationApp').withExactArgs(adb, 'io.appium.settings').once();703 await helpers.initDevice(adb, opts);704 mocks.helpers.verify();705 mocks.adb.verify();706 });707 it('should init device without locale and language', async function () {708 const opts = {};709 mocks.adb.expects('waitForDevice').once();710 mocks.adb.expects('startLogcat').once();711 mocks.helpers.expects('pushSettingsApp').once();712 mocks.helpers.expects('ensureDeviceLocale').never();713 mocks.helpers.expects('setMockLocationApp').withExactArgs(adb, 'io.appium.settings').once();714 await helpers.initDevice(adb, opts);715 mocks.helpers.verify();716 mocks.adb.verify();717 });718 it('should init device with either locale or language', async function () {719 const opts = {language: 'en'};720 mocks.adb.expects('waitForDevice').once();721 mocks.adb.expects('startLogcat').once();722 mocks.helpers.expects('pushSettingsApp').once();723 mocks.helpers.expects('ensureDeviceLocale').withExactArgs(adb, opts.language, opts.locale, opts.localeScript).once();724 mocks.helpers.expects('setMockLocationApp').withExactArgs(adb, 'io.appium.settings').once();725 await helpers.initDevice(adb, opts);726 mocks.helpers.verify();727 mocks.adb.verify();728 });729 it('should not install mock location on emulator', async function () {730 const opts = {avd: 'avd'};731 mocks.adb.expects('waitForDevice').once();732 mocks.adb.expects('startLogcat').once();733 mocks.helpers.expects('pushSettingsApp').once();734 mocks.helpers.expects('ensureDeviceLocale').never();735 mocks.helpers.expects('setMockLocationApp').never();736 await helpers.initDevice(adb, opts);737 mocks.helpers.verify();738 mocks.adb.verify();739 });740 it('should return defaultIME if unicodeKeyboard is setted to true', async function () {741 const opts = {unicodeKeyboard: true};742 mocks.adb.expects('waitForDevice').once();743 mocks.adb.expects('startLogcat').once();744 mocks.helpers.expects('pushSettingsApp').once();745 mocks.helpers.expects('ensureDeviceLocale').never();746 mocks.helpers.expects('setMockLocationApp').once();747 mocks.helpers.expects('initUnicodeKeyboard').withExactArgs(adb).once().returns('defaultIME');748 await helpers.initDevice(adb, opts).should.become('defaultIME');749 mocks.helpers.verify();750 mocks.adb.verify();751 });752 it('should return undefined if unicodeKeyboard is setted to false', async function () {753 const opts = {unicodeKeyboard: false};754 mocks.adb.expects('waitForDevice').once();755 mocks.adb.expects('startLogcat').once();756 mocks.helpers.expects('pushSettingsApp').once();757 mocks.helpers.expects('ensureDeviceLocale').never();758 mocks.helpers.expects('setMockLocationApp').once();759 mocks.helpers.expects('initUnicodeKeyboard').never();760 should.not.exist(await helpers.initDevice(adb, opts));761 mocks.helpers.verify();762 mocks.adb.verify();763 });764 it('should not push unlock app if unlockType is defined', async function () {765 const opts = {unlockType: 'unlock_type'};766 mocks.adb.expects('waitForDevice').once();767 mocks.adb.expects('startLogcat').once();768 mocks.helpers.expects('pushSettingsApp').once();769 mocks.helpers.expects('ensureDeviceLocale').never();770 mocks.helpers.expects('setMockLocationApp').once();771 mocks.helpers.expects('initUnicodeKeyboard').never();772 await helpers.initDevice(adb, opts);773 mocks.helpers.verify();774 mocks.adb.verify();775 });776 it('should init device without starting logcat', async function () {777 const opts = { skipLogcatCapture: true };778 mocks.adb.expects('waitForDevice').once();779 mocks.adb.expects('startLogcat').never();780 mocks.helpers.expects('pushSettingsApp').once();781 mocks.helpers.expects('ensureDeviceLocale').never();782 mocks.helpers.expects('setMockLocationApp').withExactArgs(adb, 'io.appium.settings').once();783 await helpers.initDevice(adb, opts);784 mocks.helpers.verify();785 mocks.adb.verify();786 });787 }));788 describe('removeNullProperties', function () {789 it('should ignore null properties', function () {790 let test = {foo: null, bar: true};791 helpers.removeNullProperties(test);792 _.keys(test).length.should.equal(1);793 });794 it('should ignore undefined properties', function () {795 let test = {foo: undefined, bar: true};796 helpers.removeNullProperties(test);797 _.keys(test).length.should.equal(1);798 });799 it('should not ignore falsy properties like 0 and false', function () {800 let test = {foo: false, bar: true, zero: 0};801 helpers.removeNullProperties(test);802 _.keys(test).length.should.equal(3);803 });804 });805 describe('truncateDecimals', function () {806 it('should use floor when number is positive', function () {807 helpers.truncateDecimals(12.345, 2).should.equal(12.34);808 });809 it('should use ceil when number is negative', function () {810 helpers.truncateDecimals(-12.345, 2).should.equal(-12.34);811 });812 });813 describe('getChromePkg', function () {814 it('should return pakage for chromium', function () {815 helpers.getChromePkg('chromium').should.deep.equal(816 {pkg: 'org.chromium.chrome.shell', activity: '.ChromeShellActivity'});817 });818 it('should return pakage for chromebeta', function () {819 helpers.getChromePkg('chromebeta').should.deep.equal(820 {pkg: 'com.chrome.beta', activity: 'com.google.android.apps.chrome.Main'});821 });822 it('should return pakage for browser', function () {823 helpers.getChromePkg('browser').should.deep.equal(824 {pkg: 'com.android.browser', activity: 'com.android.browser.BrowserActivity'});825 });826 it('should return pakage for chromium-browser', function () {827 helpers.getChromePkg('chromium-browser').should.deep.equal(828 {pkg: 'org.chromium.chrome', activity: 'com.google.android.apps.chrome.Main'});829 });830 it('should return pakage for chromium-webview', function () {831 helpers.getChromePkg('chromium-webview').should.deep.equal(832 {pkg: 'org.chromium.webview_shell', activity: 'org.chromium.webview_shell.WebViewBrowserActivity'});833 });834 });835 describe('#parseArray', function () {836 it('should parse array string to array', function () {837 helpers.parseArray('["a", "b", "c"]').should.eql(['a', 'b', 'c']);838 });839 it('should parse a simple string to one item array', function () {840 helpers.parseArray('abc').should.eql(['abc']);841 });842 });...

Full Screen

Full Screen

apk-utils-specs.js

Source:apk-utils-specs.js Github

copy

Full Screen

...562 name: pkgId563 });564 mocks.adb.expects('isAppInstalled').withExactArgs(pkgId).once().returns(false);565 mocks.adb.expects('install').withArgs(apkPath, false).once().returns(true);566 await adb.installOrUpgrade(apkPath);567 mocks.adb.verify();568 });569 it('should return if the same package version is already installed', async () => {570 mocks.adb.expects('getApkInfo').withExactArgs(apkPath).once().returns({571 versionCode: 1572 });573 mocks.adb.expects('getPackageInfo').once().returns({574 versionCode: 1575 });576 mocks.adb.expects('isAppInstalled').withExactArgs(pkgId).once().returns(true);577 await adb.installOrUpgrade(apkPath, pkgId);578 mocks.adb.verify();579 });580 it('should return if newer package version is already installed', async () => {581 mocks.adb.expects('getApkInfo').withExactArgs(apkPath).once().returns({582 name: pkgId,583 versionCode: 1584 });585 mocks.adb.expects('getPackageInfo').once().returns({586 versionCode: 2587 });588 mocks.adb.expects('isAppInstalled').withExactArgs(pkgId).once().returns(true);589 await adb.installOrUpgrade(apkPath);590 mocks.adb.verify();591 });592 it('should not throw an error if apk version code cannot be read', async () => {593 mocks.adb.expects('getApkInfo').withExactArgs(apkPath).once().returns({594 name: pkgId595 });596 mocks.adb.expects('getPackageInfo').once().returns({597 versionCode: 2598 });599 mocks.adb.expects('isAppInstalled').withExactArgs(pkgId).once().returns(true);600 await adb.installOrUpgrade(apkPath);601 mocks.adb.verify();602 });603 it('should not throw an error if pkg version code cannot be read', async () => {604 mocks.adb.expects('getApkInfo').withExactArgs(apkPath).once().returns({605 name: pkgId,606 versionCode: 1607 });608 mocks.adb.expects('getPackageInfo').once().returns({});609 mocks.adb.expects('isAppInstalled').withExactArgs(pkgId).once().returns(true);610 await adb.installOrUpgrade(apkPath);611 mocks.adb.verify();612 });613 it('should not throw an error if pkg id cannot be read', async () => {614 mocks.adb.expects('getApkInfo').withExactArgs(apkPath).once().returns({});615 await adb.installOrUpgrade(apkPath);616 mocks.adb.verify();617 });618 it('should perform upgrade if older package version is installed', async () => {619 mocks.adb.expects('getApkInfo').withExactArgs(apkPath).once().returns({620 name: pkgId,621 versionCode: 2622 });623 mocks.adb.expects('getPackageInfo').once().returns({624 versionCode: 1625 });626 mocks.adb.expects('isAppInstalled').withExactArgs(pkgId).once().returns(true);627 mocks.adb.expects('install').withArgs(apkPath, true).once().returns(true);628 await adb.installOrUpgrade(apkPath);629 mocks.adb.verify();630 });631 it('should uninstall and re-install if older package version is installed and upgrade fails', async () => {632 mocks.adb.expects('getApkInfo').withExactArgs(apkPath).once().returns({633 name: pkgId,634 versionCode: 2635 });636 mocks.adb.expects('getPackageInfo').once().returns({637 versionCode: 1638 });639 mocks.adb.expects('isAppInstalled').withExactArgs(pkgId).once().returns(true);640 mocks.adb.expects('install').withArgs(apkPath, true).once().throws();641 mocks.adb.expects('uninstallApk').withExactArgs(pkgId).once().returns(true);642 mocks.adb.expects('install').withArgs(apkPath, false).once().returns(true);643 await adb.installOrUpgrade(apkPath);644 mocks.adb.verify();645 });646 it('should throw an exception if upgrade and reinstall fail', async () => {647 mocks.adb.expects('getApkInfo').withExactArgs(apkPath).once().returns({648 name: pkgId,649 versionCode: 2650 });651 mocks.adb.expects('getPackageInfo').once().returns({652 versionCode: 1653 });654 mocks.adb.expects('isAppInstalled').withExactArgs(pkgId).once().returns(true);655 mocks.adb.expects('uninstallApk').withExactArgs(pkgId).once().returns(true);656 mocks.adb.expects('install').withArgs(apkPath).twice().throws();657 let isExceptionThrown = false;658 try {659 await adb.installOrUpgrade(apkPath);660 } catch (e) {661 isExceptionThrown = true;662 }663 isExceptionThrown.should.be.true;664 mocks.adb.verify();665 });666 it('should throw an exception if upgrade and uninstall fail', async () => {667 mocks.adb.expects('getApkInfo').withExactArgs(apkPath).once().returns({668 name: pkgId,669 versionCode: 2670 });671 mocks.adb.expects('getPackageInfo').once().returns({672 versionCode: 1673 });674 mocks.adb.expects('isAppInstalled').withExactArgs(pkgId).once().returns(true);675 mocks.adb.expects('uninstallApk').withExactArgs(pkgId).once().returns(false);676 mocks.adb.expects('install').withArgs(apkPath, true).once().throws();677 let isExceptionThrown = false;678 try {679 await adb.installOrUpgrade(apkPath);680 } catch (e) {681 isExceptionThrown = true;682 }683 isExceptionThrown.should.be.true;684 mocks.adb.verify();685 });686 }));...

Full Screen

Full Screen

android-helpers.js

Source:android-helpers.js Github

copy

Full Screen

...319 return;320 }321 // There is no need to reset the newly installed app322 const shouldPerformFastReset = fastReset && await adb.isAppInstalled(appPackage);323 await adb.installOrUpgrade(app, appPackage, {324 grantPermissions: autoGrantPermissions,325 timeout: androidInstallTimeout,326 allowTestPackages,327 });328 if (shouldPerformFastReset) {329 logger.info(`Performing fast reset on '${appPackage}'`);330 await this.resetApp(adb, opts);331 }332};333/**334 * Installs an array of apks335 * @param {ADB} adb Instance of Appium ADB object336 * @param {Object} opts Opts defined in driver.js337 */338helpers.installOtherApks = async function (otherApps, adb, opts) {339 let {340 androidInstallTimeout = PACKAGE_INSTALL_TIMEOUT,341 autoGrantPermissions,342 allowTestPackages343 } = opts;344 // Install all of the APK's asynchronously345 await B.all(otherApps.map((otherApp) => {346 logger.debug(`Installing app: ${otherApp}`);347 return adb.installOrUpgrade(otherApp, null, {348 grantPermissions: autoGrantPermissions,349 timeout: androidInstallTimeout,350 allowTestPackages,351 });352 }));353};354helpers.initUnicodeKeyboard = async function (adb) {355 logger.debug('Enabling Unicode keyboard support');356 logger.debug("Pushing unicode ime to device...");357 try {358// await adb.install(unicodeIMEPath, {replace: false});//leung359 } catch (err) {360 logger.info(`Performing full reinstall of ${UNICODE_IME_PKG_ID} as a possible fix for: ${err.message}`);361// await adb.uninstallApk(UNICODE_IME_PKG_ID);362// await adb.install(unicodeIMEPath, {replace: false});363 }364 // get the default IME so we can return back to it later if we want365 let defaultIME = await adb.defaultIME();366 logger.debug(`Unsetting previous IME ${defaultIME}`);367 const appiumIME = `${UNICODE_IME_PKG_ID}/.UnicodeIME`;368 logger.debug(`Setting IME to '${appiumIME}'`);369 await adb.enableIME(appiumIME);370 await adb.setIME(appiumIME);371 return defaultIME;372};373helpers.setMockLocationApp = async function (adb, app) {374 try {375 if (await adb.getApiLevel() < 23) {376 await adb.shell(['settings', 'put', 'secure', 'mock_location', '1']);377 } else {378 await adb.shell(['appops', 'set', app, 'android:mock_location', 'allow']);379 }380 } catch (err) {381 logger.warn(`Unable to set mock location for app '${app}': ${err.message}`);382 }383};384helpers.installHelperApp = async function (adb, apkPath, packageId, appName) {385 try {386 await adb.installOrUpgrade(apkPath, packageId, {grantPermissions: true});387 } catch (err) {388 logger.warn(`Ignored error while installing Appium ${appName} helper: ` +389 `'${err.message}'. Manually uninstalling the application ` +390 `with package id '${packageId}' may help. Expect some Appium ` +391 `features may not work as expected unless this problem is ` +392 `fixed.`);393 }394};395helpers.pushSettingsApp = async function (adb, throwError = false) {396 logger.debug("Pushing settings apk to device...");397 await helpers.installHelperApp(adb, settingsApkPath, SETTINGS_HELPER_PKG_ID, 'Settings');398 // Reinstall will stop the settings helper process anyway, so399 // there is no need to continue if the application is still running400 if (await adb.processExists(SETTINGS_HELPER_PKG_ID)) {...

Full Screen

Full Screen

ah1.js

Source:ah1.js Github

copy

Full Screen

...319 return;320 }321 // There is no need to reset the newly installed app322 const shouldPerformFastReset = fastReset && await adb.isAppInstalled(appPackage);323 await adb.installOrUpgrade(app, appPackage, {324 grantPermissions: autoGrantPermissions,325 timeout: androidInstallTimeout,326 allowTestPackages,327 });328 if (shouldPerformFastReset) {329 logger.info(`Performing fast reset on '${appPackage}'`);330 await this.resetApp(adb, opts);331 }332};333/**334 * Installs an array of apks335 * @param {ADB} adb Instance of Appium ADB object336 * @param {Object} opts Opts defined in driver.js337 */338helpers.installOtherApks = async function (otherApps, adb, opts) {339 let {340 androidInstallTimeout = PACKAGE_INSTALL_TIMEOUT,341 autoGrantPermissions,342 allowTestPackages343 } = opts;344 // Install all of the APK's asynchronously345 await B.all(otherApps.map((otherApp) => {346 logger.debug(`Installing app: ${otherApp}`);347 return adb.installOrUpgrade(otherApp, null, {348 grantPermissions: autoGrantPermissions,349 timeout: androidInstallTimeout,350 allowTestPackages,351 });352 }));353};354helpers.initUnicodeKeyboard = async function (adb) {355 logger.debug('Enabling Unicode keyboard support');356 logger.debug("Pushing unicode ime to device...");357 try {358 await adb.install(unicodeIMEPath, {replace: false});359 } catch (err) {360 logger.info(`Performing full reinstall of ${UNICODE_IME_PKG_ID} as a possible fix for: ${err.message}`);361 await adb.uninstallApk(UNICODE_IME_PKG_ID);362 await adb.install(unicodeIMEPath, {replace: false});363 }364 // get the default IME so we can return back to it later if we want365 let defaultIME = await adb.defaultIME();366 logger.debug(`Unsetting previous IME ${defaultIME}`);367 const appiumIME = `${UNICODE_IME_PKG_ID}/.UnicodeIME`;368 logger.debug(`Setting IME to '${appiumIME}'`);369 await adb.enableIME(appiumIME);370 await adb.setIME(appiumIME);371 return defaultIME;372};373helpers.setMockLocationApp = async function (adb, app) {374 try {375 if (await adb.getApiLevel() < 23) {376 await adb.shell(['settings', 'put', 'secure', 'mock_location', '1']);377 } else {378 await adb.shell(['appops', 'set', app, 'android:mock_location', 'allow']);379 }380 } catch (err) {381 logger.warn(`Unable to set mock location for app '${app}': ${err.message}`);382 }383};384helpers.installHelperApp = async function (adb, apkPath, packageId, appName) {385 try {386 await adb.installOrUpgrade(apkPath, packageId, {grantPermissions: true});387 } catch (err) {388 logger.warn(`Ignored error while installing Appium ${appName} helper: ` +389 `'${err.message}'. Manually uninstalling the application ` +390 `with package id '${packageId}' may help. Expect some Appium ` +391 `features may not work as expected unless this problem is ` +392 `fixed.`);393 }394};395helpers.pushSettingsApp = async function (adb, throwError = false) {396 logger.debug("Pushing settings apk to device...");397 await helpers.installHelperApp(adb, settingsApkPath, SETTINGS_HELPER_PKG_ID, 'Settings');398 // Reinstall will stop the settings helper process anyway, so399 // there is no need to continue if the application is still running400 if (await adb.processExists(SETTINGS_HELPER_PKG_ID)) {...

Full Screen

Full Screen

uiautomator2.js

Source:uiautomator2.js Github

copy

Full Screen

...55 }56 }57 }58 for (const {appPath, appId} of packagesInfo) {59 await this.adb.installOrUpgrade(appPath, appId, {60 timeout: installTimeout,61 });62 }63 let retries = getRetries('Server install', installTimeout, SERVER_INSTALL_RETRIES);64 logger.debug(`Waiting up to ${retries * 1000}ms for instrumentation '${INSTRUMENTATION_TARGET}' to be available`);65 let output;66 try {67 await retryInterval(retries, 1000, async () => {68 output = await this.adb.shell(['pm', 'list', 'instrumentation']);69 if (output.indexOf('Could not access the Package Manager') !== -1) {70 let err = new Error(`Problem running package manager: ${output}`);71 output = null; // remove output, so it is not printed below72 throw err;73 } else if (output.indexOf(INSTRUMENTATION_TARGET) === -1) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var wd = require('wd');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6chai.should();7chaiAsPromised.transferPromiseness = wd.transferPromiseness;8var desired = {9 app: path.resolve('test.apk'),10};11var driver = wd.promiseChainRemote('localhost', 4723);12 .init(desired)13 .then(function() { return driver.installOrUpgrade(path.resolve('test.apk')); })14 .then(function() { return driver.startActivity('com.example.test', 'com.example.test.MainActivity'); })15 .then(function() { return driver.quit(); })16 .done();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var AndroidDriver = require('appium-android-driver');4var desiredCaps = {5};6var driver = wd.promiseChainRemote("localhost", 4723);7driver.init(desiredCaps).then(function () {8 return driver.adb.installOrUpgrade("/Users/XXXXXX/Desktop/Android/app-debug.apk", "com.abc");9}).then(function () {10 console.log("Success");11});12helpers.installOrUpgrade = async function (adb, apk, pkg) {13 let isAppInstalled = await adb.isAppInstalled(pkg);14 if (isAppInstalled) {15 log.info("App is already installed, resetting app");16 await adb.forceStop(pkg);17 await adb.clear(pkg);18 } else {19 log.info("Installing app");20 await adb.install(apk, true);21 }22};

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var path = require('path');3var assert = require('assert');4var os = require('os');5var fs = require('fs');6var AdmZip = require('adm-zip');7var unzip = require('unzip');8var appPath = path.resolve(__dirname, 'ApiDemos-debug.apk');9var appPath2 = path.resolve(__dirname, 'ApiDemos-debug2.apk');10var appPath3 = path.resolve(__dirname, 'ApiDemos-debug3.apk');11var appPath4 = path.resolve(__dirname, 'ApiDemos-debug4.apk');12var appPath5 = path.resolve(__dirname, 'ApiDemos-debug5.apk');13var appPath6 = path.resolve(__dirname, 'ApiDemos-debug6.apk');14var appPath7 = path.resolve(__dirname, 'ApiDemos-debug7.apk');15var appPath8 = path.resolve(__dirname, 'ApiDemos-debug8.apk');16var appPath9 = path.resolve(__dirname, 'ApiDemos-debug9.apk');17var appPath10 = path.resolve(__dirname, 'ApiDemos-debug10.apk');18var appPath11 = path.resolve(__dirname, 'ApiDemos-debug11.apk');19var appPath12 = path.resolve(__dirname, 'ApiDemos-debug12.apk');20var appPath13 = path.resolve(__dirname, 'ApiDemos-debug13.apk');21var appPath14 = path.resolve(__dirname, 'ApiDemos-debug14.apk');22var appPath15 = path.resolve(__dirname, 'ApiDemos-debug15.apk');23var appPath16 = path.resolve(__dirname, 'ApiDemos-debug16.apk');24var appPath17 = path.resolve(__dirname, 'ApiDemos-debug17.apk');25var appPath18 = path.resolve(__dirname, 'ApiDemos-debug18.apk');26var appPath19 = path.resolve(__dirname, 'ApiDemos-debug19.apk');27var appPath20 = path.resolve(__dirname, 'ApiDemos-debug20.apk');28var appPath21 = path.resolve(__dirname, 'ApiDemos-debug21.apk');29var appPath22 = path.resolve(__dirname, 'ApiDemos-debug22

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require('appium-adb').ADB;2var appium = require('appium-android-driver');3var driver = new appium.AndroidDriver();4var adb = new adb();5var apkPath = '/path/to/apk/file';6driver.adb.installOrUpgrade(apkPath).then(function(){7 console.log('apk installed or upgraded successfully');8});9var appium = require('appium-android-driver');10var driver = new appium.AndroidDriver();

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require('appium-adb');2var adb = new ADB();3adb.installOrUpgrade('/Users/sudheer/Desktop/ContactManager.apk', function(err, result) {4 if (err) {5 console.log(err);6 } else {7 console.log(result);8 }9});10at ChildProcess.exithandler (child_process.js:202:12)11at ChildProcess.emit (events.js:98:17)12at maybeClose (child_process.js:766:16)13at Process.ChildProcess._handle.onexit (child_process.js:833:5)14at ChildProcess.exithandler (child_process.js:202:12)15at ChildProcess.emit (events.js:98:17)16at maybeClose (child_process.js:766:16)17at Process.ChildProcess._handle.onexit (child_process.js:833:5)18at ChildProcess.exithandler (child_process.js:202:12)19at ChildProcess.emit (events.js:98:17)20at maybeClose (child_process.js:766:16)21at Process.ChildProcess._handle.onexit (child_process.js:833:5

Full Screen

Using AI Code Generation

copy

Full Screen

1var adb = require('appium-adb').ADB.createADB();2var app = "d:/projects/Android/app-debug.apk";3var pkg = "com.example.android.apis";4var activity = "com.example.android.apis.ApiDemos";5adb.installOrUpgrade(app, pkg, activity, function(err) {6 if (err) {7 console.log(err);8 } else {9 console.log("App is installed or upgraded");10 }11});12adb.installOrUpgrade(app, pkg, activity, 5554, function(err) {13 if (err) {14 console.log(err);15 } else {16 console.log("App is installed or upgraded");17 }18});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var path = require('path');4var chai = require('chai');5var chaiAsPromised = require('chai-as-promised');6var should = chai.should();7var expect = chai.expect;8chai.use(chaiAsPromised);9var desiredCaps = {10 app: path.resolve(__dirname, 'ApiDemos-debug.apk'),11};12var driver = wd.promiseChainRemote('localhost', 4723);13driver.init(desiredCaps)14 .then(function () {15 return driver.installApp(path.resolve(__dirname, 'ApiDemos-debug.apk'));16 })17 .then(function () {18 return driver.installApp(path.resolve(__dirname, 'ApiDemos-debug.apk'));19 })20 .then(function () {21 return driver.removeApp('io.appium.android.apis');22 })23 .then(function () {24 return driver.quit();25 })26 .done();

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