How to use driver.elementByName method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

ios.spec.js

Source:ios.spec.js Github

copy

Full Screen

1/*jshint node: true, jasmine: true */2/*3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 *21*/22// these tests are meant to be executed by Cordova Medic Appium runner23// you can find it here: https://github.com/apache/cordova-medic/24// it is not necessary to do a full CI setup to run these tests25// just run "node cordova-medic/medic/medic.js appium --platform android --plugins cordova-plugin-camera"26'use strict';27var wdHelper = require('../helpers/wdHelper');28var wd = wdHelper.getWD();29var isDevice = global.DEVICE;30var cameraConstants = require('../../www/CameraConstants');31var cameraHelper = require('../helpers/cameraHelper');32var screenshotHelper = require('../helpers/screenshotHelper');33var MINUTE = 60 * 1000;34var DEFAULT_WEBVIEW_CONTEXT = 'WEBVIEW_1';35describe('Camera tests iOS.', function () {36 var driver;37 var webviewContext = DEFAULT_WEBVIEW_CONTEXT;38 var startingMessage = 'Ready for action!';39 function win() {40 expect(true).toBe(true);41 }42 function fail(error) {43 screenshotHelper.saveScreenshot(driver);44 if (error && error.message) {45 console.log('An error occured: ' + error.message);46 expect(true).toFailWithMessage(error.message);47 throw error.message;48 }49 if (error) {50 console.log('Failed expectation: ' + error);51 expect(true).toFailWithMessage(error);52 throw error;53 }54 // no message provided :(55 expect(true).toBe(false);56 throw 'An error without description occured';57 }58 // generates test specs by combining all the specified options59 // you can add more options to test more scenarios60 function generateSpecs() {61 var sourceTypes = [62 cameraConstants.PictureSourceType.CAMERA,63 cameraConstants.PictureSourceType.PHOTOLIBRARY64 ],65 destinationTypes = cameraConstants.DestinationType,66 encodingTypes = [67 cameraConstants.EncodingType.JPEG,68 cameraConstants.EncodingType.PNG69 ],70 allowEditOptions = [71 true,72 false73 ];74 return cameraHelper.generateSpecs(sourceTypes, destinationTypes, encodingTypes, allowEditOptions);75 }76 function getPicture(options, cancelCamera, skipUiInteractions) {77 if (!options) {78 options = {};79 }80 var command = "navigator.camera.getPicture(function (result) { document.getElementById('info').innerHTML = 'Success: ' + result.slice(0, 100); }, " +81 "function (err) { document.getElementById('info').innerHTML = 'ERROR: ' + err; }," + JSON.stringify(options) + ");";82 return driver83 .sleep(2000)84 .context(webviewContext)85 .execute(command)86 .sleep(5000)87 .context('NATIVE_APP')88 .then(function () {89 if (skipUiInteractions) {90 return;91 }92 if (options.hasOwnProperty('sourceType') && options.sourceType === cameraConstants.PictureSourceType.PHOTOLIBRARY) {93 return driver94 .elementByName('Camera Roll')95 .click()96 .elementByXPath('//UIACollectionCell')97 .click()98 .then(function () {99 if (options.hasOwnProperty('allowEdit') && options.allowEdit === true) {100 return driver101 .elementByName('Use')102 .click();103 }104 return driver;105 });106 }107 if (options.hasOwnProperty('sourceType') && options.sourceType === cameraConstants.PictureSourceType.SAVEDPHOTOALBUM) {108 return driver109 .elementByXPath('//UIACollectionCell')110 .click()111 .then(function () {112 if (options.hasOwnProperty('allowEdit') && options.allowEdit === true) {113 return driver114 .elementByName('Use')115 .click();116 }117 return driver;118 });119 }120 if (cancelCamera) {121 return driver122 .elementByName('Cancel')123 .click();124 }125 return driver126 .elementByName('PhotoCapture')127 .click()128 .elementByName('Use Photo')129 .click();130 })131 .sleep(3000);132 }133 function enterTest() {134 return driver135 .contexts(function (err, contexts) {136 if (err) {137 fail(err);138 } else {139 // if WEBVIEW context is available, use it140 // if not, use NATIVE_APP141 webviewContext = contexts[contexts.length - 1];142 }143 })144 .then(function () {145 return driver146 .context(webviewContext);147 })148 .fail(fail)149 .elementById('info')150 .fail(function () {151 // unknown starting page: no 'info' div152 // adding it manually153 return driver154 .execute('var info = document.createElement("div"); ' +155 'info.id = "info"' +156 'document.body.appendChild(info);')157 .fail(fail);158 })159 .execute('document.getElementById("info").innerHTML = "' + startingMessage + '";')160 .fail(fail);161 }162 function checkPicture(shouldLoad) {163 return driver164 .contexts(function (err, contexts) {165 // if WEBVIEW context is available, use it166 // if not, use NATIVE_APP167 webviewContext = contexts[contexts.length - 1];168 })169 .context(webviewContext)170 .elementById('info')171 .getAttribute('innerHTML')172 .then(function (html) {173 if (html.indexOf(startingMessage) >= 0) {174 expect(true).toFailWithMessage('No callback was fired');175 } else if (shouldLoad) {176 expect(html.length).toBeGreaterThan(0);177 if (html.indexOf('ERROR') >= 0) {178 expect(true).toFailWithMessage(html);179 }180 } else {181 if (html.indexOf('ERROR') === -1) {182 expect(true).toFailWithMessage('Unexpected success callback with result: ' + html);183 }184 expect(html.indexOf('ERROR')).toBe(0);185 }186 })187 .context('NATIVE_APP');188 }189 function runCombinedSpec(spec) {190 return enterTest()191 .then(function () {192 return getPicture(spec.options);193 })194 .then(function () {195 return checkPicture(true);196 })197 .then(win, fail);198 }199 beforeEach(function () {200 jasmine.addMatchers({201 toFailWithMessage : function () {202 return {203 compare: function (actual, msg) {204 console.log('Failing with message: ' + msg);205 var result = {206 pass: false,207 message: msg208 };209 return result;210 }211 };212 }213 });214 });215 it('camera.ui.util Configuring driver and starting a session', function (done) {216 driver = wdHelper.getDriver('iOS', done);217 }, 3 * MINUTE);218 describe('Specs.', function () {219 // getPicture() with mediaType: VIDEO, sourceType: PHOTOLIBRARY220 it('camera.ui.spec.1 Selecting only videos', function (done) {221 var options = { sourceType: cameraConstants.PictureSourceType.PHOTOLIBRARY,222 mediaType: cameraConstants.MediaType.VIDEO };223 enterTest()224 .then(function () { return getPicture(options, false, true); }) // skip ui unteractions225 .sleep(5000)226 .elementByName('Videos')227 .then(win, fail)228 .elementByName('Cancel')229 .click()230 .finally(done);231 }, 3 * MINUTE);232 // getPicture(), then dismiss233 // wait for the error callback to bee called234 it('camera.ui.spec.2 Dismissing the camera', function (done) {235 // camera is not available on iOS simulator236 if (!isDevice) {237 pending();238 }239 var options = { sourceType: cameraConstants.PictureSourceType.CAMERA };240 enterTest()241 .then(function () {242 return getPicture(options, true);243 })244 .then(function () {245 return checkPicture(false);246 })247 .elementByXPath('//UIAStaticText[contains(@label,"no image selected")]')248 .then(function () {249 return checkPicture(false);250 }, fail)251 .finally(done);252 }, 3 * MINUTE);253 // combine various options for getPicture()254 generateSpecs().forEach(function (spec) {255 it('camera.ui.spec.3.' + spec.id + ' Combining options', function (done) {256 // camera is not available on iOS simulator257 if (!isDevice) {258 pending();259 }260 runCombinedSpec(spec).then(done);261 }, 3 * MINUTE);262 });263 });264 it('camera.ui.util.4 Destroy the session', function (done) {265 driver.quit(done);266 }, 10000);...

