How to use this.findElOrEls method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-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

1const wdio = require('webdriverio');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const assert = chai.assert;5const expect = chai.expect;6chai.use(chaiAsPromised);7const opts = {8    capabilities: {9    }10};11const client = wdio.remote(opts);12(async () => {13    await client.init();14    const searchBox = await client.$('input[name="q"]');15    await searchBox.setValue('Appium');16    const searchButton = await client.$('input[name="btnK"]');17    await searchButton.click();18    await client.pause(3000);19    await client.deleteSession();20})().catch(async (e) => {21    console.error(e);22    await client.deleteSession();23});24const wdio = require('webdriverio');25const chai = require('chai');26const chaiAsPromised = require('chai-as-promised');27const assert = chai.assert;28const expect = chai.expect;29chai.use(chaiAsPromised);30const opts = {31    capabilities: {32    }33};34const client = wdio.remote(opts);35(async () => {36    await client.init();37    const searchBox = await client.$('input[name="q"]');38    await searchBox.setValue('Appium');39    const searchButton = await client.$('input[name="btnK"]');40    await searchButton.click();41    await client.pause(3000);42    await client.deleteSession();43})().catch(async (e) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { findElOrEls } = require('appium-xcuitest-driver/lib/commands/find');2const { findElOrEls } = require('appium-xcuitest-driver/lib/commands/find');3const { findElOrEls } = require('appium-xcuitest-driver/lib/commands/find');4const { findElOrEls } = require('appium-xcuitest-driver/lib/commands/find');5const { findElOrEls } = require('appium-xcuitest-driver/lib/commands/find');6const { findElOrEls } = require('appium-xcuitest-driver/lib/commands/find');7const { findElOrEls } = require('appium-xcuitest-driver/lib/commands/find');8const { findElOrEls } = require('appium-xcuitest-driver/lib/commands/find');9const { findElOrEls } = require('appium-xcuitest-driver/lib/commands/find');10const { findElOrEls } = require('appium-xcuitest-driver/lib/commands/find');11const { findElOrEls }

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const { exec } = require('child_process');3const PORT = 4723;4const HOST = 'localhost';5const config = {6};7const driver = wd.promiseChainRemote(HOST, PORT);8const startApp = async () => {9  await driver.init(config);10  await driver.sleep(5000);11  const els = await driver.execute('mobile: findElOrEls', {12  });13  console.log(els);14};15startApp();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const path = require('path');3const assert = require('assert');4const { exec } = require('child_process');5const { APPIUM_HOST, APPIUM_PORT, APPIUM_LOGS, APPIUM_CAPS, APPIUM_DRIVER } = require('./constants');6const driver = wd.promiseChainRemote(APPIUM_HOST, APPIUM_PORT);7const caps = APPIUM_CAPS;8caps.app = path.resolve(__dirname, '../apps/TestApp.app.zip');9caps.platformName = 'iOS';10caps.platformVersion = '11.2';11caps.deviceName = 'iPhone 8';12driver.init(caps).then(() => {13    console.log('Appium session started');14    return driver.elementByAccessibilityId('Buttons').click();15}).then(() => {16    return driver.findElOrEls('class chain', '**/XCUIElementTypeButton[`label == "Button"`]', false);17}).then((el) => {18    console.log('Element found');19    console.log(el);20    return driver.quit();21}).catch((err) => {22    console.log('Error');23    console.log(err);24});25const APPIUM_HOST = 'localhost';26const APPIUM_PORT = 4723;27const APPIUM_LOGS = path.resolve(__dirname, '../logs/appium.log');28const APPIUM_CAPS = {29};30const APPIUM_DRIVER = wd.promiseChainRemote(APPIUM_HOST, APPIUM_PORT);31module.exports = {32};33{34  "scripts": {35  },

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', function () {2  it('test', function () {3    driver.findElOrEls('accessibility id', 'test', true).should.eventually.have.length(1);4  });5});6I am able to run the test on my local machine but I am not able to run the test on the cloud (Sauce Labs). I am getting the following error:7{8}

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('findElOrEls', function () {2    it('should find element by id', async function () {3        await driver.findElOrEls('id', '123', false);4    });5});6commands.findElOrEls = async function (strategy, selector, mult) {7    const isWebContext = this.isWebContext();8    const doFindElement = async () => {9        if (isWebContext) {10            return await this.findWebElementOrElements(strategy, selector, mult);11        }12        return await this.findNativeElementOrElements(strategy, selector, mult);13    };14    const doFindElements = async () => {15        if (isWebContext) {16            return await this.findWebElementsOrElements(strategy, selector, mult);17        }18        return await this.findNativeElementsOrElements(strategy, selector, mult);19    };20    if (mult) {21        return await doFindElements();22    }23    return await doFindElement();24};25commands.findWebElementOrElements = async function (strategy, selector, mult) {26    if (strategy === 'id') {27        strategy = 'css selector';28        selector = `*[id="${selector}"]`;29    }30    return await this.findWebElementsOrElements(strategy, selector, mult);31};32commands.findWebElementsOrElements = async function (strategy, selector, mult) {33    if (strategy === 'accessibility id') {34        strategy = 'css selector';35        selector = `*[name="${selector}"]`;36    }37    return await this.findWebElementsOrElements(strategy, selector, mult);38};39commands.findNativeElementOrElements = async function (strategy, selector, mult) {40    const doFindElement = async () => {41        if (strategy === 'id') {42            return await this.findNativeElementOrElementsUsingUIAutomation(strategy, selector, mult);43        }

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 Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful