How to use driver.elementByTagName method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

tests.js

Source:tests.js Github

copy

Full Screen

...66 });67};68let localTest = async function (driver, url) {69 await driver.get(url);70 let h1 = await driver.elementByTagName('h1');71 (await h1.text()).should.containEql('the server of awesome');72};73tests.webTestConnect = async function (driver) {74 await localTest(driver, 'http://localhost:8000');75};76tests.webTestLocalName = async function (driver, caps, opts) {77 let host = opts.localname;78 if (!host || host === '' || host === 'localhost') {79 throw new Error("Can't run local name test without an interesting " +80 "hostname. Please use the 'localname' option.");81 }82 await localTest(driver, 'http://' + host + ':8000');83};84tests.webTestHttps = async function (driver) {85 await driver.get('https://buildslave.saucelabs.com');86 await driver.waitFor(titleToMatch('Sauce Labs'), 10000, 1000);87};88tests.webTestHttpsSelfSigned = async function (driver) {89 await driver.get('https://selfsigned.buildslave.saucelabs.com');90 await driver.waitFor(titleToMatch('Sauce Labs'), 10000, 1000);91};92tests.webTestHttpsSelfSigned.extraCaps = {93 keepKeyChains: true94};95tests.iosTest = async function (driver, caps) {96 let appium1 = isAppium1(caps);97 let fs;98 if (appium1) {99 // we might get an alert saying the app is slow, click the OK button100 // if it's there101 if (parseFloat(caps.platformVersion) < 10.2) {102 try {103 await driver.elementByAccessibilityId('OK').click();104 } catch (ign) {}105 }106 fs = await driver.elementsByClassName('UIATextField');107 } else {108 fs = await driver.elementsByTagName('textField');109 }110 // some early versions of appium didn't filter out the extra text fields111 // that UIAutomation started putting in, so make the test sensitive112 // to that113 let firstField = fs[0], secondField;114 if (fs.length === 2) {115 secondField = fs[1];116 } else if (fs.length === 4) {117 secondField = fs[2];118 } else {119 throw new Error('Got strange number of fields in testapp: ' + fs.length);120 }121 await firstField.sendKeys('4');122 await secondField.sendKeys('5');123 if (appium1) {124 await driver.elementByClassName('UIAButton').click();125 } else {126 await driver.elementByTagName('button').click();127 }128 let text;129 if (appium1) {130 text = await driver.elementByClassName('UIAStaticText').text();131 } else {132 text = await driver.elementByTagName('staticText').text();133 }134 text.should.equal('9');135};136async function iosCycle (driver, caps) {137 let appium1 = isAppium1(caps);138 let el;139 if (appium1) {140 el = await driver.elementByClassName('UIATextField');141 } else {142 el = await driver.elementByTagName('textField');143 }144 await el.sendKeys('123');145 await el.clear();146}147tests.iosSendKeysStressTest = async function (driver, caps) {148 try {149 await driver.elementByAccessibilityId('OK').click();150 } catch (ign) {}151 for (let i = 0; i < (process.env.STRESS_TIMES || 50); i++) {152 try {153 await iosCycle(driver, caps);154 } catch (e) {155 throw new Error(`Failure on stress run ${i}: ${e}`);156 }157 }158};159tests.iosHybridTest = async function (driver, caps) {160 if (!isAppium1(caps)) {161 throw new Error('Hybrid test only works with Appium 1 caps');162 }163 await selectWebview(driver);164 await driver.get('https://google.com');165 await driver.waitFor(titleToMatch('Google'), 10000, 1000);166 await driver.context('NATIVE_APP');167 (await driver.source()).should.containEql('<AppiumAUT>');168};169tests.iosLocServTest = async function (driver) {170 await retryInterval(5, 1000, async () => {171 let uiSwitch = await driver.elementByClassName('UIASwitch');172 let res = await uiSwitch.getAttribute('value');173 [1, true].should.containEql(res);174 });175};176tests.iosLocServTest.extraCaps = {177 locationServicesAuthorized: true,178 locationServicesEnabled: true,179 bundleId: 'io.appium.TestApp'180};181tests.iosIwd = async function (driver, caps) {182 let appium1 = isAppium1(caps);183 let times = 30, timings = [];184 const maxTimeMs = 900;185 const loop = async () => {186 let start = Date.now();187 if (appium1) {188 await driver.elementsByClassName('UIATextField');189 } else {190 await driver.elementsByTagName('textField');191 }192 return Date.now() - start;193 };194 for (let i = 0; i < times; i++) {195 timings.push(await loop());196 }197 const avgTime = _.sum(timings) / times;198 if (avgTime > maxTimeMs) {199 throw new Error(`Expected average command time to be no greater than ` +200 `${maxTimeMs}ms but it was ${avgTime}ms`);201 }202};203tests.androidTest = async function (driver, caps) {204 await androidCycle(driver, caps);205};206tests.androidLongTest = async function (driver, caps) {207 for (let i = 0; i < 15; i++) {208 await androidCycle(driver, caps);209 }210};211tests.androidLoadTest = async function (driver) {212 const iterations = 20; // 10 minute runtime213 const intervalMs = 30000;214 let args = await driver.elementById('textOptions');215 let goBtn = await driver.elementById('go');216 await args.clear();217 await args.sendKeys(`-M 500 -v 20 -s ${Math.floor(iterations * intervalMs / 1000)}`);218 for (let i = 0; i < iterations; i++) {219 // Only the first click triggers the test, the rest of the clicks are ignored220 // and only to keep the session open whilst the test is running221 await goBtn.click();222 await driver.sleep(30000);223 }224};225async function androidCycle (driver, caps) {226 let appium1 = isAppium1(caps);227 if (appium1) {228 await driver.elementByAccessibilityId('Add Contact').click();229 } else {230 await driver.elementByName('Add Contact').click();231 }232 let fs;233 if (appium1) {234 fs = await driver.elementsByClassName('android.widget.EditText');235 } else {236 fs = await driver.elementsByTagName('textfield');237 }238 await fs[0].sendKeys('My Name');239 await fs[2].sendKeys('someone@somewhere.com');240 // do contains search since RDC adds weird extra edit text241 (await fs[0].text()).should.containEql('My Name');242 (await fs[2].text()).should.containEql('someone@somewhere.com');243 await driver.back();244 await driver.sleep(2);245 let text;246 if (appium1) {247 text = await driver.elementByClassName('android.widget.Button').text();248 } else {249 text = await driver.elementByTagName('button').text();250 }251 ['Add Contact', 'Save'].should.containEql(text);252 let cb = null;253 try {254 if (appium1) {255 cb = await driver.elementByXPath('//android.widget.CheckBox');256 } else {257 cb = await driver.elementByXPath('//checkBox');258 }259 } catch (e) {}260 if (cb) {261 await cb.click();262 'Show Invisible Contacts (Only)'.should.equal(await cb.text());263 }264}265tests.selendroidTest = async function (driver) {266 await driver.elementById('buttonStartWebView').click();267 await driver.elementByClassName('android.webkit.WebView');268 await selectWebview(driver);269 await driver.sleep(6);270 let f = await driver.elementById('name_input');271 try {272 // selendroid #492, sometimes this errors273 await f.clear();274 } catch (e) {}275 await f.sendKeys('Test string');276 // test against lowercase to handle selendroid + android 4.0 bug277 (await f.getAttribute('value')).toLowerCase().should.containEql('test string');278 await driver.elementByCss('input[type=submit]').click();279 await driver.sleep(3);280 let h1Text = await driver.elementByTagName('h1').text();281 // some versions of selendroid have a bug where this is the empty string282 h1Text.should.match(/()|(This is my way of saying hello)/);283};284tests.androidHybridTest = async function (driver) {285 await selectWebview(driver);286 let el = await driver.elementById('i_am_a_textbox');287 await el.clear();288 await el.sendKeys('Test string');289 let refreshedEl = await driver.elementById('i_am_a_textbox');290 // test against lowercase to handle selendroid + android 4.0 bug291 'test string'.should.equal((await refreshedEl.getAttribute('value')).toLowerCase());292};...

Full Screen

Full Screen

safari-window-e2e-specs.js

Source:safari-window-e2e-specs.js Github

copy

Full Screen

...86 });87 it('should switch to frame by name', async () => {88 await driver.frame('first');89 (await driver.title()).should.be.equal('Frameset guinea pig');90 let h1 = await driver.elementByTagName('h1');91 (await h1.text()).should.be.equal('Sub frame 1');92 });93 it('should switch to frame by index', async () => {94 await driver.frame(1);95 (await driver.title()).should.be.equal('Frameset guinea pig');96 let h1 = await driver.elementByTagName('h1');97 (await h1.text()).should.be.equal('Sub frame 2');98 });99 it('should switch to frame by id', async () => {100 await driver.frame('frame3');101 (await driver.title()).should.be.equal('Frameset guinea pig');102 let h1 = await driver.elementByTagName('h1');103 (await h1.text()).should.be.equal('Sub frame 3');104 });105 it('should switch back to default content from frame', async () => {106 await driver.frame('first');107 (await driver.title()).should.be.equal('Frameset guinea pig');108 let h1 = await driver.elementByTagName('h1');109 (await h1.text()).should.be.equal('Sub frame 1');110 await driver.frame(null);111 (await driver.elementByTagName('frameset')).should.exist;112 });113 it('should switch to child frames', async () => {114 await driver.frame('third');115 (await driver.title()).should.be.equal('Frameset guinea pig');116 await driver.frame('childframe');117 (await driver.elementById('only_on_page_2')).should.exist;118 });119 it('should execute javascript in frame', async () => {120 await driver.frame('first');121 (await driver.execute(GET_ELEM_SYNC)).should.be.equal('Sub frame 1');122 });123 it.skip('should execute async javascript in frame', async () => {124 await driver.frame('first');125 (await driver.executeAsync(GET_ELEM_ASYNC)).should.be.equal('Sub frame 1');126 });127 });128 describe('iframes', function () {129 beforeEach(async () => {130 await driver.get(GUINEA_PIG_IFRAME_PAGE);131 });132 it('should switch to iframe by name', async () => {133 await driver.frame('iframe1');134 (await driver.title()).should.be.equal('Iframe guinea pig');135 let h1 = await driver.elementByTagName('h1');136 (await h1.text()).should.be.equal('Sub frame 1');137 });138 it('should switch to iframe by index', async () => {139 await driver.frame(1);140 (await driver.title()).should.be.equal('Iframe guinea pig');141 let h1 = await driver.elementByTagName('h1');142 (await h1.text()).should.be.equal('Sub frame 2');143 });144 it('should switch to iframe by id', async () => {145 await driver.frame('id-iframe3');146 (await driver.title()).should.be.equal('Iframe guinea pig');147 let h1 = await driver.elementByTagName('h1');148 (await h1.text()).should.be.equal('Sub frame 3');149 });150 it('should switch to iframe by element', async () => {151 let frame = await driver.elementById('id-iframe3');152 await driver.frame(frame);153 (await driver.title()).should.be.equal('Iframe guinea pig');154 let h1 = await driver.elementByTagName('h1');155 (await h1.text()).should.be.equal('Sub frame 3');156 });157 it('should not switch to iframe by element of wrong type', async () => {158 let h1 = await driver.elementByTagName('h1');159 await driver.frame(h1).should.eventually.be.rejected;160 });161 it('should switch back to default content from iframe', async () => {162 await driver.frame('iframe1');163 (await driver.title()).should.be.equal('Iframe guinea pig');164 let h1 = await driver.elementByTagName('h1');165 (await h1.text()).should.be.equal('Sub frame 1');166 await driver.frame(null);167 (await driver.elementsByTagName('iframe')).should.have.length(3);168 });169 });...

