Best JavaScript code snippet using appium-android-driver
utils.js
Source: utils.js
1import { fs, tempDir } from 'appium-support';2import path from 'path';3import { utils as iosUtils } from 'appium-ios-driver';4import { exec } from 'teen_process';5import xcode from 'appium-xcode';6import _ from 'lodash';7import log from './logger';8import pkgObj from '../../package.json'; // eslint-disable-line import/no-unresolved9const WDA_DERIVED_DATA_SEARCH_SUFFIX = 'Library/Developer/Xcode/DerivedData/WebDriverAgent-*';10const WDA_ATTACHMENTS_FOLDER_RELATIVE_PATH = 'Logs/Test/Attachments';11const DRIVER_VER = pkgObj.version;12async function detectUdid () {13 log.debug('Auto-detecting real device udid...');14 let cmd, args = [];15 try {16 cmd = await fs.which('idevice_id');17 args.push('-l');18 log.debug('Using idevice_id');19 } catch (err) {20 log.debug('Using udidetect');21 cmd = require.resolve('udidetect');22 }23 let udid;24 try {25 let {stdout} = await exec(cmd, args, {timeout: 3000});26 let udids = _.filter(stdout.split('\n'), Boolean);27 udid = _.last(udids);28 if (udids.length > 1) {29 log.warn(`Multiple devices found: ${udids.join(', ')}`);30 log.warn(`Choosing '${udid}'. If this is wrong, manually set with 'udid' desired capability`);31 }32 } catch (err) {33 log.errorAndThrow(`Error detecting udid: ${err.message}`);34 }35 if (!udid || udid.length <= 2) {36 throw new Error('Could not detect udid.');37 }38 log.debug(`Detected real device udid: '${udid}'`);39 return udid;40}41async function getAndCheckXcodeVersion () {42 let version;43 try {44 version = await xcode.getVersion(true);45 } catch (err) {46 log.debug(err);47 log.errorAndThrow(`Could not determine Xcode version: ${err.message}`);48 }49 if (!version.toolsVersion) {50 try {51 version.toolsVersion = await xcode.getCommandLineToolsVersion();52 } catch (ign) {}53 }54 // we do not support Xcodes < 7.3,55 if (version.versionFloat < 7.3) {56 log.errorAndThrow(`Xcode version '${version.versionString}'. Support for ` +57 `Xcode ${version.versionString} is not supported. ` +58 `Please upgrade to version 7.3 or higher`);59 }60 return version;61}62async function getAndCheckIosSdkVersion () {63 let versionNumber;64 try {65 versionNumber = await xcode.getMaxIOSSDK();66 } catch (err) {67 log.errorAndThrow(`Could not determine iOS SDK version: ${err.message}`);68 }69 return versionNumber;70}71async function killAppUsingAppName (udid, appName) {72 let psArgs = [`-c`, `ps -ax|grep -i "${appName}"|grep -i "${udid}"|grep -v grep|awk '{print "kill -9 " $1}'|sh`];73 try {74 await exec(`bash`, psArgs);75 } catch (err) {76 log.debug(`Error : ${err.message}`);77 }78}79async function adjustWDAAttachmentsPermissions (perms) {80 if (!process.env.HOME) {81 throw new Error('Need HOME env var to be set in order to adjust WDA attachments permission');82 }83 let derivedDataSearchMask = path.join(process.env.HOME, WDA_DERIVED_DATA_SEARCH_SUFFIX);84 let folders = await fs.glob(derivedDataSearchMask);85 let changesMade = false;86 for (let folder of folders) {87 log.debug(`Found WDA derived data folder: '${folder}'`);88 let attachmentsFolder = path.join(folder, WDA_ATTACHMENTS_FOLDER_RELATIVE_PATH);89 if (await fs.exists(attachmentsFolder)) {90 log.info(`Setting '${perms}' permissions to '${attachmentsFolder}' folder`);91 await fs.chmod(attachmentsFolder, perms);92 changesMade = true;93 }94 }95 if (!changesMade) {96 log.info('No WDA derived data folders have been found.');97 }98}99async function clearSystemFiles (wda) {100 // only want to clear the system files for the particular WDA xcode run101 if (!wda || !wda.derivedDataPath) {102 log.debug('No WebDriverAgent derived data available, so unable to clear system files');103 return;104 }105 let toDelete = [path.resolve(wda.derivedDataPath, 'Logs')];106 await iosUtils.clearLogs(toDelete);107}108async function generateXcodeConfigFile (orgId, signingId) {109 log.debug(`Generating xcode config file for orgId '${orgId}' and signingId ` +110 `'${signingId}'`);111 let contents = `DEVELOPMENT_TEAM = ${orgId}112CODE_SIGN_IDENTITY = ${signingId}113`;114 let xcconfigPath = await tempDir.path('appium-temp.xcconfig');115 log.debug(`Writing xcode config file to ${xcconfigPath}`);116 await fs.writeFile(xcconfigPath, contents, "utf8");117 return xcconfigPath;118}119async function checkAppPresent (app) {120 log.debug(`Checking whether app '${app}' is actually present on file system`);121 if (!(await fs.exists(app))) {122 log.errorAndThrow(`Could not find app at '${app}'`);123 }124 log.debug('App is present');125}126async function getDriverInfo () {127 let stat = await fs.stat(path.resolve(__dirname, '..'));128 let built = stat.mtime.getTime();129 let info = {130 built,131 version: DRIVER_VER,132 };133 return info;134}135export { detectUdid, getAndCheckXcodeVersion, getAndCheckIosSdkVersion,136 killAppUsingAppName, adjustWDAAttachmentsPermissions,137 generateXcodeConfigFile, checkAppPresent, getDriverInfo,...
driver-specs.js
Source: driver-specs.js
...49 .returns(B.resolve());50 sinon.mock(driver.helpers).expects('configureApp')51 .returns(app);52 await driver.createSession({app});53 await driver.checkAppPresent(); // should not error54 // configureApp is shared between the two,55 // so restore mock or the next test will fail56 driver.helpers.configureApp.restore();57 });58 it('should reject if app not present', async function () {59 let driver = new SelendroidDriver({}, false);60 let app = path.resolve('asdfasdf');61 sinon.mock(driver).expects('checkAppPresent')62 .returns(B.resolve());63 sinon.mock(driver).expects('startSelendroidSession')64 .returns(B.resolve());65 sinon.mock(driver.helpers).expects('configureApp')66 .returns(app);67 await driver.createSession({app});68 driver.checkAppPresent.restore();69 await driver.checkAppPresent().should.eventually.be.rejectedWith('Could not find');70 });71 });72 describe('proxying', function () {73 let driver;74 before(function () {75 driver = new SelendroidDriver({}, false);76 driver.sessionId = 'abc';77 });78 describe('#proxyActive', function () {79 it('should exist', function () {80 driver.proxyActive.should.be.an.instanceof(Function);81 });82 it('should return true', function () {83 driver.proxyActive('abc').should.be.true;...
driver.js
Source: driver.js
...28 // TODO handle otherSessionData for multiple sessions29 let sessionId;30 [sessionId] = await super.createSession(caps);31 // fail very early if the app doesn't actually exist32 await this.checkAppPresent();33 if (!this.opts.bundleId) {34 this.opts.bundleId = await extractBundleId(this.opts.app);35 }36 // start sim, or use running sim37 log.info('starting simlator (if not booted)');38 this.sim = await this.startSim();39 this.wda = new WebDriverAgent({40 udid: this.sim.udid,41 platformVersion: this.opts.platformVersion,42 host: this.opts.host,43 agentPath: this.opts.agentPath44 });45 await this.wda.launch(sessionId);46 log.info("Installing the app");...
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var serverConfig = {4};5var desiredCaps = {6};7var driver = wd.promiseChainRemote(serverConfig);8 .init(desiredCaps)9 .then(function () {10 return driver.checkAppPresent();11 })12 .then(function (isPresent) {13 assert.ok(isPresent);14 })15 .fin(function () {16 return driver.quit();17 })18 .done();19var wd = require('wd');20var assert = require('assert');21var serverConfig = {22};23var desiredCaps = {24};25var driver = wd.promiseChainRemote(serverConfig);26 .init(desiredCaps)27 .then(function () {28 return driver.checkAppPresent();29 })30 .then(function (isPresent) {31 assert.ok(isPresent);32 })33 .fin(function () {34 return driver.quit();35 })36 .done();
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2 build();3driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');4driver.findElement(webdriver.By.name('btnG')).click();5driver.wait(function() {6 return driver.getTitle().then(function(title) {7 return title === 'webdriver - Google Search';8 });9}, 1000);10driver.quit();11driver.checkAppPresent('com.example.android.apis');12driver.quit();13driver.checkAppPresent('com.example.android.apis', function(err, present) {14 if (present) {15 console.log('The app is present.');16 } else {17 console.log('The app is not present.');18 }19});20driver.quit();21driver.checkAppPresent('com.example.android.apis', function(err, present) {22 if (present) {23 console.log('The app is present.');24 driver.startActivity('com.example.android.apis', '.ApiDemos');25 } else {26 console.log('The app is not present.');27 }28});29driver.quit();30driver.checkAppPresent('com.example.android.apis', function(err, present) {31 if (present) {32 console.log('The app is present.');33 driver.startActivity('com.example.android.apis', '.ApiDemos');34 } else {35 console.log('The app is not present.');36 driver.installApp('path/to/my.apk');37 driver.startActivity('com.example.android.apis', '.ApiDemos');38 }39});40driver.quit();41driver.checkAppPresent('com.example.android.apis', function(err, present) {42 if (present) {43 console.log('The app is present.');44 driver.startActivity('com.example.android.apis', '.ApiDemos');45 } else {46 console.log('The app is not present.');47 driver.installApp('path/to/my.ap
Using AI Code Generation
1driver.checkAppPresent("com.android.calculator2");2driver.checkAppPresent("com.apple.calculator");3driver.checkAppPresent("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");4driver.checkAppPresent("com.apple.calculator");5driver.checkAppPresent("com.android.calculator2");6driver.checkAppPresent("com.android.calculator2");7driver.checkAppPresent("com.android.calculator2");8driver.checkAppPresent("com.apple.calculator");9driver.checkAppPresent("com.android.calculator2");10driver.checkAppPresent("com.android.calculator2");11driver.checkAppPresent("com.android.calculator2");12driver.checkAppPresent("com.android.calculator2");13driver.checkAppPresent("com.android.calculator2", "com.android.calculator2.Calculator");14driver.checkAppPresent("com.apple.calculator", "CalculatorViewController");15driver.checkAppPresent("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App", "Calculator");16driver.checkAppPresent("com.apple.calculator", "Calculator");17driver.checkAppPresent("com.android.calculator2", "com.android.calculator2.Calculator");18driver.checkAppPresent("com.android.calculator2", "com.android.calculator2.Calculator");
Using AI Code Generation
1var wd = require('wd'),2 chai = require('chai'),3 chaiAsPromised = require('chai-as-promised'),4 assert = chai.assert;5chai.use(chaiAsPromised);6var desired = {
Using AI Code Generation
1driver.checkAppPresent("com.example.android.apis");2driver.checkAppPresent("com.example.android.apis", "package");3driver.checkAppPresent("com.example.android.apis", "activity");4driver.checkAppPresent("com.example.android.apis");5driver.checkAppPresent("com.example.android.apis", "package");6driver.checkAppPresent("com.example.android.apis", "activity");7driver.checkAppPresent("com.example.android.apis");8driver.checkAppPresent("com.example.android.apis", "package");9driver.checkAppPresent("com.example.android.apis", "activity");10driver.checkAppPresent("com.example.android.apis");11driver.checkAppPresent("com.example.android.apis", "package");12driver.checkAppPresent("com.example.android.apis", "activity");13driver.checkAppPresent("com.example.android.apis");14driver.checkAppPresent("com.example.android.apis", "package");15driver.checkAppPresent("com.example.android.apis", "activity");16driver.checkAppPresent("com.example.android.apis");17driver.checkAppPresent("com.example.android.apis", "package");18driver.checkAppPresent("com.example.android.apis", "activity");19driver.checkAppPresent("com.example.android.apis");20driver.checkAppPresent("com.example.android.apis", "package");21driver.checkAppPresent("com.example.android.apis", "activity");22driver.checkAppPresent("com.example.android.apis");23driver.checkAppPresent("com.example.android.apis", "package");24driver.checkAppPresent("com.example.android.apis", "activity");25driver.checkAppPresent("com.example.android.apis");26driver.checkAppPresent("com.example.android.apis", "package");27driver.checkAppPresent("com.example.android.apis", "activity");28driver.checkAppPresent("com.example.android.apis");29driver.checkAppPresent("com.example.android
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var AndroidDriver = require('appium-android-driver');3var driver = new AndroidDriver();4driver.checkAppPresent('com.example.android.contactmanager').then(function (isPresent) {5 console.log('isPresent: ' + isPresent);6});
Using AI Code Generation
1driver.checkAppPresent("com.example.android.apis");2driver.checkAppPresent("com.example.android.apis", "1.0", "1.0.1");3driver.installApp("C:\\Users\\Downloads\\ApiDemos-debug.apk", "com.example.android.apis", "1.0", "1.0.1");4driver.installApp("C:\\Users\\Downloads\\ApiDemos-debug.apk");5driver.removeApp("com.example.android.apis", "1.0", "1.0.1");6driver.removeApp("com.example.android.apis");7driver.launchApp();8driver.closeApp();9driver.runAppInBackground(5);10driver.resetApp();11driver.isAppInstalled("com.example.android.apis", "1.0", "1.0.1");12driver.isAppInstalled("com.example.android.apis");13driver.activateApp("com.example.android.apis", "1.0", "1.0.1");14driver.activateApp("com.example.android.apis");15driver.terminateApp("com.example.android.apis", "1.0", "1.0.1");16driver.terminateApp("com.example.android.apis");17driver.installApp("C:\\Users\\Downloads\\ApiDemos-debug.apk", "com.example.android.apis", "1.0", "1.0.1");18driver.installApp("C:\\Users\\Downloads\\ApiDemos-debug.apk");19driver.removeApp("com.example.android.apis", "1.0", "1.0.1");20driver.removeApp("com.example.android.apis");21driver.launchApp();
Check out the latest blogs from LambdaTest on this topic:
Mobile apps have been an inseparable part of daily lives. Every business wants to be part of the ever-growing digital world and stay ahead of the competition by developing unique and stable applications.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
Let’s put it short: Appium Desktop = Appium Server + Inspector. When Appium Server runs automation test scripts, Appium Inspector can identify the UI elements of every application under test. The core structure of an Appium Inspector is to ensure that you discover every visible app element when you develop your test scripts. Before you kickstart your journey with Appium Inspector, you need to understand the details of it.
Mobile devices and mobile applications – both are booming in the world today. The idea of having the power of a computer in your pocket is revolutionary. As per Statista, mobile accounts for more than half of the web traffic worldwide. Mobile devices (excluding tablets) contributed to 54.4 percent of global website traffic in the fourth quarter of 2021, increasing consistently over the past couple of years.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
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!!