Full Screen

Full Screen

touch-id-e2e-specs.js

Source:touch-id-e2e-specs.js Github

copy

Full Screen

...34 driver = await initSession(caps);35 await B.delay(2000); // Give the app a couple seconds to open36 });37 it('should not support touchID if not enrolled', async () => {38 let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');39 await authenticateButton.click();40 await driver.elementByName('TouchID not supported').should.eventually.exist;41 });42 it('should accept matching fingerprint if touchID is enrolled or it should not be supported if phone doesn\'t support touchID', async () => {43 await driver.toggleTouchIdEnrollment();44 let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');45 await authenticateButton.click();46 await driver.touchId(true);47 try {48 await driver.elementByName('Authenticated Successfully').should.eventually.exist;49 } catch (ign) {50 await driver.elementByName('TouchID not supported').should.eventually.exist;51 }52 await driver.toggleTouchIdEnrollment();53 });54 it('should reject not matching fingerprint if touchID is enrolled or it should not be supported if phone doesn\'t support touchID', async () => {55 await driver.toggleTouchIdEnrollment();56 let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');57 await authenticateButton.click();58 await driver.touchId(false);59 try {60 await driver.elementByName('Try Again').should.eventually.exist;61 } catch (ign) {62 await driver.elementByName('TouchID not supported').should.eventually.exist;63 }64 await driver.toggleTouchIdEnrollment();65 });66 it('should enroll touchID and accept matching fingerprints then unenroll touchID and not be supported', async () => {67 // Don't enroll68 let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');69 await authenticateButton.click();70 await driver.elementByName('TouchID not supported').should.eventually.exist;71 let okButton = await driver.elementByName('OK');72 await okButton.click();73 await B.delay(1000);74 // Enroll75 await driver.toggleTouchIdEnrollment();76 await authenticateButton.click();77 await driver.touchId(true);78 try {79 await driver.elementByName('Authenticated Successfully').should.eventually.exist;80 } catch (ign) {81 return await driver.elementByName('TouchID not supported').should.eventually.exist;82 }83 okButton = await driver.elementByName('OK');84 await okButton.click();85 await B.delay(1000);86 // Unenroll87 await driver.toggleTouchIdEnrollment();88 authenticateButton = await driver.elementByName(' Authenticate with Touch ID');89 await authenticateButton.click();90 await driver.elementByName('TouchID not supported').should.eventually.exist;91 });92 });...