Full Screen

Full Screen

find-element-tests.js

Source:find-element-tests.js Github

copy

Full Screen

...76 });77 it('should find an element from another element', async function () {78 let el = await driver.elementById('iframe1');79 let title = await el.elementByTagName('title');80 let earlierTitle = await driver.elementByTagName('title');81 (await earlierTitle.equals(title)).should.equal(false);82 });83 it('should find multiple elements from another element', async function () {84 let el = await driver.elementByTagName('html');85 let titles = await el.elementsByTagName('title');86 titles.length.should.equal(2);87 });88 it('should not find an element that doesnt exist from another element', async function () {89 let el = await driver.elementByTagName('html');90 await el.elementByTagName('marquee')91 .should.eventually.be.rejectedWith(/7/);92 });93 it('should not find multiple elements that dont exist from another element', async function () {94 let el = await driver.elementByTagName('html');95 (await el.elementsByTagName('marquee')).should.eql([]);96 });97 it('should not find an element with bad strategy from another element', async function () {98 await driver.elementByTagName('html').elementByCss('.sorry')99 .should.eventually.be.rejectedWith(/9/);100 });101 it('should not find elements with bad strategy from another element', async function () {102 await driver.elementByTagName('html').elementsByCss('.sorry')103 .should.eventually.be.rejectedWith(/9/);104 });105 it('should error if root element is not valid', async function () {106 let el = await driver.elementByTagName('html');107 el.value = 'foobar';108 await el.elementByTagName('body').should.eventually.be.rejectedWith(/10/);109 });110 });111}...

