How to use driver.elements method in Appium

Best JavaScript code snippet using appium

find-e2e-specs.js

Source:find-e2e-specs.js Github

copy

Full Screen

...277 // if we don't pause, WDA freaks out sometimes, especially on fast systems278 await B.delay(500);279 });280 it('should find visible elements', async function () {281 let els = await driver.elements('-ios predicate string', 'visible = 1');282 els.should.have.length.above(0);283 });284 it('should find invisible elements', async function () {285 let els = await driver.elements('-ios predicate string', 'visible = 0');286 els.should.have.length.above(0);287 });288 it('should find elements with widths above 0', async function () {289 let els = await driver.elements('-ios predicate string', 'wdRect.width >= 0');290 els.should.have.length.above(0);291 });292 it('should find elements with widths between 100 and 200', async function () {293 let els = await driver.elements('-ios predicate string', 'wdRect.width BETWEEN {100,200}');294 els.should.have.length.above(0);295 });296 it('should find elements that end in the word "View" in the name', async function () {297 let els = await driver.elements('-ios predicate string', "wdName LIKE '* View'");298 els.should.have.length.above(1);299 });300 it('should find elements that have x and y coordinates greater than 0', async function () {301 let els = await driver.elements('-ios predicate string', 'wdRect.x >= 0 AND wdRect.y >= 0');302 els.should.have.length.above(1);303 });304 });305 describe('by class chain', function () {306 before(async function () {307 // if we don't pause, WDA freaks out sometimes, especially on fast systems308 await B.delay(500);309 });310 it('should find elements', async function () {311 let els = await driver.elements('-ios class chain', 'XCUIElementTypeWindow');312 els.should.have.length.above(0);313 });314 it('should find child elements', async function () {315 let els = await driver.elements('-ios class chain', 'XCUIElementTypeWindow/*');316 els.should.have.length.above(0);317 });318 it('should find elements with index', async function () {319 let els1 = await driver.elements('-ios class chain', 'XCUIElementTypeWindow[1]/*');320 let els2 = await driver.elements('-ios class chain', 'XCUIElementTypeWindow/*');321 els1.should.have.length(els2.length);322 });323 it('should find elements with negative index', async function () {324 let els = await driver.elements('-ios class chain', 'XCUIElementTypeWindow/*[-1]');325 els.should.have.length(1);326 });327 });328 describe('magic first visible child xpath', function () {329 it('should find the first visible child of an element', async function () {330 let el = await driver.elementByClassName('XCUIElementTypeTable');331 let child = await el.elementByXPath('/*[@firstVisible="true"]');332 await child.getAttribute("type").should.eventually.eql("XCUIElementTypeCell");333 // do another call and double-check the different quote/spacing works334 let grandchild = await child.elementByXPath("/*[@firstVisible = 'true']");335 await grandchild.getAttribute("name").should.eventually.eql("Action Sheets");336 });337 });338 describe('magic scrollable descendents xpath', function () {...

Full Screen

Full Screen

find-element-specs.js

Source:find-element-specs.js Github

copy

Full Screen

...111 }).nodeify(done);112 });113 });114 it('should return an array of one element if the plural "elements" is used', function (done) {115 driver.elements('accessibility id', 'UICatalog').then(function (els) {116 els.length.should.equal(2);117 }).nodeify(done);118 });119 });120 describe('findElementsByClassName', function () {121 it('should return all image elements with internally generated ids', function (done) {122 driver.elementsByClassName('UIAImage').then(function (els) {123 els.length.should.be.above(0);124 _(els).each(function (el) {125 el.should.exist;126 });127 }).nodeify(done);128 });129 });...

Full Screen

Full Screen

by-uiautomator-e2e-specs.js