Full Screen

Full Screen

attributes-specs.js

Source:attributes-specs.js Github

copy

Full Screen

...16 .should.become("Animation")17 .nodeify(done);18 });19 it('should be able to find name attribute', function (done) {20 driver.elementByName('Animation').getAttribute('name')21 .should.become("Animation")22 .nodeify(done);23 });24 it('should be able to find name attribute, falling back to text', function (done) {25 driver26 .elementByName('Animation').click()27 .elementsByClassName('android.widget.TextView')28 .then(function (els) { return els[1].getAttribute('name'); })29 .should.become("Bouncing Balls")30 .back()31 .nodeify(done);32 });33 it('should be able to find displayed attribute', function (done) {34 driver...

Full Screen

Full Screen

valet_page.js

Source:valet_page.js Github

copy

Full Screen

2var ValetPage = function () {3 return {4 // assertions5 assert : function (driver) {6 return driver.elementByName('Valet Parking').should.eventually.exist;7 },8 checkTicketNumberEntered : function (driver, ticketNumber) {9 return driver.elementByName(ticketNumber).should.exist;10 },11 checkRequestMyCarAlert : function (driver) {12 return driver.elementByName('Please confirm your request for car pickup.').should.exist;13 },14 checkRequestMyCarAlertErrorOccurred : function (driver) {15 return driver.elementByName('Unable to request your car.').should.exist;16 },17 // actions18 clickClose : function (driver) {19 return driver.elementByName('CloseButton').click();20 },21 clickSave : function (driver) {22 return driver.elementByName('Save').click();23 },24 clickCancel : function (driver) {25 return driver.elementByName('Cancel').click();26 },27 clickDone : function (driver) {28 return driver.elementByName('Done').click();29 },30 clickRequestMyCarConfirm : function (driver) {31 return driver.acceptAlert();32 },33 clickRequestMyCarCancel : function (driver) {34 return driver.dismissAlert();35 },36 clickRequestMyCar : function (driver) {37 return driver.elementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[2]/UIAButton[1]").click();38 },39 clickRequestMyCarAlertErrorOccurredDismiss : function (driver) {40 return driver.elementByName('OK').click();41 },42 enterTicketNumber : function (driver, ticketNumber) {43 return driver.elementByClassName('UIATextField').sendKeys(ticketNumber);44 }45 };46};...

Full Screen

Full Screen

calendar-e2e-specs.js

Source:calendar-e2e-specs.js Github

copy

Full Screen

...16 });17 it('should authorize calendar access if calendarAccessAuthorized == true', async () => {18 caps.calendarAccessAuthorized = true;19 driver = await initSession(caps);20 let checkCalendarButton = await driver.elementByName('Check calendar authorized');21 await checkCalendarButton.click();22 await driver.elementByName('authorized');23 });24 it('should disable calendar access if calendarAccessAuthorized == false', async () => {25 caps.calendarAccessAuthorized = false;26 driver = await initSession(caps);27 let checkCalendarButton = await driver.elementByName('Check calendar authorized');28 await checkCalendarButton.click();29 await driver.elementByName('not authorized');30 });31 });...