Full Screen

Full Screen

salesforce-atom-timeout.js

Source:salesforce-atom-timeout.js Github

copy

Full Screen

...30 await driver.init(caps);31 const context = await driver.currentContext();32 console.log('context:', context);33 await driver.setImplicitWaitTimeout(5000);34 await driver.elementByTagName('body');35 const res = await driver.execute(`return document.readyState == 'complete'`);36 console.log('ready state:', res);37 await driver.elementByTagName('body');38 await driver.url('http://www.google.com');39 if (process.env.CLOUD)40 await driver.sauceJobStatus(true);41 } catch(e) {42 failureCount++;43 console.error(e);44 if (process.env.CLOUD)45 await driver.sauceJobStatus(false);46 } finally {47 await driver.quit();48 }49 }50 let failureCount = 0;51 for (let i=0; i<100; i++) {...

Full Screen

Full Screen

element.js

Source:element.js Github

copy

Full Screen

...43 } catch (err) {44 e = err;45 }46 e.message.should.include("7");47 yield driver.elementByTagName("nowaydude");48 }).nodeify(function(err) {49 should.exist(err);50 err.message.should.include("NoSuchElement");51 done();52 });53 });54 it('should defer findElement if requested', function*() {55 yield driver.get(baseUrl + "guinea-pig.html");56 yield driver.elementByLinkText("i am a link").click();57 (yield driver.title()).should.equal("I am another page title");58 yield driver.back();59 var text = yield driver.elementByTagName('body').elementById('the_forms_id')60 .elementByTagName('input').getValue();61 text.should.equal("i has no focus");62 });...