Source:by-uiautomator-e2e-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import { APIDEMOS_CAPS } from '../../desired';4import { initDriver } from '../../helpers/session';5chai.should();6chai.use(chaiAsPromised);7describe('Find - uiautomator', function () {8 let driver;9 before(async function () {10 driver = await initDriver(APIDEMOS_CAPS);11 await driver.updateSettings({'enableNotificationListener': false});12 await driver.setImplicitWaitTimeout(20000);13 });14 after(async function () {15 await driver.quit();16 });17 it('should find elements with a boolean argument', async function () {18 await driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true)')19 .should.eventually.have.length.at.least(10);20 });21 it('should find elements within the context of another element', async function () {22 let els = await driver23 .elementsByAndroidUIAutomator('new UiSelector().className("android.widget.TextView")');24 els.length.should.be.above(8);25 els.length.should.be.below(14);26 });27 it('should find elements without prepending "new UiSelector()"', async function () {28 await driver.elementsByAndroidUIAutomator('.clickable(true)')29 .should.eventually.have.length.at.least(10);30 });31 it('should find elements without prepending "new UiSelector()"', async function () {32 await driver.elementsByAndroidUIAutomator('clickable(true)')33 .should.eventually.have.length.at.least(10);34 });35 it('should find elements without prepending "new "', async function () {36 await driver.elementsByAndroidUIAutomator('UiSelector().clickable(true)')37 .should.eventually.have.length.at.least(10);38 });39 it('should ignore trailing semicolons', async function () {40 await driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true);')41 .should.eventually.have.length.at.least(10);42 });43 it('should find an element with an int argument', async function () {44 let el = await driver.elementByAndroidUIAutomator('new UiSelector().index(0)');45 await el.getAttribute('className').should.eventually.equal('android.widget.FrameLayout');46 });47 it('should find an element with a string argument', async function () {48 await driver49 .elementByAndroidUIAutomator('new UiSelector().description("Animation")')50 .should.eventually.exist;51 });52 it('should find an element with an overloaded method argument', async function () {53 await driver.elementsByAndroidUIAutomator('new UiSelector().className("android.widget.TextView")')54 .should.eventually.have.length.at.least(10);55 });56 it('should find an element with a Class<T> method argument', async function () {57 await driver.elementsByAndroidUIAutomator('new UiSelector().className(android.widget.TextView)')58 .should.eventually.have.length.at.least(10);59 });60 it('should find an element with a long chain of methods', async function () {61 let el = await driver.elementByAndroidUIAutomator('new UiSelector().clickable(true).className(android.widget.TextView).index(1)');62 await el.text().should.eventually.equal('Accessibility');63 });64 it('should find an element with recursive UiSelectors', async function () {65 await driver.elementsByAndroidUIAutomator('new UiSelector().childSelector(new UiSelector().clickable(true)).focused(true)')66 .should.eventually.have.length(1);67 });68 it('should not find an element which does not exist', async function () {69 await driver.setImplicitWaitTimeout(1000); // expect this to fail, so no need to wait too long70 await driver.elementsByAndroidUIAutomator('new UiSelector().description("chuckwudi")')71 .should.eventually.have.length(0);72 await driver.setImplicitWaitTimeout(20000); // restore implicit wait73 });74 it('should allow multiple selector statements and return the Union of the two sets', async function () {75 let clickableEls = await driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true)');76 clickableEls.length.should.be.above(0);77 let notClickableEls = await driver.elementsByAndroidUIAutomator('new UiSelector().clickable(false)');78 notClickableEls.length.should.be.above(0);79 let both = await driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true); new UiSelector().clickable(false);');80 both.should.have.length(clickableEls.length + notClickableEls.length);81 });82 it('should allow multiple selector statements and return the Union of the two sets', async function () {83 let clickableEls = await driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true)');84 clickableEls.length.should.be.above(0);85 let clickableClickableEl = await driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true); new UiSelector().clickable(true);');86 clickableClickableEl.length.should.be.above(0);87 clickableClickableEl.should.have.length(clickableEls.length);88 });89 it('should find an element in the second selector if the first finds no elements (when finding multiple elements)', async function () {90 let selector = 'new UiSelector().className("not.a.class"); new UiSelector().className("android.widget.TextView")';91 const els = await driver.elementsByAndroidUIAutomator(selector);92 els.length.should.be.above(0);93 });94 it.skip('should find an element in the second selector if the first finds no elements (when finding a single element)', async function () {95 // TODO: This test is broken.96 // * The test above this one works and it proxies to 'POST /elements'.97 // * This test doesn't work and the only difference is that it proxies to 'POST /element'98 // (see find.js for reference)99 let selector = 'new UiSelector().className("not.a.class"); new UiSelector().className("android.widget.TextView")';100 await driver.elementByAndroidUIAutomator(selector).should.eventually.exist;101 });102 it('should scroll to, and return elements using UiScrollable', async function () {103 await driver.startActivity({appPackage: 'io.appium.android.apis', appActivity: '.view.List1'});104 let selector = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Beer Cheese").instance(0))';105 let el = await driver.elementByAndroidUIAutomator(selector);106 await el.text().should.eventually.equal('Beer Cheese');107 });108 it('should allow chaining UiScrollable methods', async function () {109 await driver.startActivity({appPackage: 'io.appium.android.apis', appActivity: '.view.List1'});110 let selector = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).setMaxSearchSwipes(11).scrollIntoView(new UiSelector().text("Beer Cheese").instance(0))';111 let el = await driver.elementByAndroidUIAutomator(selector);112 await el.text().should.eventually.equal('Beer Cheese');113 });114 it('should allow UiScrollable scrollIntoView', async function () {115 await driver.startActivity({appPackage: 'io.appium.android.apis', appActivity: '.view.List1'});116 let selector = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Beer Cheese").instance(0));';117 let el = await driver.elementByAndroidUIAutomator(selector);118 await el.text().should.eventually.equal('Beer Cheese');119 });120 it('should allow UiScrollable with unicode string', async function () {121 await driver.startActivity({appPackage: 'io.appium.android.apis', appActivity: '.text.Unicode'});122 let selector = 'new UiSelector().text("عربي").instance(0);';123 let el = await driver.elementByAndroidUIAutomator(selector);124 await el.text().should.eventually.equal('عربي');125 });...

Full Screen

Full Screen

by-uiautomator-specs.js

Source:by-uiautomator-specs.js Github

copy

Full Screen

1"use strict";2var setup = require("../../../common/setup-base")3 , desired = require("../desired")4 , Q = require("q");5describe("apidemo - find elements - by uiautomator", function () {6 var driver;7 setup(this, desired).then(function (d) { driver = d; });8 it('should find elements with a boolean argument', function (done) {9 driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true)').then(function (els) {10 els.length.should.be.above(10);11 }).nodeify(done);12 });13 it('should find elements within the context of another element', function (done) {14 driver15 .elementByClassName('android.widget.ListView').then(function (el) {16 el.elementsByAndroidUIAutomator('new UiSelector().className("android.widget.TextView")')17 .then(function (els) {18 els.length.should.be.above(8);19 els.length.should.be.below(12);20 });21 }).nodeify(done);22 });23 it('should find elements without prepending "new UiSelector()"', function (done) {24 driver.elementsByAndroidUIAutomator('.clickable(true)').then(function (els) {25 els.length.should.be.above(10);26 }).nodeify(done);27 });28 it('should find elements without prepending "new UiSelector()."', function (done) {29 driver.elementsByAndroidUIAutomator('clickable(true)').then(function (els) {30 els.length.should.be.above(10);31 }).nodeify(done);32 });33 it('should find elements without prepending "new "', function (done) {34 driver.elementsByAndroidUIAutomator('UiSelector().clickable(true)').then(function (els) {35 els.length.should.be.above(10);36 }).nodeify(done);37 });38 it('should ignore trailing semicolons', function (done) {39 driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true);')40 .then(function (els) {41 els.length.should.be.above(10);42 }).nodeify(done);43 });44 it('should find an element with an int argument', function (done) {45 driver.elementByAndroidUIAutomator('new UiSelector().index(0)').getTagName().then(function (tag) {46 tag.should.equal('android.widget.FrameLayout');47 }).nodeify(done);48 });49 it('should find an element with a string argument', function (done) {50 driver.elementByAndroidUIAutomator('new UiSelector().description("Animation")').then(function (el) {51 el.should.exist;52 }).nodeify(done);53 });54 it('should find an element with an overloaded method argument', function (done) {55 driver.elementsByAndroidUIAutomator('new UiSelector().className("android.widget.TextView")').then(function (els) {56 els.length.should.be.above(10);57 }).nodeify(done);58 });59 it('should find an element with a Class<T> method argument', function (done) {60 driver.elementsByAndroidUIAutomator('new UiSelector().className(android.widget.TextView)').then(function (els) {61 els.length.should.be.above(10);62 }).nodeify(done);63 });64 it('should find an element with a long chain of methods', function (done) {65 driver.elementByAndroidUIAutomator('new UiSelector().clickable(true).className(android.widget.TextView).index(1)').text().then(function (text) {66 text.should.equal('Accessibility');67 }).nodeify(done);68 });69 it('should find an element with recursive UiSelectors', function (done) {70 driver.elementsByAndroidUIAutomator('new UiSelector().childSelector(new UiSelector().clickable(true)).clickable(true)').then(function (els) {71 els.length.should.equal(1);72 }).nodeify(done);73 });74 it('should not find an element with bad syntax', function (done) {75 driver.elementByAndroidUIAutomator('new UiSelector().clickable((true)')76 .should.be.rejectedWith(/status: 9/)77 .nodeify(done);78 });79 it('should not find an element with a made up method', function (done) {80 driver.elementByAndroidUIAutomator('new UiSelector().drinkable(true)')81 .should.be.rejectedWith(/status: 9/)82 .nodeify(done);83 });84 it('should not find an element which does not exist', function (done) {85 driver.elementByAndroidUIAutomator('new UiSelector().description("chuckwudi")')86 .should.be.rejectedWith(/status: 7/)87 .nodeify(done);88 });89 it('should allow multiple selector statements and return the Union of the two sets', function (done) {90 var clickable =91 driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true)')92 .then(function (els) {93 els.length.should.be.above(0);94 return els.length;95 });96 var notClickable =97 driver.elementsByAndroidUIAutomator('new UiSelector().clickable(false)')98 .then(function (els) {99 els.length.should.be.above(0);100 return els.length;101 });102 var both =103 driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true); new UiSelector().clickable(false);')104 .then(function (els) {105 return els.length;106 });107 Q.all([clickable, notClickable, both]).then(function (vals) {108 var clickable = vals[0];109 var notClickable = vals[1];110 var both = vals[2];111 both.should.equal(clickable + notClickable);112 }).nodeify(done);113 });114 it('should remove duplicates when using multiple selectors', function (done) {115 var clickable = driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true)').then(function (els) {116 els.length.should.be.above(0);117 return els.length;118 }).fail(console.log);119 var clickableClickable = driver.elementsByAndroidUIAutomator('new UiSelector().clickable(true); new UiSelector().clickable(true);').then(function (els) {120 els.length.should.be.above(0);121 return els.length;122 }).fail(console.log);123 Q.all([clickable, clickableClickable]).then(function (vals) {124 vals[0].should.equal(vals[1]);125 }).nodeify(done);126 });127 it('should find an element in the second selector if the first finds no elements', function (done) {128 driver.elementByAndroidUIAutomator('new UiSelector().className("not.a.class"); new UiSelector().className("android.widget.TextView")')129 .then(function (el) {130 el.should.exist;131 }).nodeify(done);132 });133 it('should scroll to, and return elements using UiScrollable', function (done) {134 driver.elementByAndroidUIAutomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0))')135 .text()136 .then(function (text) {137 text.should.equal("Views");138 }).nodeify(done);139 });140 it('should allow chaining UiScrollable methods', function (done) {141 driver.elementByAndroidUIAutomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).setMaxSearchSwipes(10).scrollIntoView(new UiSelector().text("Views").instance(0))')142 .text()143 .then(function (text) {144 text.should.equal("Views");145 }).nodeify(done);146 });147 it('should allow UiScrollable scrollIntoView', function (done) {148 driver.elementByAndroidUIAutomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0));')149 .text()150 .then(function (text) {151 text.should.equal("Views");152 }).nodeify(done);153 });154 it('should error reasonably if a UiScrollable does not return a UiObject', function (done) {155 driver.elementByAndroidUIAutomator('new UiScrollable(new UiSelector().scrollable(true).instance(0)).setMaxSearchSwipes(10)')156 .should.be.rejectedWith(/status: 9/)157 .nodeify(done);158 });...