Full Screen

Full Screen

home_page.js

Source:home_page.js Github

copy

Full Screen

2var HomePage = function () {3 return {4 // assertions5 assert : function (driver) {6 return driver.elementByName('My Stay').should.eventually.exist;7 },8 checkInIsShown : function (driver) {9 return driver.elementByName('Check-in').should.eventually.exist;10 },11 roomKeyIsShown : function (driver) {12 return driver.elementByName('Room Key').should.eventually.exist;13 },14 // actions15 clickMenu : function (driver) {16 return driver.elementByName('Hamburger').click();17 },18 clickSignOut : function (driver) {19 return driver.elementByName('Logout').click();20 },21 clickValet : function (driver) {22 return driver.elementByName('Valet Service').click();23 }24 };25};...

Full Screen

Full Screen

room_key_page.js

Source:room_key_page.js Github

copy

Full Screen

2var RoomKeyPage = function () {3 return {4 // assertions5 assert : function (driver) {6 return driver.elementByName('Room Key').should.eventually.exist;7 },8 // actions9 confirmation : function (driver) {10 return driver.elementByName('You\'re checked in.').should.eventually.exist;11 },12 clickDone : function (driver) {13 return driver.elementByName('Done').click();14 },15 clickClose : function (driver) {16 return driver.elementByName('CloseButton').click();17 }18 }19};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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();11var webdriver = require('selenium-webdriver');12 build();13driver.findElement(webdriver.By.id('q')).sendKeys('webdriver');14driver.findElement(webdriver.By.id('btnG')).click();15driver.wait(function() {16 return driver.getTitle().then(function(title) {17 return title === 'webdriver - Google Search';18 });19}, 1000);20driver.quit();21var webdriver = require('selenium-webdriver');22 build();23driver.wait(function() {24 return driver.getTitle().then(function(title) {25 return title === 'webdriver - Google Search';26 });27}, 1000);28driver.quit();29var webdriver = require('selenium-webdriver');30 build();31driver.findElement(webdriver.By.xpath

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const {exec} = require('child_process');5chai.use(chaiAsPromised);6chai.should();7const serverConfig = {8};9const desiredCaps = {10};11const driver = wd.promiseChainRemote(serverConfig);12before(async () => {13 await driver.init(desiredCaps);14});15after(async () => {16 await driver.quit();17});18it('should find an element by name', async () => {19 const element = await driver.elementByName('username');20 await element.click();21});22describe('My first test', () => {23 it('should find an element by name', async () => {24 const element = await driver.elementByName('username');25 await element.click();26 });27});28describe('My first test', () => {29 it('should find an element by name', async () => {30 const element = await driver.elementByName('username');31 await element.click();32 });33});

Full Screen

Using AI Code Generation

copy

Full Screen

1const webdriverio = require('webdriverio');2const assert = require('assert');3const opts = {4 capabilities: {5 }6};7async function main() {8 const client = await webdriverio.remote(opts);9 await client.init();10 const el = await client.elementByName('myButton');11 assert(el);12 await client.end();13}14main();15info: [debug] [JSONWP Proxy] Got response with status 200: {"value":{"ELEMENT":"0.0.1"},"sessionId":"0C5F5C16-8E1E-4F9C-B5D5-5A5F5E0C3B7D","status":0}16{17 "value": {18 },

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();10var webdriver = require('selenium-webdriver'),11 until = webdriver.until;12var driver = new webdriver.Builder()13 .forBrowser('chrome')14 .build();15driver.findElement(By.name('q')).sendKeys('webdriver');16driver.findElement(By.name('btnG')).click();17driver.wait(until.titleIs('webdriver - Google Search'), 1000);18driver.quit();19var webdriver = require('selenium-webdriver'),20 until = webdriver.until;21var driver = new webdriver.Builder()22 .forBrowser('chrome')23 .build();24driver.findElement(By.name('q')).sendKeys('webdriver');25driver.findElement(By.name('btnG')).click();26driver.wait(until.titleIs('webdriver - Google Search'), 1000);27driver.quit();28var webdriver = require('selenium-webdriver'),29 until = webdriver.until;30var driver = new webdriver.Builder()31 .forBrowser('chrome')32 .build();33driver.findElement(By.name('q')).sendKeys('webdriver');34driver.findElement(By.name('btnG')).click();35driver.wait(until.titleIs('webdriver - Google Search'), 1000);36driver.quit();37var webdriver = require('selenium

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = require('appium-xcuitest-driver').driver;2var desiredCaps = {3};4driver.createSession(desiredCaps).then(function (session) {5 return driver.elementByName('Button');6}).then(function (element) {7 console.log(element);8 driver.quit();9});10var driver = require('appium-xcuitest-driver').driver;11var desiredCaps = {12};13driver.createSession(desiredCaps).then(function (session) {14 return driver.elementByAccessibilityId('Button');15}).then(function (element) {16 console.log(element);17 driver.quit();18});19at elementByAccessibilityId$ (node_modules/appium-xcuitest-driver/node_modules/appium-base-driver/lib/basedriver/commands/find.js:214:11)20at tryCatch (/Users/username/node_modules/babel-runtime/regenerator/runtime.js:67:40)21at GeneratorFunctionPrototype.invoke [as _invoke] (/Users/username/node_modules/babel-runtime/regenerator/runtime.js:315:22)22at GeneratorFunctionPrototype.prototype.(anonymous function) [as next]

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var driver = wd.promiseChainRemote('localhost', 4723);3driver.init({4}).then(function(){5 driver.elementByName('button').click();6});7 at XCUITestDriver.callee$0$0$ (../../lib/commands/find.js:40:13)8 at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)9 at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)10 at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)11 at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)12 at run (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/es6.promise.js:104:47)13 at flush (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/node_modules/core-js/library/modules/$.microtask.js:19:5)14 at _combinedTickCallback (internal/process/next_tick.js:131:7)15 at process._tickDomainCallback (internal/process/next_tick.js:218:9)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var desiredCaps = {7};8driver.init(desiredCaps).then(function() {9 return driver.elementByName('IntegerA');10}).then(function() {11 return driver.elementByName('IntegerB');12}).then(function() {13 return driver.elementByName('ComputeSumButton');14}).then(function() {15 return driver.elementByName('Answer');16}).then(function() {17 return driver.quit();18}).done();19info: [debug] [BaseDriver] Event 'newSessionRequested' logged at 1500746818553 (15:00:18 GMT+0530 (IST))20info: [Appium] Creating new XCUITestDriver (v2.7.0) session21info: [debug] [BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities {"deviceName":"iPhone 6","plat... were provided

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const { assert } = require('chai');3const { getDriver } = require('../helpers/driver');4describe('elementByName', function () {5 let driver;6 before(async function () {7 driver = await getDriver();8 });9 after(async function () {10 await driver.quit();11 });12 it('should find element by name', async function () {13 const element = await driver.elementByName('Buttons');14 const name = await element.getAttribute('name');15 assert.equal(name, 'Buttons');16 });17});18const wd = require('wd');19const { HOST, PORT, DEVICE_NAME, PLATFORM_NAME, PLATFORM_VERSION, UDID } = require('../config');20const driver = wd.promiseChainRemote(HOST, PORT);21const getDriver = async () => {22 await driver.init({

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = {4};5 .init(desired)6 .then(function () {7 return driver.elementByName('test');8 })9 .then(function (el) {10 return el.click();11 })12 .then(function () {13 return driver.quit();14 })15 .done();

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