Full Screen

Full Screen

jetpack-componse-element-values-e2e-specs.js

Source:jetpack-componse-element-values-e2e-specs.js Github

copy

Full Screen

...23 let el = await driver.elementByXPath("//*[@text='Text Input Components']");24 await driver.moveTo(el);25 await el.click();26 await driver.updateSettings({ driver: 'compose' });27 let textElement = await driver.elementByTagName('text_input');28 // verify default text29 await textElement.text().should.eventually.equal('Enter your text here');30 await textElement.setImmediateValue(['hello']);31 // should append to the exiting text32 await driver.elementByTagName('text_input').text().should.eventually.equal('Enter your text herehello');33 textElement.setText(['テスト']);34 // should replace existing text35 await textElement.text().should.eventually.equal('テスト');36 textElement.clear();37 // should clear existing text38 await textElement.text().should.eventually.equal('');39 });...

Full Screen

Full Screen

implicit-wait-base.js

Source:implicit-wait-base.js Github

copy

Full Screen

1"use strict";2var setup = require("../setup-base");3module.exports = function (desired) {4 describe('implicit wait', function () {5 var driver;6 setup(this, desired, {'no-reset': true}).then(function (d) { driver = d; });7 it('should set the implicit wait for finding web elements', function (done) {8 driver9 .setImplicitWaitTimeout(7 * 1000)10 .then(function () {11 var before = new Date().getTime() / 1000;12 return driver13 .elementByTagName('notgonnabethere')14 .should.be.rejectedWith(/status: 7/)15 .then(function () {16 var after = new Date().getTime() / 1000;17 // commenting this, it doesn't make sense18 //((after - before) < 9).should.be.ok;19 ((after - before) > 7).should.be.ok;20 });21 }).finally(function () {22 return driver.setImplicitWaitTimeout(0);23 }).nodeify(done);24 });25 });...

Full Screen

Full Screen

TestComponent.js

Source:TestComponent.js Github

copy

Full Screen

...6checkRecapSituationContains: function(textToLookFor) {7 return this.resultsFrame.then(function(frame) {8 return driver.frame(frame);9 }).then(function() {10 return driver.elementByTagName('div');11 }).then(function(recapSituation) {12 return driver.textPresent(textToLookFor, recapSituation);13 }).then(function(isPresent) {14 if (! isPresent)15 throw '"' + textToLookFor + '" could not be found in the situation recap';16 });...

Full Screen

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);6chai.should();7var desired = {8};9var driver = wd.promiseChainRemote('localhost', 4723);10driver.init(desired).then(function () {11 return driver.elementByTagName('XCUIElementTypeButton').should.eventually.exist;12}).should.notify(done);13 at Object.wrappedLogger.errorAndThrow (lib/logging.js:62:13)14 at tryCatcher (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/release/util.js:16:23)15 at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/release/promise.js:512:31)16 at Promise._settlePromise (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/release/promise.js:569:18)17 at Promise._settlePromise0 (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/release/promise.js:614:10)18 at Promise._settlePromises (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/release/promise

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('wd');2var assert = require('assert');3var desired = {4 app: '/Users/{username}/Desktop/ios-sample-code/HelloWorld/build/Release-iphonesimulator/HelloWorld.app'5};6driver.init(desired).then(function () {7 return driver.elementByTagName('XCUIElementTypeButton');8}).then(function (el) {9 return el.click();10}).fin(function () {11 return driver.quit();12}).done();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = require('./desired');4var _ = require('underscore');5 .init(desired)6 .then(function () {7 return browser.elementByTagName('XCUIElementTypeOther');8 })9 .then(function (el) {10 return el.getAttribute('name');11 })12 .then(function (text) {13 assert.equal(text, "Other");14 })15 .fin(function () { return browser.quit(); })16 .done();17module.exports = {18};19{20 "scripts": {21 },22 "dependencies": {23 }24}25var webdriver = require('wd');26var assert = require('assert');27var desired = require('./desired');28 .init(desired)29 .then(function () {30 return browser.elementByTagName('XCUIElementTypeOther');31 })32 .then(function (el) {33 return el.getAttribute('name');34 })35 .then(function (text) {36 assert.equal(text, "Other");37 })38 .fin(function () { return browser.quit(); })39 .done();

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 expect = chai.expect;7var desired = {8};9driver.init(desired).then(function () {10 return driver.elementByTagName('XCUIElementTypeButton');11}).then(function (el) {12 expect(el).to.exist;13 return driver.quit();14}).done();

Full Screen

Using AI Code Generation

copy

Full Screen

1console.log("Starting Appium Xcuitest Driver test");2var wd = require('wd');3var assert = require('assert');4var desiredCaps = {5}6var driver = wd.promiseChainRemote("localhost", 4723);7driver.init(desiredCaps)8 .then(function () {9 return driver.elementByTagName("XCUIElementTypeStaticText");10 })11 .then(function (el) {12 return el.text();13 })14 .then(function (text) {15 console.log("Text value is: " + text);16 assert.equal(text, "Label");17 })18 .fin(function () {19 driver.quit();20 })21 .done();22info: [debug] [BaseDriver] Event 'newSessionRequested' logged at 1509521909735 (12:31:49 GMT+0530 (IST))23info: [Appium] Creating new XCUITestDriver (v2.28.0) session24info: [debug] [BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities {"platformName":"iOS","platformVersion":"11.0","deviceName":"iPhone 7","app":"/Users/

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = {4};5driver.init(desired).then(function () {6}).then(function () {7 return driver.elementByTagName('h1').text();8}).then(function (text) {9 assert.equal(text, 'Appium: Mobile App Automation Made Awesome.');10}).fin(function () { return driver.quit(); })11 .done();12In the code above, we use the driver.elementByTagName method to get the h1 element on the Appium home page. The driver.elementByTagName method takes a string as an argument, which is the tag name of the element to be found. In the code above, we pass in the string "h1" to the driver.elementByTagName method. The driver.elementByTagName method returns a promise that will be fulfilled with the element found. We then use the .text() method on the element to get the text of the element. We then assert that the text of the element is equal to the expected text "App

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