How to use this.findElOrEls method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

driver.js

Source:driver.js Github

copy

Full Screen

...265 if (activity !== "org.chromium.chrome.browser.firstrun.FirstRunActivity") {266 log.info("Chrome welcome dialog never showed up! Continuing");267 return;268 }269 let el = await this.findElOrEls('id', 'com.android.chrome:id/terms_accept', false);270 await this.click(el.ELEMENT);271 try {272 let el = await this.findElOrEls('id', 'com.android.chrome:id/negative_button', false);273 await this.click(el.ELEMENT);274 } catch (e) {275 // DO NOTHING, THIS DEVICE DIDNT LAUNCH THE SIGNIN DIALOG276 // IT MUST BE A NON GMS DEVICE277 log.warn(`This device didnt show Chrome SignIn dialog, ${e.message}`);278 }279 }280 async initAutoWebview () {281 if (this.opts.autoWebview) {282 let viewName = this.defaultWebviewName();283 let timeout = (this.opts.autoWebviewTimeout) || 2000;284 log.info(`Setting auto webview to context '${viewName}' with timeout ${timeout}ms`);285 // try every 500ms until timeout is over286 await retryInterval(timeout / 500, 500, async () => {...

Full Screen

Full Screen

context.js

Source:context.js Github

copy

Full Screen

...181 if (activity !== 'org.chromium.chrome.browser.firstrun.FirstRunActivity') {182 log.info('Chrome welcome dialog never showed up! Continuing');183 return;184 }185 let el = await this.findElOrEls('id', 'com.android.chrome:id/terms_accept', false);186 await this.click(el.ELEMENT);187 try {188 let el = await this.findElOrEls('id', 'com.android.chrome:id/negative_button', false);189 await this.click(el.ELEMENT);190 } catch (e) {191 // DO NOTHING, THIS DEVICE DIDNT LAUNCH THE SIGNIN DIALOG192 // IT MUST BE A NON GMS DEVICE193 log.warn(`This device did not show Chrome SignIn dialog, ${e.message}`);194 }195};196helpers.startChromeSession = async function startChromeSession () {197 log.info('Starting a chrome-based browser session');198 let opts = _.cloneDeep(this.opts);199 const knownPackages = [200 'org.chromium.chrome.shell',201 'com.android.chrome',202 'com.chrome.beta',...

Full Screen

Full Screen

driver-specs.js

Source:driver-specs.js Github

copy

Full Screen

1import fs from 'fs';2import chai from 'chai';3import chaiAsPromised from 'chai-as-promised';4import sinon from 'sinon';5import YouiEngineDriver from '../..';6let driver;7let sandbox = sinon.createSandbox();8let expect = chai.expect;9chai.should();10chai.use(chaiAsPromised);11describe('driver', function () {12 describe('constructor', function () {13 it('should call BaseDriver constructor with opts', function () {14 let driver = new YouiEngineDriver({foo: 'bar'});15 driver.should.exist;16 driver.opts.foo.should.equal('bar');17 });18 it('should have this.findElOrEls', function () {19 let driver = new YouiEngineDriver({foo: 'bar'});20 driver.findElOrEls.should.exist;21 driver.findElOrEls.should.be.a('function');22 });23 });24 describe('createSession', function () {25 beforeEach(function () {26 driver = new YouiEngineDriver();27 sandbox.stub(driver, 'validateDesiredCaps').returns(true);28 sandbox.stub(driver, 'executeSocketCommand');29 sandbox.stub(driver, 'connectSocket');30 sandbox.stub(driver, 'updateSettings');31 });32 afterEach(function () {33 sandbox.restore();34 });35 it('should start an Android session if platformName is Android', async function () {36 sandbox.stub(driver, 'startAndroidSession');37 await driver.createSession({automationName: 'YouiEngine', youiEngineAppAddress: '192.168.2.45', platformName: 'Android', deviceName: 'device', app: 'some.app.package'});38 driver.startAndroidSession.calledOnce.should.be.true;39 });40 it('should start an iOS session if platformName is iOS', async function () {41 sandbox.stub(driver, 'setupNewXCUITestDriver');42 await driver.createSession({automationName: 'YouiEngine', youiEngineAppAddress: '192.168.2.45', platformName: 'iOS', deviceName: 'device', app: 'some.app.package'});43 driver.setupNewXCUITestDriver.calledOnce.should.be.true;44 });45 it('should delete a session on failure', async function () {46 // Force an error to make sure deleteSession gets called47 sandbox.stub(driver, 'startXCUITestSession').throws();48 sandbox.stub(driver, 'deleteSession');49 try {50 await driver.createSession({automationName: 'YouiEngine', youiEngineAppAddress: '192.168.2.45', platformName: 'iOS', deviceName: 'device', app: 'some.app.package'});51 } catch (ign) {}52 driver.deleteSession.calledOnce.should.be.true;53 });54 it('should set up maxRetryCount if specified', async function () {55 sandbox.stub(driver, 'startAndroidSession');56 await driver.createSession({maxRetryCount: 5, automationName: 'YouiEngine', youiEngineAppAddress: '192.168.2.45', platformName: 'Android', deviceName: 'device', app: 'some.app.package'});57 driver.maxRetryCount.should.equal(5);58 });59 it('should default maxRetryCount to 3 if not specified', async function () {60 sandbox.stub(driver, 'startAndroidSession');61 await driver.createSession({automationName: 'YouiEngine', youiEngineAppAddress: '192.168.2.45', platformName: 'Android', deviceName: 'device', app: 'some.app.package'});62 driver.maxRetryCount.should.equal(3);63 });64 });65 describe('validateDesiredCaps', function () {66 const originalExistsSync = fs.existsSync;67 before(function () {68 driver = new YouiEngineDriver({}, true);69 fs.existsSync = sinon.stub().returns(true);70 });71 after(function () {72 fs.existsSync = originalExistsSync;73 });74 // List of scenarios to test:75 // 1) iOS simulator76 // 2) iOS real device77 // 3) Android emulator78 // 4) Android real device79 // 5) iOS simulator without proxy80 // 6) iOS real device without proxy81 // 7) Android emulator without proxy82 // 8) Android real device without proxy83 // Applies to all scenarios84 it('should throw an error if caps do not contain automationName', function () {85 expect(() => {86 driver.validateDesiredCaps({ platformName: 'Android', youiEngineAppAddress: 'localhost', deviceName: 'device', app: '/path/to/some.apk'});87 }).to.throw('\'automationName\' can\'t be blank');88 });89 it('should throw an error if caps do not contain platformName', function () {90 expect(() => {91 driver.validateDesiredCaps({ automationName: 'YouiEngine', youiEngineAppAddress: 'localhost', deviceName: 'device', app: '/path/to/some.apk'});92 }).to.throw('\'platformName\' can\'t be blank');93 });94 it('should throw an error if caps do not contain deviceName', function () {95 expect(() => {96 driver.validateDesiredCaps({automationName: 'YouiEngine', youiEngineAppAddress: 'localhost', platformName: 'Android', app: '/path/to/some.apk'});97 }).to.throw('\'deviceName\' can\'t be blank');98 });99 it('should not be sensitive to platform name casing', function () {100 expect(() => {101 driver.validateDesiredCaps({automationName: 'YouiEngine', youiEngineAppAddress: 'localhost', platformName: 'AnDrOiD', deviceName: 'device', app: '/path/to/some.apk'});102 }).to.not.throw();103 });104 it('should not be sensitive to automationName name casing', function () {105 expect(() => {106 driver.validateDesiredCaps({automationName: 'youIengIne', youiEngineAppAddress: 'localhost', platformName: 'Android', deviceName: 'device', app: '/path/to/some.apk'});107 }).to.not.throw();108 });109 it('should throw an error if maxRetryCount is not a number', function () {110 expect(() => {111 driver.validateDesiredCaps({maxRetryCount: 'not-a-number', automationName: 'YouiEngine', youiEngineAppAddress: 'localhost', platformName: 'Android', deviceName: 'device', app: '/path/to/some.apk'});112 }).to.throw('\'maxRetryCount\' must be of type number');113 });114 // Applies to all scenarios with proxy115 it('should throw an error if caps contain "platformName != NoProxy" and do not contain youiEngineAppAddress', function () {116 expect(function () {117 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'Android', deviceName: 'mydevice' });118 }).to.throw(/must include/);119 });120 it('should throw an error if caps contain "platformName != NoProxy" and do not contain app', function () {121 expect(() => {122 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'Android', deviceName: 'mydevice' });123 }).to.throw(/must include/);124 });125 // Applies to all scenarios with no proxy126 it('should not throw an error if caps contain "platformName == NoProxy" and do not contain youiEngineAppAddress', function () {127 expect(() => {128 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'NoProxy', deviceName: 'mydevice' });129 }).to.not.throw();130 });131 // 1) iOS simulator132 it('should not throw an error for minimum caps of iOS simulator', function () {133 expect(() => {134 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'iOS', deviceName: 'iOS Simulator', youiEngineAppAddress: 'localhost', app: '/path/to/some.app' });135 }).to.not.throw();136 });137 // 2) iOS real device138 it('should not throw an error for minimum caps of iOS real device', function () {139 expect(() => {140 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'iOS', deviceName: 'my device', youiEngineAppAddress: '192.168.1.72', app: '/path/to/some.app', udid: '09a24b51470b059f545d7a2fc996091e06675a61' });141 }).to.not.throw();142 });143 // 3) Android emulator144 it('should throw an error if caps contain "deviceName == Android" and do not contain avd', function () {145 expect(() => {146 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'NoProxy', deviceName: 'Android' });147 }).to.not.throw(/must include/);148 });149 /*it('should not throw an error for minimum caps of Android emulator', () => {150 expect(() => {151 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'Android', deviceName: 'Android', youiEngineAppAddress: 'localhost', app: '/path/to/some.app', avd: 'Nexus' });152 }).to.not.throw(Error);153 });*/154 // 4) Android real device155 it('should not throw an error for minimum caps of Android real device', function () {156 expect(() => {157 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'Android', deviceName: '83B7N14B02224534', youiEngineAppAddress: '192.168.1.72', app: '/path/to/some.app', avd: 'Nexus' });158 }).to.not.throw(Error);159 });160 // 5) iOS simulator without proxy161 it('should not throw an error for minimum caps of iOS simulator without proxy', function () {162 expect(() => {163 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'NoProxy', deviceName: 'localhost' });164 }).to.not.throw(Error);165 });166 // 6) iOS real device without proxy167 it('should not throw an error for minimum caps of iOS real device without proxy', function () {168 expect(() => {169 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'NoProxy', deviceName: 'my device', youiEngineAppAddress: '192.168.1.72' });170 }).to.not.throw(Error);171 });172 // 7) Android emulator without proxy173 // TBD174 // 8) Android real device without proxy175 it('should not throw an error for minimum caps of Android real device without proxy', function () {176 expect(() => {177 driver.validateDesiredCaps({automationName: 'YouiEngine', platformName: 'NoProxy', deviceName: '83B7N14B02224534', youiEngineAppAddress: '192.168.1.72'});178 }).to.not.throw(Error);179 });180 });...

Full Screen

Full Screen

alert.js

Source:alert.js Github

copy

Full Screen

...25 } catch (err) {26 log.debug(`Error finding alert element: ${err.message}`);27 throw new errors.NoAlertOpenError();28 }29 let possibleTextFields = await this.findElOrEls('-ios predicate string', `type == 'XCUIElementTypeTextField' OR type == 'XCUIElementTypeSecureTextField'`, true, alert);30 if (possibleTextFields.length !== 1) {31 let msg = `${possibleTextFields.length ? 'More than one' : 'No'} text ` +32 `field or secure text field found. Unable to type into the alert`;33 log.errorAndThrow(msg);34 }35 await this.setValue(text, util.unwrapElement(possibleTextFields[0]));36};37// TODO: WDA does not currently support this natively38commands.setAlertText = async function (text) {39 if (!Array.isArray(text)) {40 text = text.split('');41 }42 try {43 let method = 'POST';...

Full Screen

Full Screen

element.js

Source:element.js Github

copy

Full Screen

...3import log from '../logger';4let commands = {};5let extensions = {};6commands.getAttribute = async function getAttribute (elementId, attribute) {7 const element = await this.findElOrEls(strategies.ELEMENT_ID, elementId);8 return element.attributes[attribute];9};10commands.getName = async function getName (elementId) {11 const element = await this.findElOrEls(strategies.ELEMENT_ID, elementId);12 return element.tag;13};14commands.elementDisplayed = async function elementDisplayed (elementId) {15 const element = await this.findElOrEls(strategies.ELEMENT_ID, elementId);16 return element.isDisplayed;17};18commands.elementEnabled = async function elementEnabled (elementId) {19 return await this.elementDisplayed(elementId);20};21commands.elementSelected = async function elementSelected (elementId) {22 const element = await this.findElOrEls(strategies.ELEMENT_ID, elementId);23 return element.isFocused;24};25commands.setValue = async function setValue (keys, elementId) {26 const element = await this.findElOrEls(strategies.ELEMENT_ID, elementId);27 await element.append(keys);28};29commands.replaceValue = async function replaceValue (keys, elementId) {30 const element = await this.findElOrEls(strategies.ELEMENT_ID, elementId);31 await element.type(keys);32};33commands.setValueImmediate = async function setValueImmediate (keys, elementId) {34 await this.replaceValue(keys, elementId);35};36commands.getText = async function getText (elementId) {37 const element = await this.findElOrEls(strategies.ELEMENT_ID, elementId);38 return element.text;39};40commands.getSize = async function getSize (elementId) {41 const element = await this.findElOrEls(strategies.ELEMENT_ID, elementId);42 if (!element.bounds) {43 return log.errorAndThrow(new errors.ElementNotVisibleError());44 }45 return { width: element.bounds.width, height: element.bounds.height };46};47commands.getLocation = async function getLocation (elementId) {48 const node = await this.findElOrEls(strategies.ELEMENT_ID, elementId);49 if (!node) {50 return log.errorAndThrow(new errors.ElementNotVisibleError());51 }52 return { x: node.bounds.x, y: node.bounds.y };53};54commands.getElementRect = async function getElementRect (elementId) {55 const element = await this.findElOrEls(strategies.ELEMENT_ID, elementId);56 if (!element.bounds) {57 return log.errorAndThrow(new errors.ElementNotVisibleError());58 }59 return element.bounds;60};61commands.click = async function click (elementId) {62 const element = await this.findElOrEls(strategies.ELEMENT_ID, elementId);63 await element.select(this.ecp);64};65commands.clear = async function clear (elementId) {66 await this.replaceValue('', elementId);67};68commands.active = async function active () {69 return await this.findElOrEls(strategies.CSS_SELECTOR, '[focused="true"]:not(:has([focused="true"]))');70};71Object.assign(extensions, commands);72export {commands};...

Full Screen

Full Screen

find.js

Source:find.js Github

copy

Full Screen

...53 throw new errors.NoSuchElementError();54 }55};56commands.findElement = async function findElement (strategy, selector) {57 return this.findElOrEls(strategy, selector, false);58};59commands.findElements = async function findElements (strategy, selector) {60 return this.findElOrEls(strategy, selector, true);61};62commands.findElementFromElement = async function findElementFromElement (strategy, selector, elementId) {63 let el = this.getElement(elementId);64 return this.findElOrEls(strategy, selector, false, el.xmlFragment);65};66commands.findElementsFromElement = async function findElementsFromElement (strategy, selector, elementId) {67 let el = this.getElement(elementId);68 return this.findElOrEls(strategy, selector, true, el.xmlFragment);69};70Object.assign(extensions, commands, helpers);71export { commands, helpers};...

Full Screen

Full Screen

general.js

Source:general.js Github

copy

Full Screen

...36 },37 });38};39commands.getWindowRect = async function getWindowRect () {40 const element = await this.findElOrEls(strategies.XPATH, '//@bounds');41 return element.bounds;42};43commands.getWindowSize = async function getWindowSize () {44 log.info('Getting window size...');45 const { width, height } = await this.getWindowRect();46 return { width, height };47};48Object.assign(extensions, commands, helpers);49export {commands, helpers};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new webdriver.Builder()2 .withCapabilities({3 }).build();4 console.log(res);5});6driver.quit();7 console.log(res);8});9driver.quit();10 console.log(res);11});12driver.quit();13 console.log(res);14});15driver.quit();16 console.log(res);17});18driver.quit();19 console.log(res);20});21driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('findElOrEls', function () {2 let driver;3 before(async () => {4 driver = await initDriver();5 });6 after(async () => {7 await driver.quit();8 });9 it('findElOrEls', async () => {10 let els = await driver.findElOrEls('class name', 'android.widget.TextView', true);11 console.log(els);12 let el = await driver.findElOrEls('class name', 'android.widget.TextView', false);13 console.log(el);14 });15});16const findElOrEls = async function (strategy, selector, mult) {17 const findEl = mult ? this.findElOrEls : this.findEl;18 let res = await findEl.call(this, strategy, selector, mult);19 if (res === null) {20 res = await this.uiautomator2.jwproxy.command(`/element`, 'POST', {strategy, selector, context: this.curContext});21 }22 return res;23};24async function initDriver() {25 let driver = await wdio.remote({26 capabilities: {27 }28 });29 driver.findElOrEls = findElOrEls;30 return driver;31}322017-11-06 11:38:16:892 - [debug] [MJSONWP] Calling AppiumDriver.findElOrEls() with args: ["class name","android.widget.TextView",true,"d0a6f7e9-8f9a-4c6e-9a7d-6b8a6e0d6f7a"]332017-11-06 11:38:16:892 - [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"class name","selector":"android.widget.TextView","context":"","multiple":true}}342017-11-06 11:38:16:893 - [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action

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