Best JavaScript code snippet using appium-android-driver
android-helpers.js
Source:android-helpers.js
...354 category: "android.intent.category.LAUNCHER",355 flags: "0x10200000",356 stopApp: false357 };358 await adb.startApp(startOpts);359 }360 } catch (err) {361 logger.warn(`Failed to launch settings app: ${err.message}`);362 if (throwError) {363 throw err;364 }365 }366};367helpers.pushUnlock = async function (adb) {368 if (!(await adb.isAppInstalled(SETTINGS_HELPER_PKG_ID))) { // never update, added by shawn369 logger.debug("Pushing unlock helper app to device...");370 await helpers.installHelperApp(adb, unlockApkPath, UNLOCK_HELPER_PKG_ID, 'Unlock');371 }372};373// pushStrings method extracts string.xml and converts it to string.json and pushes374// it to /data/local/tmp/string.json on for use of bootstrap375// if app is not present to extract string.xml it deletes remote strings.json376// if app does not have strings.xml we push an empty json object to remote377helpers.pushStrings = async function (language, adb, opts) {378 let remotePath = '/data/local/tmp';379 let stringsJson = 'strings.json';380 let stringsTmpDir = path.resolve(opts.tmpDir, opts.appPackage);381 try {382 logger.debug('Extracting strings from apk', opts.app, language, stringsTmpDir);383 let {apkStrings, localPath} = await adb.extractStringsFromApk(384 opts.app, language, stringsTmpDir);385 await adb.push(localPath, remotePath);386 return apkStrings;387 } catch (err) {388 if (!(await fs.exists(opts.app))) {389 // delete remote string.json if present390 await adb.rimraf(`${remotePath}/${stringsJson}`);391 } else {392 logger.warn("Could not get strings, continuing anyway");393 let remoteFile = `${remotePath}/${stringsJson}`;394 await adb.shell('echo', [`'{}' > ${remoteFile}`]);395 }396 }397 return {};398};399helpers.unlockWithUIAutomation = async function (driver, adb, unlockCapabilities) {400 let unlockType = unlockCapabilities.unlockType;401 if (!unlocker.isValidUnlockType(unlockType)) {402 throw new Error(`Invalid unlock type ${unlockType}`);403 }404 let unlockKey = unlockCapabilities.unlockKey;405 if (!unlocker.isValidKey(unlockType, unlockKey)) {406 throw new Error(`Missing unlockKey ${unlockKey} capability for unlockType ${unlockType}`);407 }408 const unlockMethod = {409 [PIN_UNLOCK]: unlocker.pinUnlock,410 [PASSWORD_UNLOCK]: unlocker.passwordUnlock,411 [PATTERN_UNLOCK]: unlocker.patternUnlock,412 [FINGERPRINT_UNLOCK]: unlocker.fingerprintUnlock413 }[unlockType];414 await unlockMethod(adb, driver, unlockCapabilities);415};416helpers.unlockWithHelperApp = async function (adb) {417 logger.info("Unlocking screen");418 await adb.forceStop(UNLOCK_HELPER_PKG_ID);419 // then start the app twice, as once is flakey420 let startOpts = {421 pkg: UNLOCK_HELPER_PKG_ID,422 activity: UNLOCK_HELPER_PKG_ACTIVITY,423 action: "android.intent.action.MAIN",424 category: "android.intent.category.LAUNCHER",425 flags: "0x10200000",426 stopApp: false427 };428 await adb.startApp(startOpts);429 await adb.startApp(startOpts);430};431helpers.unlock = async function (driver, adb, capabilities) {432 if (!(await adb.isScreenLocked())) {433 logger.info("Screen already unlocked, doing nothing");434 return;435 }436 if (_.isUndefined(capabilities.unlockType)) {437 // Leave the old unlock to avoid breaking existing tests438 await retryInterval(10, 1000, async () => {439 logger.debug("Screen is locked, trying to unlock");440 // check if it worked, twice441 logger.warn("Using app unlock, this is going to be deprecated!");442 await helpers.unlockWithHelperApp(adb);443 await helpers.verifyUnlock(adb);...
general-specs.js
Source:general-specs.js
1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import sinon from 'sinon';4import AndroidDriver from '../../..';5import { parseSurfaceLine, parseWindows } from '../../../lib/commands/general';6import helpers from '../../../lib/android-helpers';7import { withMocks } from 'appium-test-support';8import { fs } from 'appium-support';9import Bootstrap from 'appium-android-bootstrap';10import B from 'bluebird';11import ADB from 'appium-adb';12chai.should();13chai.use(chaiAsPromised);14let driver;15let sandbox = sinon.sandbox.create();16let expect = chai.expect;17describe('General', () => {18 beforeEach(() => {19 driver = new AndroidDriver();20 driver.bootstrap = new Bootstrap();21 driver.adb = new ADB();22 driver.caps = {};23 driver.opts = {};24 });25 afterEach(() => {26 sandbox.restore();27 });28 describe('keys', () => {29 it('should send keys via setText bootstrap command', async () => {30 sandbox.stub(driver.bootstrap, 'sendAction');31 driver.opts.unicodeKeyboard = true;32 await driver.keys('keys');33 driver.bootstrap.sendAction34 .calledWithExactly('setText',35 {text: 'keys', replace: false, unicodeKeyboard: true})36 .should.be.true;37 });38 it('should join keys if keys is array', async () => {39 sandbox.stub(driver.bootstrap, 'sendAction');40 driver.opts.unicodeKeyboard = false;41 await driver.keys(['k', 'e', 'y', 's']);42 driver.bootstrap.sendAction43 .calledWithExactly('setText', {text: 'keys', replace: false})44 .should.be.true;45 });46 });47 describe('getDeviceTime', () => {48 it('should return device time', async () => {49 sandbox.stub(driver.adb, 'shell');50 driver.adb.shell.returns(' 11:12 ');51 await driver.getDeviceTime().should.become('11:12');52 driver.adb.shell.calledWithExactly(['date']).should.be.true;53 });54 it('should thorws error if shell command failed', async () => {55 sandbox.stub(driver.adb, 'shell').throws();56 await driver.getDeviceTime().should.be.rejectedWith('Could not capture');57 });58 });59 describe('getPageSource', () => {60 it('should return page source', async () => {61 sandbox.stub(driver.bootstrap, 'sendAction').withArgs('source').returns('sources');62 await driver.getPageSource().should.be.equal('sources');63 });64 });65 describe('back', () => {66 it('should press back', async () => {67 sandbox.stub(driver.bootstrap, 'sendAction');68 await driver.back();69 driver.bootstrap.sendAction.calledWithExactly('pressBack').should.be.true;70 });71 });72 describe('isKeyboardShown', () => {73 it('should return true if the keyboard is shown', async () => {74 driver.adb.isSoftKeyboardPresent = () => { return {isKeyboardShown: true, canCloseKeyboard: true}; };75 (await driver.isKeyboardShown()).should.equal(true);76 });77 it('should return false if the keyboard is not shown', async () => {78 driver.adb.isSoftKeyboardPresent = () => { return {isKeyboardShown: false, canCloseKeyboard: true}; };79 (await driver.isKeyboardShown()).should.equal(false);80 });81 });82 describe('hideKeyboard', () => {83 it('should hide keyboard via back command', async () => {84 sandbox.stub(driver, 'back');85 driver.adb.isSoftKeyboardPresent = () => { return {isKeyboardShown: true, canCloseKeyboard: true}; };86 await driver.hideKeyboard();87 driver.back.calledOnce.should.be.true;88 });89 it('should not call back command if can\'t close keyboard', async () => {90 sandbox.stub(driver, 'back');91 driver.adb.isSoftKeyboardPresent = () => { return {isKeyboardShown: true, canCloseKeyboard: false}; };92 await driver.hideKeyboard();93 driver.back.notCalled.should.be.true;94 });95 it('should throw an error if no keyboard is present', async () => {96 driver.adb.isSoftKeyboardPresent = () => { return false; };97 await driver.hideKeyboard().should.be.rejectedWith(/not present/);98 });99 });100 describe('openSettingsActivity', () => {101 it('should open settings activity', async () => {102 sandbox.stub(driver.adb, 'getFocusedPackageAndActivity')103 .returns({appPackage: 'pkg', appActivity: 'act'});104 sandbox.stub(driver.adb, 'shell');105 sandbox.stub(driver.adb, 'waitForNotActivity');106 await driver.openSettingsActivity('set1');107 driver.adb.shell.calledWithExactly(['am', 'start', '-a', 'android.settings.set1'])108 .should.be.true;109 driver.adb.waitForNotActivity.calledWithExactly('pkg', 'act', 5000)110 .should.be.true;111 });112 });113 describe('getWindowSize', () => {114 it('should get window size', async () => {115 sandbox.stub(driver.bootstrap, 'sendAction')116 .withArgs('getDeviceSize').returns('size');117 await driver.getWindowSize().should.be.equal('size');118 });119 });120 describe('getCurrentActivity', () => {121 it('should get current activity', async () => {122 sandbox.stub(driver.adb, 'getFocusedPackageAndActivity')123 .returns({appActivity: 'act'});124 await driver.getCurrentActivity().should.eventually.be.equal('act');125 });126 });127 describe('getCurrentPackage', () => {128 it('should get current activity', async () => {129 sandbox.stub(driver.adb, 'getFocusedPackageAndActivity')130 .returns({appPackage: 'pkg'});131 await driver.getCurrentPackage().should.eventually.equal('pkg');132 });133 });134 describe('getLogTypes', () => {135 it('should get log types', async () => {136 await driver.getLogTypes().should.be.deep.equal(['logcat']);137 });138 });139 describe('getLog', () => {140 it('should get log types', async () => {141 sandbox.stub(driver.adb, 'getLogcatLogs').returns('logs');142 await driver.getLog('logcat').should.be.equal('logs');143 });144 it('should throws exception if log type is unsupported', async () => {145 expect(() => driver.getLog('unsupported_type'))146 .to.throw('Unsupported log type unsupported_type');147 });148 });149 describe('isAppInstalled', () => {150 it('should return true if app is installed', async () => {151 sandbox.stub(driver.adb, 'isAppInstalled').withArgs('pkg').returns(true);152 await driver.isAppInstalled('pkg').should.be.true;153 });154 });155 describe('removeApp', () => {156 it('should remove app', async () => {157 sandbox.stub(driver.adb, 'uninstallApk').withArgs('pkg').returns(true);158 await driver.removeApp('pkg').should.be.true;159 });160 });161 describe('installApp', () => {162 it('should install app', async () => {163 driver.opts.fastReset = 'fastReset';164 let app = 'app.apk';165 let opts = {app: 'app.apk', appPackage: 'pkg', fastReset: 'fastReset'};166 sandbox.stub(driver.helpers, 'configureApp').withArgs('app', '.apk')167 .returns(app);168 sandbox.stub(fs, 'exists').withArgs(app).returns(true);169 sandbox.stub(driver.adb, 'packageAndLaunchActivityFromManifest')170 .withArgs(app).returns({apkPackage: 'pkg'});171 sandbox.stub(helpers, 'installApkRemotely')172 .returns(true);173 await driver.installApp('app').should.eventually.be.true;174 driver.helpers.configureApp.calledOnce.should.be.true;175 fs.exists.calledOnce.should.be.true;176 driver.adb.packageAndLaunchActivityFromManifest.calledOnce.should.be.true;177 helpers.installApkRemotely.calledWithExactly(driver.adb, opts)178 .should.be.true;179 });180 it('should throw an error if APK does not exist', async () => {181 await driver.installApp('non/existent/app.apk').should.be.rejectedWith(/Could not find/);182 });183 });184 describe('background', function () {185 it('should bring app to background and back', async function () {186 const appPackage = 'wpkg';187 const appActivity = 'wacv';188 driver.opts = {appPackage, appActivity, intentAction: 'act',189 intentCategory: 'cat', intentFlags: 'flgs',190 optionalIntentArguments: 'opt'};191 let params = {pkg: appPackage, activity: appActivity, action: 'act', category: 'cat',192 flags: 'flgs',193 optionalIntentArguments: 'opt', stopApp: false};194 sandbox.stub(driver.adb, 'goToHome');195 sandbox.stub(driver.adb, 'getFocusedPackageAndActivity')196 .returns({appPackage, appActivity});197 sandbox.stub(B, 'delay');198 sandbox.stub(driver.adb, 'startApp');199 await driver.background(10);200 driver.adb.getFocusedPackageAndActivity.calledOnce.should.be.true;201 driver.adb.goToHome.calledOnce.should.be.true;202 B.delay.calledWithExactly(10000).should.be.true;203 driver.adb.startApp.calledWithExactly(params).should.be.true;204 });205 it('should bring app to background and back if started after session init', async function () {206 const appPackage = 'newpkg';207 const appActivity = 'newacv';208 driver.opts = {appPackage: 'pkg', appActivity: 'acv', intentAction: 'act',209 intentCategory: 'cat', intentFlags: 'flgs',210 optionalIntentArguments: 'opt'};211 let params = {pkg: appPackage, activity: appActivity, action: 'act', category: 'cat',212 flags: 'flgs', waitPkg: 'wpkg', waitActivity: 'wacv',213 optionalIntentArguments: 'opt', stopApp: false};214 driver.opts.startActivityArgs = {[`${appPackage}/${appActivity}`]: params};215 sandbox.stub(driver.adb, 'goToHome');216 sandbox.stub(driver.adb, 'getFocusedPackageAndActivity')217 .returns({appPackage, appActivity});218 sandbox.stub(B, 'delay');219 sandbox.stub(driver.adb, 'startApp');220 await driver.background(10);221 driver.adb.getFocusedPackageAndActivity.calledOnce.should.be.true;222 driver.adb.goToHome.calledOnce.should.be.true;223 B.delay.calledWithExactly(10000).should.be.true;224 driver.adb.startApp.calledWithExactly(params).should.be.true;225 });226 it('should not bring app back if seconds are negative', async function () {227 sandbox.stub(driver.adb, 'goToHome');228 sandbox.stub(driver.adb, 'startApp');229 await driver.background(-1);230 driver.adb.goToHome.calledOnce.should.be.true;231 driver.adb.startApp.notCalled.should.be.true;232 });233 });234 describe('getStrings', withMocks({helpers}, (mocks) => {235 it('should return app strings', async () => {236 driver.bootstrap.sendAction = () => { return ''; };237 mocks.helpers.expects("pushStrings")238 .returns({test: 'en_value'});239 let strings = await driver.getStrings('en');240 strings.test.should.equal('en_value');241 mocks.helpers.verify();242 });243 it('should return cached app strings for the specified language', async () => {244 driver.adb.getDeviceLanguage = () => { return 'en'; };245 driver.apkStrings.en = {test: 'en_value'};246 driver.apkStrings.fr = {test: 'fr_value'};247 let strings = await driver.getStrings('fr');248 strings.test.should.equal('fr_value');249 });250 it('should return cached app strings for the device language', async () => {251 driver.adb.getDeviceLanguage = () => { return 'en'; };252 driver.apkStrings.en = {test: 'en_value'};253 driver.apkStrings.fr = {test: 'fr_value'};254 let strings = await driver.getStrings();255 strings.test.should.equal('en_value');256 });257 }));258 describe('launchApp', () => {259 it('should init and start app', async () => {260 sandbox.stub(driver, 'initAUT');261 sandbox.stub(driver, 'startAUT');262 await driver.launchApp();263 driver.initAUT.calledOnce.should.be.true;264 driver.startAUT.calledOnce.should.be.true;265 });266 });267 describe('startActivity', () => {268 let params;269 beforeEach(() => {270 params = {pkg: 'pkg', activity: 'act', waitPkg: 'wpkg', waitActivity: 'wact',271 action: 'act', category: 'cat', flags: 'flgs', optionalIntentArguments: 'opt'};272 sandbox.stub(driver.adb, 'startApp');273 });274 it('should start activity', async () => {275 params.optionalIntentArguments = 'opt';276 params.stopApp = false;277 await driver.startActivity('pkg', 'act', 'wpkg', 'wact', 'act',278 'cat', 'flgs', 'opt', true);279 driver.adb.startApp.calledWithExactly(params).should.be.true;280 });281 it('should use dontStopAppOnReset from opts if it is not passed as param', async () => {282 driver.opts.dontStopAppOnReset = true;283 params.stopApp = false;284 await driver.startActivity('pkg', 'act', 'wpkg', 'wact', 'act', 'cat', 'flgs', 'opt');285 driver.adb.startApp.calledWithExactly(params).should.be.true;286 });287 it('should use appPackage and appActivity if appWaitPackage and appWaitActivity are undefined', async () => {288 params.waitPkg = 'pkg';289 params.waitActivity = 'act';290 params.stopApp = true;291 await driver.startActivity('pkg', 'act', null, null, 'act', 'cat', 'flgs', 'opt', false);292 driver.adb.startApp.calledWithExactly(params).should.be.true;293 });294 });295 describe('reset', () => {296 it('should reset app via reinstall if fullReset is true', async () => {297 driver.opts.fullReset = true;298 driver.opts.appPackage = 'pkg';299 sandbox.stub(driver.adb, 'stopAndClear');300 sandbox.stub(driver.adb, 'uninstallApk');301 sandbox.stub(helpers, 'installApkRemotely');302 sandbox.stub(driver, 'grantPermissions');303 sandbox.stub(driver, 'startAUT').returns('aut');304 await driver.reset().should.eventually.be.equal('aut');305 driver.adb.stopAndClear.calledWithExactly('pkg').should.be.true;306 driver.adb.uninstallApk.calledWithExactly('pkg').should.be.true;307 helpers.installApkRemotely.calledWithExactly(driver.adb, driver.opts)308 .should.be.true;309 driver.grantPermissions.calledOnce.should.be.true;310 driver.startAUT.calledOnce.should.be.true;311 });312 it('should do fast reset if fullReset is false', async () => {313 driver.opts.fullReset = false;314 driver.opts.appPackage = 'pkg';315 sandbox.stub(driver.adb, 'stopAndClear');316 sandbox.stub(driver, 'grantPermissions');317 sandbox.stub(driver, 'startAUT').returns('aut');318 await driver.reset().should.eventually.be.equal('aut');319 driver.adb.stopAndClear.calledWithExactly('pkg').should.be.true;320 driver.grantPermissions.calledOnce.should.be.true;321 driver.startAUT.calledOnce.should.be.true;322 });323 });324 describe('startAUT', () => {325 it('should start AUT', async () => {326 driver.opts = {appPackage: 'pkg', appActivity: 'act', intentAction: 'actn',327 intentCategory: 'cat', intentFlags: 'flgs', appWaitPackage: 'wpkg',328 appWaitActivity: 'wact', appWaitDuration: 'wdur',329 optionalIntentArguments: 'opt'};330 let params = {pkg: 'pkg', activity: 'act', action: 'actn', category: 'cat',331 flags: 'flgs', waitPkg: 'wpkg', waitActivity: 'wact',332 waitDuration: 'wdur', optionalIntentArguments: 'opt', stopApp: false};333 driver.opts.dontStopAppOnReset = true;334 params.stopApp = false;335 sandbox.stub(driver.adb, 'startApp');336 await driver.startAUT();337 driver.adb.startApp.calledWithExactly(params).should.be.true;338 });339 });340 describe('setUrl', () => {341 it('should set url', async () => {342 driver.opts = {appPackage: 'pkg'};343 sandbox.stub(driver.adb, 'startUri');344 await driver.setUrl('url');345 driver.adb.startUri.calledWithExactly('url', 'pkg').should.be.true;346 });347 });348 describe('closeApp', () => {349 it('should close app', async () => {350 driver.opts = {appPackage: 'pkg'};351 sandbox.stub(driver.adb, 'forceStop');352 await driver.closeApp();353 driver.adb.forceStop.calledWithExactly('pkg').should.be.true;354 });355 });356 describe('getDisplayDensity', () => {357 it('should return the display density of a device', async () => {358 driver.adb.shell = () => { return '123'; };359 (await driver.getDisplayDensity()).should.equal(123);360 });361 it('should return the display density of an emulator', async () => {362 driver.adb.shell = (cmd) => {363 let joinedCmd = cmd.join(' ');364 if (joinedCmd.indexOf('ro.sf') !== -1) {365 // device property look up366 return '';367 } else if (joinedCmd.indexOf('qemu.sf') !== -1) {368 // emulator property look up369 return '456';370 }371 return '';372 };373 (await driver.getDisplayDensity()).should.equal(456);374 });375 it('should throw an error if the display density property can\'t be found', async () => {376 driver.adb.shell = () => { return ''; };377 await driver.getDisplayDensity().should.be.rejectedWith(/Failed to get display density property/);378 });379 it('should throw and error if the display density is not a number', async () => {380 driver.adb.shell = () => { return 'abc'; };381 await driver.getDisplayDensity().should.be.rejectedWith(/Failed to get display density property/);382 });383 });384 describe('parseSurfaceLine', () => {385 it('should return visible true if the surface is visible', async () => {386 parseSurfaceLine('shown=true rect=1 1 1 1').should.be.eql({387 visible: true,388 x: 1,389 y: 1,390 width: 1,391 height: 1392 });393 });394 it('should return visible false if the surface is not visible', async () => {395 parseSurfaceLine('shown=false rect=1 1 1 1').should.be.eql({396 visible: false,397 x: 1,398 y: 1,399 width: 1,400 height: 1401 });402 });403 it('should return the parsed surface bounds', async () => {404 parseSurfaceLine('shown=true rect=(1.0,2.0) 3.0 x 4.0').should.be.eql({405 visible: true,406 x: 1,407 y: 2,408 width: 3,409 height: 4410 });411 });412 });413 // these are used for both parseWindows and getSystemBars tests414 let validWindowOutput = [415 ' Window #1 Derp',416 ' stuff',417 ' Surface: derp shown=false lalalala rect=(9.0,8.0) 7.0 x 6.0',418 ' more stuff',419 ' Window #2 StatusBar',420 ' blah blah blah',421 ' Surface: blah blah shown=true blah blah rect=(1.0,2.0) 3.0 x 4.0',422 ' blah blah blah',423 ' Window #3 NavigationBar',424 ' womp womp',425 ' Surface: blah blah shown=false womp womp rect=(5.0,6.0) 50.0 x 60.0',426 ' qwerty asd zxc'427 ].join('\n');428 let validSystemBars = {429 statusBar: {visible: true, x: 1, y: 2, width: 3, height: 4},430 navigationBar: {visible: false, x: 5, y: 6, width: 50, height: 60}431 };432 describe('parseWindows', () => {433 it('should throw an error if the status bar info wasn\'t found', async () => {434 expect(() => { parseWindows(''); })435 .to.throw(Error, /Failed to parse status bar information./);436 });437 it('should throw an error if the navigation bar info wasn\'t found', async () => {438 let windowOutput = [439 ' Window #1 StatusBar',440 ' blah blah blah',441 ' Surface: blah blah shown=true blah blah rect=(1.0,2.0) 3.0 x 4.0',442 ' blah blah blah'443 ].join('\n');444 expect(() => { parseWindows(windowOutput); })445 .to.throw(Error, /Failed to parse navigation bar information./);446 });447 it('should return status and navigation bar info when both are given', async () => {448 parseWindows(validWindowOutput).should.be.eql(validSystemBars);449 });450 });451 describe('getSystemBars', () => {452 it('should throw an error if there\'s no window manager output', async () => {453 driver = new AndroidDriver();454 driver.adb = {};455 driver.adb.shell = () => { return ''; };456 await driver.getSystemBars().should.be.rejectedWith(/Did not get window manager output./);457 });458 it('should return the parsed system bar info', async () => {459 driver = new AndroidDriver();460 driver.adb = {};461 driver.adb.shell = () => { return validWindowOutput; };462 (await driver.getSystemBars()).should.be.eql(validSystemBars);463 });464 });...
general.js
Source:general.js
...136 };137 }138 args = await util.filterObject(args);139 log.debug(`Bringing application back to foreground with arguments: ${JSON.stringify(args)}`);140 return await this.adb.startApp(args);141};142commands.getStrings = async function (language) {143 if (!language) {144 language = await this.adb.getDeviceLanguage();145 log.info(`No language specified, returning strings for: ${language}`);146 }147 if (this.apkStrings[language]) {148 // Return cached strings149 return this.apkStrings[language];150 }151 // TODO: This is mutating the current language, but it's how appium currently works152 this.apkStrings[language] = await androidHelpers.pushStrings(language, this.adb, this.opts);153 await this.bootstrap.sendAction('updateStrings');154 return this.apkStrings[language];155};156commands.launchApp = async function () {157 await this.initAUT();158 await this.startAUT();159};160commands.startActivity = async function (appPackage, appActivity,161 appWaitPackage, appWaitActivity,162 intentAction, intentCategory,163 intentFlags, optionalIntentArguments,164 dontStopAppOnReset) {165 log.debug(`Starting package '${appPackage}' and activity '${appActivity}'`);166 // dontStopAppOnReset is both an argument here, and a desired capability167 // if the argument is set, use it, otherwise use the cap168 if (!util.hasValue(dontStopAppOnReset)) {169 dontStopAppOnReset = !!this.opts.dontStopAppOnReset;170 }171 let args = {172 pkg: appPackage,173 activity: appActivity,174 waitPkg: appWaitPackage || appPackage,175 waitActivity: appWaitActivity || appActivity,176 action: intentAction,177 category: intentCategory,178 flags: intentFlags,179 optionalIntentArguments,180 stopApp: !dontStopAppOnReset181 };182 this.opts.startActivityArgs = this.opts.startActivityArgs || {};183 this.opts.startActivityArgs[`${appPackage}/${appActivity}`] = args;184 await this.adb.startApp(args);185};186commands.reset = async function () {187 if (this.opts.fullReset) {188 log.info("Running old fashion reset (reinstall)");189 await this.adb.stopAndClear(this.opts.appPackage);190 await this.adb.uninstallApk(this.opts.appPackage);191 await androidHelpers.installApkRemotely(this.adb, this.opts);192 } else {193 log.info("Running fast reset (stop and clear)");194 await this.adb.stopAndClear(this.opts.appPackage);195 }196 await this.grantPermissions();197 return await this.startAUT();198};199commands.startAUT = async function () {200 await this.adb.startApp({201 pkg: this.opts.appPackage,202 activity: this.opts.appActivity,203 action: this.opts.intentAction,204 category: this.opts.intentCategory,205 flags: this.opts.intentFlags,206 waitPkg: this.opts.appWaitPackage,207 waitActivity: this.opts.appWaitActivity,208 waitDuration: this.opts.appWaitDuration,209 optionalIntentArguments: this.opts.optionalIntentArguments,210 stopApp: !this.opts.dontStopAppOnReset211 });212};213// we override setUrl to take an android URI which can be used for deep-linking214// inside an app, similar to starting an intent...
macaca-android.js
Source:macaca-android.js
...208 yield this.adb.install(UnlockApk.apkPath);209 }210 var isScreenLocked = yield this.adb.isScreenLocked();211 if (isScreenLocked) {212 yield this.adb.startApp(UnlockApk);213 yield _.sleep(5000);214 yield this.unlock();215 }216};217Android.prototype.checkApkVersion = function * (app, pkg) {218 var newVersion = yield ADB.getApkVersion(app);219 var oldVersion = yield this.adb.getInstalledApkVersion(pkg);220 if (newVersion > oldVersion) {221 yield this.adb.install(app);222 }223};224Android.prototype.launchApk = function * () {225 if (!this.isChrome) {226 const reuse = this.args.reuse;227 const app = this.args.app;228 const pkg = this.apkInfo.package;229 const isInstalled = yield this.adb.isInstalled(pkg);230 if (!isInstalled && !app) {231 throw new Error('App is neither installed, nor provided!');232 }233 if (isInstalled) {234 switch (reuse) {235 case reuseStatus.noReuse:236 case reuseStatus.reuseEmu:237 if (app) {238 yield this.adb.unInstall(pkg);239 yield this.adb.install(app);240 } else {241 yield this.adb.clear(pkg);242 }243 break;244 case reuseStatus.reuseEmuApp:245 if (app) {246 yield this.adb.install(app);247 }248 break;249 case reuseStatus.reuseEmuAppState:250 // Keep app state, don't change to main activity.251 this.apkInfo.activity = '';252 }253 } else {254 yield this.adb.install(app);255 }256 }257 logger.debug(`start app with: ${JSON.stringify(this.apkInfo)}`);258 yield this.adb.startApp(this.apkInfo);259 yield _.sleep(5 * 1000);260};261Android.prototype.getWebviews = function * () {262 if (!this.chromedriver) {263 var webviewVersion = null;264 try {265 webviewVersion = yield this.adb.getWebviewVersion();266 } catch (error) {267 console.log(error);268 logger.info('No webview version found from adb shell!');269 webviewVersion = null;270 }271 try {272 if (webviewVersion) {...
adb-commands-e2e-specs.js
Source:adb-commands-e2e-specs.js
...55 (await adb.getPIDsByName('m.android.phone')).should.have.length.above(0);56 });57 it('killProcessesByName should kill process', async () => {58 await adb.install(contactManagerPath);59 await adb.startApp({pkg, activity});60 await adb.killProcessesByName(pkg);61 (await adb.getPIDsByName(pkg)).should.have.length(0);62 });63 it('killProcessByPID should kill process', async () => {64 await adb.install(contactManagerPath);65 await adb.startApp({pkg, activity});66 let pids = await adb.getPIDsByName(pkg);67 pids.should.have.length.above(0);68 await adb.killProcessByPID(pids[0]);69 (await adb.getPIDsByName(pkg)).length.should.equal(0);70 });71 it('should get device language and country', async function () {72 if (parseInt(apiLevel, 10) >= 23) return this.skip(); // eslint-disable-line curly73 if (process.env.TRAVIS) return this.skip(); // eslint-disable-line curly74 ['en', 'fr'].should.contain(await adb.getDeviceSysLanguage());75 ['US', 'EN_US', 'EN', 'FR'].should.contain(await adb.getDeviceSysCountry());76 });77 it('should set device language and country', async function () {78 if (parseInt(apiLevel, 10) >= 23) return this.skip(); // eslint-disable-line curly79 if (process.env.TRAVIS) return this.skip(); // eslint-disable-line curly...
apk-utils-e2e-specs.js
Source:apk-utils-e2e-specs.js
...55 });56 describe('startApp', async () => {57 it('should be able to start', async () => {58 await adb.install(contactManagerPath);59 await adb.startApp({pkg: 'com.example.android.contactmanager',60 activity: 'ContactManager'});61 await assertPackageAndActivity();62 });63 it('should throw error for wrong activity', async () => {64 await adb.install(contactManagerPath);65 await adb.startApp({pkg: 'com.example.android.contactmanager',66 activity: 'ContactManage'}).should.eventually67 .be.rejectedWith('Activity');68 });69 it('should throw error for wrong wait activity', async () => {70 await adb.install(contactManagerPath);71 await adb.startApp({pkg: 'com.example.android.contactmanager',72 activity: 'ContactManager',73 waitActivity: 'foo',74 waitDuration: 1000}).should.eventually75 .be.rejectedWith('foo');76 });77 it('should start activity with wait activity', async () => {78 await adb.install(contactManagerPath);79 await adb.startApp({pkg: 'com.example.android.contactmanager',80 activity: 'ContactManager',81 waitActivity: '.ContactManager'});82 await assertPackageAndActivity();83 });84 it('should start activity when wait activity is a wildcard', async () => {85 await adb.install(contactManagerPath);86 await adb.startApp({pkg: 'com.example.android.contactmanager',87 activity: 'ContactManager',88 waitActivity: '*'});89 await assertPackageAndActivity();90 });91 it('should start activity when wait activity contains a wildcard', async () => {92 await adb.install(contactManagerPath);93 await adb.startApp({pkg: 'com.example.android.contactmanager',94 activity: 'ContactManager',95 waitActivity: '*.ContactManager'});96 await assertPackageAndActivity();97 });98 it('should throw error for wrong activity when wait activity contains a wildcard', async () => {99 await adb.install(contactManagerPath);100 await adb.startApp({pkg: 'com.example.android.contactmanager',101 activity: 'SuperManager',102 waitActivity: '*.ContactManager'}).should.eventually103 .be.rejectedWith('Activity');104 });105 it('should throw error for wrong wait activity which contains wildcard', async () => {106 await adb.install(contactManagerPath);107 await adb.startApp({pkg: 'com.example.android.contactmanager',108 activity: 'ContactManager',109 waitActivity: '*.SuperManager'}).should.eventually110 .be.rejectedWith('SuperManager');111 });112 it('should start activity with comma separated wait packages list', async () => {113 await adb.install(contactManagerPath);114 await adb.startApp({pkg: 'com.example.android.contactmanager',115 waitPkg: 'com.android.settings, com.example.android.contactmanager',116 activity: 'ContactManager',117 waitActivity: '.ContactManager'});118 await assertPackageAndActivity();119 });120 it('should throw error for wrong activity when packages provided as comma separated list', async () => {121 await adb.install(contactManagerPath);122 await adb.startApp({pkg: 'com.example.android.contactmanager',123 waitPkg: 'com.android.settings, com.example.somethingelse',124 activity: 'SuperManager',125 waitActivity: '*.ContactManager'}).should.eventually126 .be.rejectedWith('Activity');127 });128 });129 it('should start activity when start activity is an inner class', async () => {130 await adb.install(contactManagerPath);131 await adb.startApp({pkg: 'com.android.settings',132 activity: '.Settings$NotificationAppListActivity'});133 let {appPackage, appActivity} = await adb.getFocusedPackageAndActivity();134 appPackage.should.equal('com.android.settings');135 appActivity.should.equal('.Settings$NotificationAppListActivity');136 });137 it('getFocusedPackageAndActivity should be able get package and activity', async () => {138 await adb.install(contactManagerPath);139 await adb.startApp({pkg: 'com.example.android.contactmanager',140 activity: 'ContactManager'});141 await assertPackageAndActivity();142 });143 it('extractStringsFromApk should get strings for default language', async () => {144 let {apkStrings} = await adb.extractStringsFromApk(contactManagerPath, null, '/tmp');145 apkStrings.save.should.equal('Save');146 });...
bootstrap-e2e-specs.js
Source:bootstrap-e2e-specs.js
...19 adb = await ADB.createADB();20 const packageName = 'io.appium.android.apis',21 activityName = '.ApiDemos';22 await adb.install(apiDemos);23 await adb.startApp({pkg: packageName,24 activity: activityName});25 androidBootstrap = new AndroidBootstrap(adb, systemPort);26 await androidBootstrap.start('io.appium.android.apis', false);27 });28 after(async function () {29 await androidBootstrap.shutdown();30 });31 it("sendAction should work", async function () {32 (await androidBootstrap.sendAction('wake')).should.equal(true);33 });34 it("sendCommand should work", async function () {35 (await androidBootstrap.sendCommand(COMMAND_TYPES.ACTION, {action: 'getDataDir'})).should36 .equal("/data");37 });...
adb-emu-commands-e2e-specs.js
Source:adb-emu-commands-e2e-specs.js
...25 await adb.forceStop(pkg);26 await adb.uninstallApk(pkg);27 }28 await adb.install(fingerprintPath);29 await adb.startApp({pkg, activity});30 await sleep(500);31 let app = await adb.getFocusedPackageAndActivity();32 app.appActivity.should.equal(activity);33 await adb.fingerprint(1111);34 await sleep(2500);35 app = await adb.getFocusedPackageAndActivity();36 app.appActivity.should.equal(secretActivity);37 });...
Using AI Code Generation
1var adb = require('./lib/adb.js');2adb.startApp({3}, function(err) {4 if (err) {5 console.log(err);6 }7});8var exec = require('child_process').exec;9var adb = require('adbkit');10var client = adb.createClient();11function startApp(opts, cb) {12 client.shell(opts.udid, 'am start -n ' + opts.pkg + '/' + opts.activity, cb);13}14module.exports.startApp = startApp;15var adb = require('appium-adb');
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var _ = require('underscore');4var fs = require('fs');5var path = require('path');6var Q = require('q');7var util = require('util');8var ADB = require('appium-adb').ADB;9var adb = new ADB();10var desired = {11};12var driver = wd.promiseChainRemote('
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!