How to use this.adb.install method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

android-common.js

Source:android-common.js Github

copy

Full Screen

...574 if (err) {575 cb(new Error("Could not find Unicode IME apk; please run " +576 "'reset.sh --android' to build it."));577 } else {578 this.adb.install(imePath, false, cb);579 }580 }.bind(this));581};582androidCommon.pushSettingsApp = function (cb) {583 logger.debug("Pushing settings apk to device...");584 var settingsPath = path.resolve(__dirname, "..", "..", "..", "build",585 "settings_apk", "settings_apk-debug.apk");586 fs.stat(settingsPath, function (err) {587 if (err) {588 cb(new Error("Could not find settings apk; please run " +589 "'reset.sh --android' to build it."));590 } else {591 this.adb.install(settingsPath, false, cb);592 }593 }.bind(this));594};595androidCommon.pushUnlock = function (cb) {596 logger.debug("Pushing unlock helper app to device...");597 var unlockPath = path.resolve(__dirname, "..", "..", "..", "build",598 "unlock_apk", "unlock_apk-debug.apk");599 fs.stat(unlockPath, function (err) {600 if (err) {601 cb(new Error("Could not find unlock.apk; please run " +602 "'reset.sh --android' to build it."));603 } else {604 this.adb.install(unlockPath, false, cb);605 }606 }.bind(this));607};608androidCommon.unlockScreen = function (cb) {609 this.adb.isScreenLocked(function (err, isLocked) {610 if (err) return cb(err);611 if (isLocked) {612 logger.info("Unlocking screen");613 var timeoutMs = 10000;614 var start = Date.now();615 var unlockAndCheck = function () {616 logger.debug("Screen is locked, trying to unlock");617 var onStart = function (err) {618 if (err) return cb(err);...

Full Screen

Full Screen

macaca-android.js

Source:macaca-android.js Github

copy

Full Screen

...204 const isInstalled = yield this.adb.isInstalled(UnlockApk.package);205 if (isInstalled) {206 yield this.checkApkVersion(UnlockApk.apkPath, UnlockApk.package);207 } else {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!');...

Full Screen

Full Screen

setup.js

Source:setup.js Github

copy

Full Screen

...51 this.app.enable_wifi.style.display = 'none';52 }53 }54 installLocalApk(path){55 return this.adb.install(this.deviceSerial, fs.createReadStream(path))56 .catch(e=>{57 alert(e);58 this.app.toggleLoader(false);59 });60 }61 installApk(url){62 return this.adb.install(this.deviceSerial, new Readable().wrap(request(url)))63 .catch(e=>{64 alert(e);65 this.app.toggleLoader(false);66 });67 }68 uninstallApk(pkg){69 this.app.spinner_loading_message.innerText = 'Uninstalling '+pkg;70 this.app.toggleLoader(true);71 return this.adb.uninstall(this.deviceSerial, pkg)72 .then(()=>this.app.toggleLoader(false))73 .catch(e=>{74 alert(e);75 this.app.toggleLoader(false);76 });...

Full Screen

Full Screen

AndroidDriver.js

Source:AndroidDriver.js Github

copy

Full Screen

...44 async getBundleIdFromBinary(apkPath) {45 return await this.aapt.getPackageName(apkPath);46 }47 async installApp(deviceId, binaryPath, testBinaryPath) {48 await this.adb.install(deviceId, binaryPath);49 await this.adb.install(deviceId, testBinaryPath ? testBinaryPath : this.getTestApkPath(binaryPath));50 }51 async pressBack(deviceId) {52 const call = UIDevice.pressBack(invoke.callDirectly(UIAutomatorAPI.uiDevice()));53 await this.invocationManager.execute(call);54 }55 getTestApkPath(originalApkPath) {56 const testApkPath = APKPath.getTestApkPath(originalApkPath);57 if (!fs.existsSync(testApkPath)) {58 throw new Error(`'${testApkPath}' could not be found, did you run './gradlew assembleAndroidTest' ?`);59 }60 return testApkPath;61 }62 async uninstallApp(deviceId, bundleId) {63 if (await this.adb.isPackageInstalled(deviceId, bundleId)) {...

Full Screen

Full Screen

app-management.js

Source:app-management.js Github

copy

Full Screen

...141 * @throws {Error} if the given apk does not exist or is not reachable142 */143commands.installApp = async function installApp (appPath, options = {}) {144 const localPath = await this.helpers.configureApp(appPath, APP_EXTENSIONS);145 await this.adb.install(localPath, options);146};147export { commands };...

Full Screen

Full Screen

uiautomator2.js

Source:uiautomator2.js Github

copy

Full Screen

1import { JWProxy } from 'appium-base-driver';2import { retryInterval } from 'asyncbox';3import logger from './logger';4import { SERVER_APK_PATH as apkPath, TEST_APK_PATH as testApkPath, version as serverVersion } from 'appium-uiautomator2-server';5import adbkit from 'adbkit';6import { getRetries } from './utils';7import { util } from 'appium-support';8import B from 'bluebird';9const REQD_PARAMS = ['adb', 'tmpDir', 'host', 'systemPort', 'devicePort', 'disableWindowAnimation'];10const SERVER_LAUNCH_RETRIES = 20;11const SERVER_INSTALL_RETRIES = 20;12const INSTRUMENTATION_TARGET = 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner';13const SERVER_PACKAGE_ID = 'io.appium.uiautomator2.server';14const SERVER_TEST_PACKAGE_ID = `${SERVER_PACKAGE_ID}.test`;15class UiAutomator2Server {16 constructor (opts = {}) {17 for (let req of REQD_PARAMS) {18 if (!opts || !util.hasValue(opts[req])) {19 throw new Error(`Option '${req}' is required!`);20 }21 this[req] = opts[req];22 }23 this.jwproxy = new JWProxy({server: this.host, port: this.systemPort});24 this.proxyReqRes = this.jwproxy.proxyReqRes.bind(this.jwproxy);25 this.client = adbkit.createClient({26 port: this.adb.adbPort,27 host: this.host28 });29 }30 /**31 * Installs the apks on to the device or emulator.32 *33 * @param {number} installTimeout - Installation timeout34 */35 async installServerApk (installTimeout = SERVER_INSTALL_RETRIES * 1000) {36 const packagesInfo = [37 {38 appPath: apkPath,39 appId: SERVER_PACKAGE_ID,40 }, {41 appPath: testApkPath,42 appId: SERVER_TEST_PACKAGE_ID,43 }];44 const shouldUninstallServerPackages = await B.reduce(45 packagesInfo,46 async (accumulator, pkgInfo) => (await this.checkAndSignCert(pkgInfo.appPath, pkgInfo.appId)) || accumulator,47 false);48 if (shouldUninstallServerPackages) {49 for (const {appId} of packagesInfo) {50 try {51 await this.adb.uninstallApk(appId);52 } catch (err) {53 logger.warn(`Error uninstalling '${appId}': ${err.message}`);54 logger.debug('Continuing');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) {74 throw new Error('No instrumentation process found. Retrying...');75 }76 logger.debug(`Instrumentation '${INSTRUMENTATION_TARGET}' available`);77 });78 } catch (err) {79 logger.error(`Unable to find instrumentation target '${INSTRUMENTATION_TARGET}': ${err.message}`);80 if (output) {81 logger.debug('Available targets:');82 for (let line of output.split('\n')) {83 logger.debug(` ${line.replace('instrumentation:', '')}`);84 }85 }86 }87 }88 async checkAndSignCert (apk, apkPackage) {89 return false;90 }91 async startSession (caps) {92 // kill any uiautomator existing processes93 await this.killUiAutomatorOnDevice();94 logger.info(`Starting uiautomator2 server ${serverVersion}`);95 logger.info(`Using UIAutomator2 server from '${apkPath}' and test from '${testApkPath}'`);96 // let cmd = ['am', 'instrument', '-w',97 // 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner'];98 // this.adb.shell(cmd);99 // using 3rd party module called 'adbKit' for time being as using 'appium-adb'100 // facing IllegalStateException: UiAutomation not connected exception101 // https://github.com/appium/appium-uiautomator2-driver/issues/19102 await this.startSessionUsingAdbKit(caps.deviceUDID);103 let retries = getRetries('Server launch', caps.uiautomator2ServerLaunchTimeout, SERVER_LAUNCH_RETRIES);104 logger.info(`Waiting up to ${retries * 1000}ms for UiAutomator2 to be online...`);105 // wait for UiAutomator2 to be online106 await retryInterval(retries, 1000, this.jwproxy.command.bind(this.jwproxy), '/status', 'GET');107 await this.jwproxy.command('/session', 'POST', {desiredCapabilities: caps});108 }109 async startSessionUsingAdbKit (deviceUDID) {110 let cmd = 'am instrument -w';111 if (this.disableWindowAnimation) {112 cmd = `${cmd} --no-window-animation`;113 }114 cmd = `${cmd} ${INSTRUMENTATION_TARGET}`;115 logger.info(`Running command: 'adb -s ${deviceUDID} shell ${cmd}'`);116 this.client.shell(deviceUDID, cmd)117 .then(adbkit.util.readAll) // eslint-disable-line promise/prefer-await-to-then118 .then(function (output) { // eslint-disable-line promise/prefer-await-to-then119 for (let line of output.toString().split('\n')) {120 if (line.length) {121 logger.debug(`[UIAutomator2] ${line}`);122 }123 }124 }).catch(function (err) { // eslint-disable-line promise/prefer-await-to-callbacks125 logger.error(`[UIAutomator2 Error] ${err.message}`);126 logger.debug(`Full error: ${err.stack}`);127 });128 }129 async deleteSession () {130 logger.debug('Deleting UiAutomator2 server session');131 // rely on jwproxy's intelligence to know what we're talking about and132 // delete the current session133 try {134 await this.jwproxy.command('/', 'DELETE');135 } catch (err) {136 logger.warn(`Did not get confirmation UiAutomator2 deleteSession worked; ` +137 `Error was: ${err}`);138 }139 }140 async killUiAutomatorOnDevice () {141 try {142 await this.adb.forceStop('io.appium.uiautomator2.server');143 } catch (ignore) {144 logger.info("Unable to kill the io.appium.uiautomator2.server process, assuming it is already killed");145 }146 }147}...

Full Screen

Full Screen

phone.js

Source:phone.js Github

copy

Full Screen

...44 * @returns {Promise.<void>}45 */46 async install(id, apkPath) {47 try {48 await this.adb.install(id, apkPath);49 } catch (e) {50 }51 }52 /**53 * 执行adb shell 命令54 * @param id55 * @param command56 * @returns {Promise.<void>}57 */58 async shell(id, command) {59 try {60 log.debug('exec shell command =>', command);61 return await this.adb.shell(id, command).then(adbKit.util.readAll).then((buf) => {62 return buf.toString('utf-8').trim();...

Full Screen

Full Screen

selendroid.js

Source:selendroid.js Github

copy

Full Screen

...40 }41 async installModifiedServer () {42 let installed = await this.adb.isAppInstalled(this.modServerPkg);43 if (!installed) {44 await this.adb.install(this.modServerPath);45 }46 }47 async buildNewModServer () {48 logger.info(`Repackaging selendroid for: '${this.appPackage}'`);49 let packageTmpDir = path.resolve(this.tmpDir, this.appPackage);50 let newManifestPath = path.resolve(this.tmpDir, 'AndroidManifest.xml');51 logger.info(`Creating new manifest: '${newManifestPath}'`);52 await fs.mkdir(packageTmpDir);53 await fs.copyFile(SE_MANIFEST_PATH, newManifestPath);54 await this.adb.initAapt(); // TODO this should be internal to adb55 await this.adb.compileManifest(newManifestPath, this.modServerPkg,56 this.appPackage);57 await this.adb.insertManifest(newManifestPath, SE_APK_PATH,58 this.modServerPath);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var path = require('path');3var assert = require('assert');4var Appium = require('appium');5var desiredCaps = {6 app: path.resolve(__dirname, 'app-debug.apk')7};8var driver = wd.promiseChainRemote('localhost', 4723);9 .init(desiredCaps)10 .then(function () {11 return driver.installApp(path.resolve(__dirname, 'app-debug.apk'));12 })13 .then(function () {14 return driver.quit();15 })16 .done();17var wd = require('wd');18var path = require('path');19var assert = require('assert');20var Appium = require('appium');21var desiredCaps = {22 app: path.resolve(__dirname, 'app-debug.apk')23};24var driver = wd.promiseChainRemote('localhost', 4723);25 .init(desiredCaps)26 .then(function () {27 return driver.installApp(path.resolve(__dirname, 'app-debug.apk'));28 })29 .then(function () {30 return driver.quit();31 })32 .done();33var wd = require('wd');34var path = require('path');35var assert = require('assert');36var Appium = require('appium');37var desiredCaps = {38 app: path.resolve(__dirname, 'app-debug.apk')39};40var driver = wd.promiseChainRemote('localhost', 4723);41 .init(desiredCaps)42 .then(function () {43 return driver.installApp(path.resolve(__dirname, 'app-debug.apk'));44 })45 .then(function ()

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumDriver = require('appium-android-driver');2var driver = new AppiumDriver();3driver.adb.install('path/to/apk');4var AppiumDriver = require('appium-android-driver');5var driver = new AppiumDriver();6driver.adb.uninstall('package');7var AppiumDriver = require('appium-android-driver');8var driver = new AppiumDriver();9driver.adb.shell('command');10var AppiumDriver = require('appium-android-driver');11var driver = new AppiumDriver();12driver.adb.forwardPort('systemPort', 'devicePort');13var AppiumDriver = require('appium-android-driver');14var driver = new AppiumDriver();15driver.adb.push('localPath', 'remotePath');16var AppiumDriver = require('appium-android-driver');17var driver = new AppiumDriver();18driver.adb.pull('remotePath', 'localPath');19var AppiumDriver = require('appium-android-driver');20var driver = new AppiumDriver();21driver.adb.isAppInstalled('package');22var AppiumDriver = require('appium-android-driver');23var driver = new AppiumDriver();24driver.adb.isAppRunning('package');25var AppiumDriver = require('appium-android-driver');26var driver = new AppiumDriver();27driver.adb.startApp('options');28var AppiumDriver = require('appium-android-driver');29var driver = new AppiumDriver();30driver.adb.stopApp('package');

Full Screen

Using AI Code Generation

copy

Full Screen

1var AppiumAndroidDriver = require('appium-android-driver');2var AppiumAndroidDriver = new AppiumAndroidDriver();3var adb = AppiumAndroidDriver.adb;4adb.install('/path/to/apk', true, true);5var AppiumAndroidDriver = require('appium-android-driver');6var AppiumAndroidDriver = new AppiumAndroidDriver();7var adb = AppiumAndroidDriver.adb;8adb.install('/path/to/apk', true, true);9var AppiumAndroidDriver = require('appium-android-driver');10var AppiumAndroidDriver = new AppiumAndroidDriver();11var adb = AppiumAndroidDriver.adb;12adb.uninstall('package_name');13var AppiumAndroidDriver = require('appium-android-driver');14var AppiumAndroidDriver = new AppiumAndroidDriver();15var adb = AppiumAndroidDriver.adb;16adb.getApiLevel();17var AppiumAndroidDriver = require('appium-android-driver');18var AppiumAndroidDriver = new AppiumAndroidDriver();19var adb = AppiumAndroidDriver.adb;20adb.getConnectedEmulators();21var AppiumAndroidDriver = require('appium-android-driver');22var AppiumAndroidDriver = new AppiumAndroidDriver();23var adb = AppiumAndroidDriver.adb;24adb.forwardPort(1234, 1234);25var AppiumAndroidDriver = require('appium-android-driver');26var AppiumAndroidDriver = new AppiumAndroidDriver();27var adb = AppiumAndroidDriver.adb;28adb.getDeviceTime();29var AppiumAndroidDriver = require('appium-android-driver');30var AppiumAndroidDriver = new AppiumAndroidDriver();31var adb = AppiumAndroidDriver.adb;32adb.getDeviceSysLanguage();33var AppiumAndroidDriver = require('appium-android-driver');

Full Screen

Using AI Code Generation

copy

Full Screen

1const driver = new AndroidDriver();2driver.adb.install(pathToApp);3const ApkUtils = require('./apk-utils');4const ApkUtils = new ApkUtils(this.adb);5ApkUtils.install(pathToApp);6const { readdirSync } = require('fs');7const { join } = require('path');8const currentFile = __filename;9const currentDir = __dirname;10const testFiles = readdirSync(currentDir)11 .filter(file => file !== currentFile)12 .map(file => join(currentDir, file));13testFiles.forEach(file => require(file));

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