Full Screen

Full Screen

basics-specs.js

Source:basics-specs.js Github

copy

Full Screen

1"use strict";2var env = require('../../../../helpers/env')3 , ADB = require('appium-adb')4 , setup = require("../../../common/setup-base")5 , desired = require("../desired")6 , reset = require("../reset")7 , atv = 'android.widget.TextView';8describe("apidemo - find - basics", function () {9 var driver;10 var apiLevel = "0";11 var singleResourceId = "home";12 setup(this, desired).then(function (d) { driver = d; });13 before(function (done) {14 var adb = new ADB({});15 // the app behaves differently on different api levels when it comes to16 // which resource ids are available for testing, so we switch here to make17 // sure we're using the right resource id below18 adb.getApiLevel(function (err, level) {19 if (err) return done(err);20 apiLevel = level;21 if (apiLevel >= "21") {22 singleResourceId = "decor_content_parent";23 }24 done();25 });26 });27 if (env.FAST_TESTS) {28 beforeEach(function () {29 return reset(driver);30 });31 }32 it('should find a single element by content-description', function (done) {33 driver34 .elementByName("Animation").text().should.become("Animation")35 .nodeify(done);36 });37 it('should find an element by class name', function (done) {38 driver39 .elementByClassName("android.widget.TextView").text().should.become("API Demos")40 .nodeify(done);41 });42 it('should find multiple elements by class name', function (done) {43 driver44 .elementsByClassName("android.widget.TextView")45 .should.eventually.have.length.at.least(10)46 .nodeify(done);47 });48 it('should not find an element that doesnt exist', function (done) {49 driver50 .elementByClassName("blargimarg").should.be.rejectedWith(/status: 7/)51 .nodeify(done);52 });53 it('should not find multiple elements that doesnt exist', function (done) {54 driver55 .elementsByClassName("blargimarg").should.eventually.have.length(0)56 .nodeify(done);57 });58 it('should fail on empty locator', function (done) {59 driver.elementsByClassName("")60 .catch(function (err) { throw err.data; }).should.be.rejectedWith(/selector/)61 .elementsByClassName(atv).should.eventually.exist62 .nodeify(done);63 });64 // TODO: The new version of ApiDemo doesn't use id, find a better example.65 it('should find a single element by id @skip-android-all', function (done) {66 driver67 .complexFind(["scroll", [[3, "views"]], [[7, "views"]]]).click()68 .elementByXPath("//android.widget.TextView[@text='Buttons']").click()69 .elementById("buttons_1_normal").text().should.become("Normal")70 .nodeify(done);71 });72 // TODO: The new version of ApiDemo doesn't use id, find a better example.73 it('should find a single element by string id @skip-android-all', function (done) {74 driver75 .elementById("activity_sample_code").text().should.become("API Demos")76 .nodeify(done);77 });78 it('should find a single element by resource-id', function (done) {79 driver80 .elementById('android:id/' + singleResourceId).should.eventually.exist81 .nodeify(done);82 });83 it('should find multiple elements by resource-id', function (done) {84 driver85 .elementsById('android:id/text1')86 .should.eventually.have.length.at.least(10)87 .nodeify(done);88 });89 it('should find multiple elements by resource-id even when theres just one', function (done) {90 driver91 .elementsById('android:id/' + singleResourceId)92 .then(function (els) {93 els.length.should.equal(1);94 })95 .nodeify(done);96 });97 it('should find a single element by resource-id with implicit package', function (done) {98 driver99 .elementById(singleResourceId).should.eventually.exist100 .nodeify(done);101 });102 it('should find multiple elements by resource-id with implicit package', function (done) {103 driver104 .elementsById('text1')105 .should.eventually.have.length.at.least(10)106 .nodeify(done);107 });108 it('should find multiple elements by resource-id with implicit package even when theres just one', function (done) {109 driver110 .elementsById(singleResourceId)111 .then(function (els) {112 els.length.should.equal(1);113 })114 .nodeify(done);115 });...

Full Screen

Full Screen

ios-selectors.test.js

Source:ios-selectors.test.js Github

copy

Full Screen

...50 assert.isAbove(windowElements.length, 1);51 });52 it('should find elements by NSPredicateString', async function () {53 // This is an IOS-specific selector strategy. See https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html for reference54 const allVisibleElements = await driver.elements('-ios predicate string', 'visible = 1');55 assert.isAbove(allVisibleElements.length, 1);56 });57 it('should find elements by class chain', async function () {58 // This is also an IOS-specific selector strategy. Similar to XPath. This is recommended over XPath.59 const windowElement = await driver.elements('-ios class chain', 'XCUIElementTypeWindow[1]/*');60 assert.equal(windowElement.length, 3);61 });62 it('should find elements by XPath', async function () {63 // Can find source xml by calling `driver.source()`64 // Note that XPath is not recommended due to major performance issues65 const buttons = await driver.elementsByXPath('//XCUIElementTypeWindow//XCUIElementTypeButton');66 assert.isAbove(buttons.length, 1, 'Should have more than one button');67 });...

Full Screen

Full Screen

CascadingFlow.js

Source:CascadingFlow.js Github

copy

Full Screen

1/*2 Control cascading flow processes3*/4function CascadingHub(name, cbfx, manager) {5 this.name = name; 6 this.centralHub = manager;7 this.event={8 onDataReceived:cbfx?cbfx:function(){}9 }10}11CascadingFlow.prototype.on = function(eventName,fx) {12 fx?this.events[eventName] = fx:0;13}14CascadingHub.prototype.sendData = function (data) {15 this.centralHub.sendData(this, data);16}17CascadingHub.prototype.clearData = function () {18 this.sendData();19}20function CascadingFlow(init) {21 this.hubs = [];22 this.cascadingList = [];23 this.init = init;24 this.events = {25 flowChanged:function(){}26 };27}28CascadingFlow.prototype.createHub = function (name, cbfx) {29 let idx = this.hubs.findIndex(function (hub, name) {30 return hub.name === name;31 })32 if (idx >= 0)33 throw name + " is already registered";34 let h = new CascadingHub(name, cbfx, this);35 this.hubs.push(h)36 return h;37}38CascadingFlow.prototype.sendData = function (hub, data) {39 let idx = this.cascadingList.findIndex(function (e) {40 return hub === e.hub;41 })42 let driverHubIdx = -1;43 let notifiableHubs = []44 let driverElements = []45 if(idx<0 && data===undefined)46 return;47 if (idx >= 0) // Exists in cascading list48 {49 driverHubIdx = idx;50 let e = this.cascadingList[idx]51 if (data === undefined) {52 //driverHubs will start from 0 to a hub before this removing hub53 driverHubIdx--;54 //remove this hub from order list55 this.cascadingList.splice(idx, 1);56 }57 else {58 e.data = data;59 }60 //Want to make sure if we remove top element then our driverHubs will 61 //start from 0 to end62 driverHubIdx < 0 ? driverHubIdx = this.cascadingList.length - 1 : driverHubIdx;63 }64 else // Not yet there65 { 66 driverHubIdx = this.cascadingList.length; 67 this.cascadingList.push({ hub, data }); 68 }69 //Get a list of driverHubs70 //driverHubs are hubs which participating in determining behaviors of notifiableHubs 71 this.cascadingList.every(function (e, i) {72 if (i <= driverHubIdx) {73 driverElements.push(e)74 return true;75 }76 return false;77 })78 //Find the notifiableHubs79 this.hubs.forEach(function (h) {80 if (!driverElements.find(function (dh) {81 return dh.hub === h82 })) notifiableHubs.push(h)83 })84 this.__boardcastHub(driverElements, notifiableHubs)85}86CascadingFlow.prototype.__boardcastHub = function (driverElements, notifiableHubs) {87 ///TODOS88 this.events.flowChanged(driverElements, notifiableHubs)89}90CascadingFlow.prototype.on = function (name, fx) {91 fx?this.events[name] = fx:0...

Full Screen

Full Screen

find-basic-e2e-specs.js

Source:find-basic-e2e-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import { APIDEMOS_CAPS } from '../../desired';4import { initDriver } from '../../helpers/session';5chai.should();6chai.use(chaiAsPromised);7describe('Find - basic', function () {8 let driver;9 let singleResourceId = 'decor_content_parent';10 before(async function () {11 driver = await initDriver(APIDEMOS_CAPS);12 });13 after(async function () {14 await driver.quit();15 });16 it('should find a single element by content-description', async function () {17 let el = await driver.elementByAccessibilityId('Animation');18 await el.text().should.eventually.equal('Animation');19 });20 it('should find an element by class name', async function () {21 let el = await driver.elementByClassName('android.widget.TextView');22 const text = await el.text();23 text.toLowerCase().should.equal('api demos');24 });25 it('should find multiple elements by class name', async function () {26 await driver.elementsByClassName('android.widget.TextView')27 .should.eventually.have.length.at.least(10);28 });29 it('should not find multiple elements that doesnt exist', async function () {30 await driver.elementsByClassName('blargimarg')31 .should.eventually.have.length(0);32 });33 it('should fail on empty locator', async function () {34 await driver.elementsByClassName('').should.be.rejectedWith(/selector/);35 });36 it('should find a single element by resource-id', async function () {37 await driver.elementById(`android:id/${singleResourceId}`)38 .should.eventually.exist;39 });40 it('should find multiple elements by resource-id', async function () {41 await driver.elementsById('android:id/text1')42 .should.eventually.have.length.at.least(10);43 });44 it('should find multiple elements by resource-id even when theres just one', async function () {45 await driver.elementsById(`android:id/${singleResourceId}`)46 .should.eventually.have.length(1);47 });48 describe('implicit wait', function () {49 let implicitWaitTimeout = 5000;50 before(async function () {51 await driver.setImplicitWaitTimeout(implicitWaitTimeout);52 });53 it('should respect implicit wait with multiple elements', async function () {54 let beforeMs = Date.now();55 await driver.elementsById('there_is_nothing_called_this')56 .should.eventually.have.length(0);57 let afterMs = Date.now();58 (afterMs - beforeMs).should.be.below(implicitWaitTimeout * 2);59 });60 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.elements(webdriver.By.name('Add Contact'), function(err, elements) {7 console.log(elements.length);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const {Builder, By, Key, until} = require('selenium-webdriver');2(async function example() {3 let driver = await new Builder().forBrowser('chrome').build();4 try {5 await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);6 await driver.wait(until.titleIs('webdriver - Google Search'), 1000);7 } finally {8 await driver.quit();9 }10})();11const {Builder, By, Key, until} = require('selenium-webdriver');12const {By, until} = require('selenium-webdriver');13(async function example() {14 let driver = await new Builder().forBrowser('chrome').build();15 try {16 await driver.findElement(By.name('q')).sendKeys('webdriver', Key.RETURN);17 await driver.wait(until.titleIs('webdriver - Google Search'), 1000);18 } finally {19 await driver.quit();20 }21})();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').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();11 console.log(elements);12 driver.elementIdClick(elements.value[0].ELEMENT, function(err, res) {13 console.log(res);14 });15});16 (Session info: chrome=57.0.2987.133)17 (Driver info: chromedriver=2.29.461591 (6f9c0f7d1a4a6b2e2a1a6a7a6d2f6f8a2e9c9b7d),platform=Mac OS X 10.12.5 x86_64)18var webdriver = require('selenium-webdriver');19var driver = new webdriver.Builder().forBrowser('chrome').build();20driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');21driver.findElement(webdriver.By.name('btnG')).click();22driver.wait(function() {23 return driver.getTitle().then(function(title) {24 return title === 'webdriver - Google Search';25 });26}, 1000);27driver.quit();28 console.log(elements);29 driver.elementIdClick(elements.value[0].ELEMENT, function(err, res) {

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new webdriver.Builder()2 .withCapabilities({3 })4 .build();5driver.elements('id', 'id_of_element', function(err, elements) {6 console.log("Found " + elements.length + " elements");7 elements[0].click();8});9driver.quit();10var driver = new webdriver.Builder()11 .withCapabilities({12 })13 .build();14driver.element('id', 'id_of_element', function(err, element) {15 element.click();16});17driver.quit();18var driver = new webdriver.Builder()19 .withCapabilities({20 })21 .build();22 element.click();23});24driver.quit();25var driver = new webdriver.Builder()26 .withCapabilities({

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var assert = require('assert');3var By = webdriver.By;4var until = webdriver.until;5var driver = new webdriver.Builder()6.forBrowser('chrome')7.build();8driver.findElement(By.name('q')).sendKeys('webdriver');9driver.findElement(By.name('btnG')).click();10driver.wait(until.titleIs('webdriver - Google Search'), 1000);11driver.quit();12driver.elements('class name', 'gsfi', function(err, elements) {13 console.log(elements.length);14});15Error: The element reference of <input class="gsfi" maxlength="2048" name="q" type="text"> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed16driver.findElements(By.className("gsfi")).then(function(elements) {17 console.log(elements.length);18});

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var fs = require('fs');3var webdriver = require('selenium-webdriver');4var By = webdriver.By;5var until = webdriver.until;6var driver = new webdriver.Builder()7 .forBrowser('chrome')8 .build();9driver.findElement(By.name('q')).sendKeys('webdriver');10driver.findElement(By.name('btnG')).click();11driver.wait(until.titleIs('webdriver - Google Search'), 1000);12driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .forBrowser('chrome')4 .build();5driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');6driver.findElement(webdriver.By.name('btnG')).click();7driver.wait(function() {8 return driver.getTitle().then(function(title) {9 return title === 'webdriver - Google Search';10 });11}, 1000);12driver.quit();13driver.elements('class name', 'gb_P', function(err, res) {14 console.log(res);15 driver.quit();16});17error: Failed to convert value of type [java.lang.String] to required type [java.lang.Class]; nested exception is java.lang.IllegalArgumentException: Cannot find class [class java.lang.String]18var webdriver = require('selenium-webdriver');19var driver = new webdriver.Builder()20 .forBrowser('chrome')21 .build();22driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');23driver.findElement(webdriver.By.name('btnG')).click();24driver.wait(function() {25 return driver.getTitle().then(function(title) {26 return title === 'webdriver - Google Search';27 });28}, 1000);29driver.quit();30driver.elements('class name', 'gb_P', function(err, res) {31 console.log(res);32 driver.quit();33});34error: Failed to convert value of type [java.lang.String] to required type [java.lang.Class]; nested exception is java.lang.IllegalArgumentException: Cannot find class [class java.lang.String]35driver.findElement(By.name("q")).sendKeys("Selenium");36driver.findElement(By.name("btnK")).click();37driver.findElement(By.className("gb_P")).click();38error: Failed to convert value of type [java.lang.String] to required type [java.lang.Class]; nested exception is java.lang.IllegalArgumentException: Cannot find class [class java.lang.String]

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 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