How to use driver.executeAtom method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

web.js

Source:web.js Github

copy

Full Screen

...126async function tapWebElementNatively (driver, atomsElement) {127  // try to get the text of the element, which will be accessible in the128  // native context129  try {130    let text = await driver.executeAtom('get_text', [atomsElement]);131    if (!text) {132      text = await driver.executeAtom('get_attribute_value', [atomsElement, 'value']);133    }134    if (text) {135      const el = await driver.findNativeElementOrElements('accessibility id', text, false);136      // use tap because on iOS 11.2 and below `nativeClick` crashes WDA137      const rect = await driver.proxyCommand(`/element/${el.ELEMENT}/rect`, 'GET');138      const coords = {139        x: Math.round(rect.x + rect.width / 2),140        y: Math.round(rect.y + rect.height / 2),141      };142      await driver.clickCoords(coords);143      return true;144    }145  } catch (err) {146    // any failure should fall through and trigger the more elaborate...

Full Screen

Full Screen

element-specs.js

Source:element-specs.js Github

copy

Full Screen

1import sinon from 'sinon';2import XCUITestDriver from '../../..';3import chai from 'chai';4import chaiAsPromised from 'chai-as-promised';5import { withMocks, withSandbox } from 'appium-test-support';6import _ from 'lodash';7chai.should();8chai.use(chaiAsPromised);9describe('element commands', function () {10  let driver = new XCUITestDriver();11  let proxyStub = sinon.stub(driver, 'proxyCommand');12  afterEach(function () {13    proxyStub.reset();14  });15  describe('setValueImmediate', withMocks({driver}, (mocks) => {16    afterEach(function () {17      mocks.verify();18    });19    it('should call setValue', async function () {20      mocks.driver21        .expects('setValue')22        .once().withExactArgs('hello', 2).returns();23      await driver.setValueImmediate('hello', 2);24    });25  }));26  describe('getAttribute', function () {27    const elementId = 2;28    const attribute = 'enabled';29    afterEach(function () {30      proxyStub.calledOnce.should.be.true;31    });32    it('should properly parse boolean true attribute presented as integer', async function () {33      proxyStub.returns(1);34      (await driver.getAttribute(attribute, elementId)).should.eql('true');35    });36    it('should properly parse boolean false attribute presented as integer', async function () {37      proxyStub.returns(0);38      (await driver.getAttribute(attribute, elementId)).should.eql('false');39    });40    it('should properly parse integer attribute presented as string', async function () {41      proxyStub.returns('0');42      (await driver.getAttribute(attribute, elementId)).should.eql('0');43    });44    it('should properly parse boolean attribute presented as bool', async function () {45      proxyStub.returns(false);46      (await driver.getAttribute(attribute, elementId)).should.eql('false');47    });48    it('should properly parse null attribute', async function () {49      proxyStub.returns(null);50      _.isNull(await driver.getAttribute(attribute, elementId)).should.be.true;51    });52    it('should properly parse string attribute', async function () {53      proxyStub.returns('value');54      (await driver.getAttribute(attribute, elementId)).should.eql('value');55    });56  });57  describe('getAttribute - special contentSize', withSandbox({}, function (S) {58    it('should call the internal method instead of WDA', async function () {59      const getContentSizeStub = S.sandbox.stub(driver, 'getContentSize');60      getContentSizeStub.returns('foo');61      (await driver.getAttribute('contentSize', 2)).should.eql('foo');62      proxyStub.called.should.be.false;63      getContentSizeStub.calledOnce.should.be.true;64    });65  }));66  describe('getContentSize', withSandbox({}, function (S) {67    const el = {ELEMENT: '1234'};68    let getAttrStub, getRectStub, findElStub, getSizeStub, getLocationStub;69    beforeEach(function () {70      getAttrStub = S.sandbox.stub(driver, 'getAttribute');71      getRectStub = S.sandbox.stub(driver, 'getRect');72      findElStub = S.sandbox.stub(driver, 'findElOrEls');73      getSizeStub = S.sandbox.stub(driver, 'getSize');74      getLocationStub = S.sandbox.stub(driver, 'getLocationInView');75    });76    describe('web context', function () {77      const oldContext = driver.curContext;78      beforeEach(function () {79        driver.curContext = 'WEBVIEW';80      });81      afterEach(function () {82        driver.curContext = oldContext;83      });84      it('should throw when in a web context', async function () {85        await driver.getContentSize(el).should.eventually.be.rejectedWith(/not yet implemented/);86      });87    });88    it('should throw if trying to get contentSize of something other than table or collection', async function () {89      getAttrStub.returns('XCUIElementTypeStatusBar');90      await driver.getContentSize(el).should.eventually.be.rejectedWith(/Can't get content size for type/);91    });92    it('should simply get the rect if just one child', async function () {93      getAttrStub.returns('XCUIElementTypeTable');94      findElStub.returns([{ELEMENT: 'foo'}]);95      getRectStub.returns({x: 0, y: 0, height: 100, width: 200});96      getSizeStub.returns({height: 100, width: 200});97      getLocationStub.returns({x: 0, y: 0});98      const contentSizeObj = JSON.parse(await driver.getContentSize(el));99      contentSizeObj.should.eql({100        width: 200,101        height: 100,102        top: 0,103        left: 0,104        scrollableOffset: 100105      });106      getRectStub.calledOnce.should.be.true;107    });108    it('should get simple difference in element positions of a table', async function () {109      const el1 = {ELEMENT: 1}, el2 = {ELEMENT: 2};110      getAttrStub.returns('XCUIElementTypeTable');111      findElStub.returns([el1, el2]);112      getRectStub.withArgs(el1).returns({x: 0, y: 10, width: 50, height: 60});113      getRectStub.withArgs(el2).returns({x: 10, y: 80, width: 60, height: 100});114      getSizeStub.returns({height: 100, width: 200});115      getLocationStub.returns({x: 0, y: 0});116      const contentSizeObj = JSON.parse(await driver.getContentSize(el));117      contentSizeObj.should.eql({118        width: 200,119        height: 100,120        top: 0,121        left: 0,122        scrollableOffset: 170123      });124      getRectStub.calledTwice.should.be.true;125    });126    it('should be sensitive to row items in the case of a collection view', async function () {127      // set up a collection view with 3 rows of 2 elements.128      // give the last row just one element129      const fixtures = [130        {id: 1, x: 0, y: 0, height: 50}, {id: 2, x: 50, y: 0, height: 50},131        {id: 3, x: 0, y: 60, height: 50}, {id: 4, x: 50, y: 60, height: 50},132        {id: 5, x: 0, y: 120, height: 50}133      ];134      const scrollableOffset = 170; // 3 rows plus space between two135      getAttrStub.returns('XCUIElementTypeCollectionView');136      findElStub.returns(fixtures.map(el => ({ELEMENT: el.id})));137      for (let item of fixtures) {138        getRectStub.withArgs({ELEMENT: item.id}).returns(item);139      }140      getSizeStub.returns({height: 100, width: 200});141      getLocationStub.returns({x: 0, y: 0});142      const contentSizeObj = JSON.parse(await driver.getContentSize(el));143      contentSizeObj.should.eql({144        width: 200,145        height: 100,146        top: 0,147        left: 0,148        scrollableOffset149      });150      getRectStub.callCount.should.equal(3);151    });152  }));153  describe('setValue', function () {154    const elementId = 2;155    const expectedEndpoint = `/element/${elementId}/value`;156    const expectedMethod = 'POST';157    describe('success', function () {158      afterEach(function () {159        proxyStub.calledOnce.should.be.true;160        proxyStub.firstCall.args[0].should.eql(expectedEndpoint);161        proxyStub.firstCall.args[1].should.eql(expectedMethod);162      });163      it('should proxy string as array of characters', async function () {164        await driver.setValue('hello', elementId);165        proxyStub.firstCall.args[2].should.eql({value: ['h', 'e', 'l', 'l', 'o']});166      });167      it('should proxy integer as array of characters', async function () {168        await driver.setValue(1234, elementId);169        proxyStub.firstCall.args[2].should.eql({value: ['1', '2', '3', '4']});170      });171      it('should proxy string array as array of characters', async function () {172        await driver.setValue(['hel', 'lo'], elementId);173        proxyStub.firstCall.args[2].should.eql({value: ['h', 'e', 'l', 'l', 'o']});174      });175      it('should proxy integer array as array of characters', async function () {176        await driver.setValue([1234], elementId);177        proxyStub.firstCall.args[2].should.eql({value: ['1', '2', '3', '4']});178      });179    });180    describe('failure', function () {181      it('should throw invalid argument exception for null', async function () {182        await driver.setValue(null, elementId)183          .should.eventually.be.rejectedWith(/Only strings and arrays of strings are supported as input arguments. Received: 'null'/);184      });185      it('should throw invalid argument exception for object', async function () {186        await driver.setValue({hi: 'there'}, elementId)187          .should.eventually.be.rejectedWith(/Only strings and arrays of strings are supported as input arguments. Received: '{"hi":"there"}'/);188      });189    });190  });191  describe('getLocation for web elements', function () {192    let driver = new XCUITestDriver();193    const oldContext = driver.curContext;194    const webEl = {ELEMENT: '5000'};195    const fixtureXOffset = 100, fixtureYOffset = 200;196    let executeStub = sinon.stub(driver, 'execute');197    executeStub.returns([fixtureXOffset, fixtureYOffset]);198    let atomsElStub = sinon.stub(driver, 'useAtomsElement', (el) => el);199    let atomStub = sinon.stub(driver, 'executeAtom');200    let proxyStub = sinon.stub(driver, 'proxyCommand');201    atomStub.returns({x: 0, y: 0});202    beforeEach(function () {203      driver.curContext = "fake web context";204    });205    afterEach(function () {206      driver.curContext = oldContext;207      executeStub.reset();208      atomsElStub.reset();209      atomStub.reset();210      proxyStub.reset();211    });212    it('should get location relative to scroll by default', async function () {213      const loc = await driver.getLocation(webEl);214      executeStub.calledOnce.should.be.false;215      atomStub.calledOnce.should.be.true;216      atomStub.firstCall.args[0].should.eql('get_top_left_coordinates');217      loc.x.should.equal(0);218      loc.y.should.equal(0);219    });220    it('should get location relative to document with abosluteWebLocations cap', async function () {221      driver.opts.absoluteWebLocations = true;222      const loc = await driver.getLocation(webEl);223      executeStub.calledOnce.should.be.true;224      atomStub.calledOnce.should.be.true;225      atomStub.firstCall.args[0].should.eql('get_top_left_coordinates');226      loc.x.should.equal(fixtureXOffset);227      loc.y.should.equal(fixtureYOffset);228    });229  });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriver = require('selenium-webdriver');2const {Builder} = require('selenium-webdriver');3const {By} = require('selenium-webdriver');4const {until} = require('selenium-webdriver');5const driver = new webdriver.Builder()6  .forBrowser('chrome')7  .build();8driver.findElement(By.name('q')).sendKeys('webdriver');9driver.findElement(By.name('btnK')).click();10driver.wait(until.titleIs('webdriver - Google Search'), 1000);11driver.executeAtom('mobile: scroll', {direction: 'down'});12driver.quit();13await driver.execute('mobile: scroll', {direction: 'down'});14const webdriver = require('selenium-webdriver');15const {Builder} = require('selenium-webdriver');16const {By} = require('selenium-webdriver');17const {until} = require('selenium-webdriver');18const driver = new webdriver.Builder()19  .forBrowser('chrome')20  .build();21driver.findElement(By.name('q')).sendKeys('webdriver');22driver.findElement(By.name('btnK')).click();23driver.wait(until.titleIs('webdriver - Google Search'), 1000);24driver.execute('mobile: scroll', {direction

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2const { execSync } = require('child_process');3const opts = {4    capabilities: {5    }6};7(async () => {8    const client = await remote(opts);9    const value = await client.execute('mobile: scroll', {direction: 'down'});10    console.log(value);11    await client.deleteSession();12})();13const { remote } = require('webdriverio');14const { execSync } = require('child_process');15const opts = {16    capabilities: {17    }18};19(async () => {20    const client = await remote(opts);21    const value = await client.execute('mobile: scroll', {direction: 'down'});22    console.log(value);23    await client.deleteSession();24})();25const { remote } = require('webdriverio');26const { execSync } = require('child_process');27const opts = {28    capabilities: {29    }30};31(async () => {32    const client = await remote(opts);33    const value = await client.execute('mobile: scroll', {direction: 'down'});34    console.log(value);35    await client.deleteSession();36})();37const { remote } = require('webdriverio');38const { execSync } = require('child_process');39const opts = {40    capabilities: {41    }42};43(async () => {

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const assert = chai.assert;5const expect = chai.expect;6chai.use(chaiAsPromised);7const desiredCaps = {8};9const driver = wd.promiseChainRemote('localhost', 4723);10driver.init(desiredCaps)11  .then(() => driver.executeAtom('selectPickerWheelValue', ['My Photos', 'Albums']))12  .then(() => driver.quit());13driver.executeAtom('selectPickerWheelValue', [‘My Photos’, ‘Albums’])14driver.executeAtom('selectPickerWheelValue', [[‘My Photos’, ‘Albums’]])15driver.executeAtom('selectPickerWheelValue', ['My Photos', 'Albums'])16driver.executeAtom('selectPickerWheelValue', ['My Photos, Albums'])17driver.executeAtom('selectPickerWheelValue', ['My Photos', Albums'])18driver.executeAtom('selectPickerWheelValue', ['My Photos', ‘Albums’])19driver.executeAtom('selectPickerWheelValue', [‘My Photos’, ‘Albums’])20driver.executeAtom('selectPickerWheelValue', [‘My Photos’, Albums’])21driver.executeAtom('selectPickerWheelValue

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2(async () => {3    const browser = await remote({4        capabilities: {5        }6    })7    await browser.deleteSession()8})().catch(console.error)9const { remote } = require('webdriverio');10(async () => {11    const browser = await remote({12        capabilities: {13        }14    })15    await browser.deleteSession()16})().catch(console.error)17const { remote } = require('webdriverio');18(async () => {19    const browser = await remote({20        capabilities: {21        }22    })23    await browser.execute('mobile: getText', {using: 'accessibility id', value: 'Hello World!'})24    await browser.deleteSession()25})().catch(console.error)26const { remote } = require('webdriverio');27(async () => {28    const browser = await remote({29        capabilities: {

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var {By, until} = require('selenium-webdriver');3var { XCUITestDriver } = require('appium-xcuitest-driver');4var driver = new webdriver.Builder()5    .forBrowser('Appium')6    .build();7var xcuitestDriver = new XCUITestDriver();8var caps = {9};10driver.init(caps);11var atom = 'mobile: scroll';12var args = {direction: 'up'};13driver.executeAtom(atom, args, []).then(function(result) {14    console.log(result);15});16driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { exec } = require('child_process');2const { assert } = require('chai');3describe('Appium XCUITest Driver', function () {4    it('should execute atom', function () {5        exec('node test.js', (err, stdout, stderr) => {6            if (err) {7                console.error(err)8            } else {9                console.log(`stdout: ${stdout}`);10                console.log(`stderr: ${stderr}`);11            }12        });13    });14});15stdout: {16    "value": {17        "rect": {18        },

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const assert = require('assert');3const opts = {4  capabilities: {5  }6};7const client = wdio.remote(opts);8  .init()9  .then(() => {10    return client.executeAtom('get_attribute_value', ['name', 'XCUIElementTypeApplication', 'XCUIElementTypeWindow', 'value']);11  })12  .then((value) => {13    assert.equal(value, 'Your App Name');14  })15  .catch((err) => {16    console.log(err);17  })18  .end();19const wdio = require('webdriverio');20const assert = require('assert');21const opts = {22  capabilities: {23  }24};25const client = wdio.remote(opts);26  .init()27  .then(() => {28    return client.executeAtom('get_attribute_value', ['name', 'XCUIElementTypeApplication', 'XCUIElementTypeWindow', 'value']);29  })30  .then((value) => {31    assert.equal(value, 'Your App Name');32  })33  .catch((err) => {34    console.log(err);35  })36  .end();

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