Best JavaScript code snippet using appium-xcuitest-driver
find-e2e-specs.js
Source:find-e2e-specs.js
...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 () {...
find-element-specs.js
Source:find-element-specs.js
...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 });...
by-uiautomator-e2e-specs.js
Source:by-uiautomator-e2e-specs.js
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 });...
by-uiautomator-specs.js
Source:by-uiautomator-specs.js
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 });...
basics-specs.js
Source:basics-specs.js
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 });...
ios-selectors.test.js
Source:ios-selectors.test.js
...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 });...
CascadingFlow.js
Source:CascadingFlow.js
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...
find-basic-e2e-specs.js
Source:find-basic-e2e-specs.js
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 });...
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .elements('accessibility id', 'button1')9 .then(function (res) {10 console.log(res);11 })12 .end();13{ state: 'success',14 status: 0 }15 .init()16 .elements('accessibility id', 'button1')17 .then(function (res) {18 console.log(res);19 })20 .end();21 .init()22 .elements('
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var By = webdriver.By;3var until = webdriver.until;4var driver = new webdriver.Builder()5 .forBrowser('chrome')6 .build();7driver.findElement(By.name('q')).sendKeys('webdriver');8driver.findElement(By.name('btnK')).click();9driver.wait(until.titleIs('webdriver - Google Search'), 1000);10driver.quit();11Starting ChromeDriver 2.41.578700 (c0b1e9b3c3d7e5b0d8f7d0f55bda505b2f2c2a8a) on port 951512[1537992425.479][INFO]: [c0b1e9b3c3d7e5b0d8f7d0f55bda505b2f2c2a8a] COMMAND InitSession {13 "capabilities": {14 "alwaysMatch": {15 },16 {}17 },18 "desiredCapabilities": {19 }20}21[1537992425.481][INFO]: [c0b1e9b3c3d7e5b0d8f7d0f55bda505b2f2c2a8a] RESPONSE InitSession OK (elapsed 1 ms)22[1537992425.484][INFO]: [c0b1e9b3c3d7e5b0d8f7d0f55bda505b2f2c2a8a] COMMAND NavigateTo {23}24[1537992425.497][INFO]: [c0b1e9b3c3d7e5b0d8f7d0f55bda505b2f2c2a8a] RESPONSE NavigateTo OK (elapsed 12 ms)25[1537992425.498][INFO]: [c0b1e9b3c3d7e5b0d8f7d0f55bda505b2f2c2a8a] COMMAND FindElement {
Using AI Code Generation
1const wd = require('wd');2const assert = require('assert');3const { execSync } = require('child_process');4const serverConfig = {5};6const desiredCaps = {7};8const driver = wd.promiseChainRemote(serverConfig);9(async function myFunction() {10 await driver.init(desiredCaps);11 await driver.sleep(5000);12 console.log(element);13 await driver.quit();14}());15const wd = require('wd');16const assert = require('assert');17const { execSync } = require('child_process');18const serverConfig = {19};20const desiredCaps = {
Using AI Code Generation
1const wdio = require('webdriverio');2const opts = {3 capabilities: {4 }5};6(async () => {7 const client = await wdio.remote(opts);8 const els = await client.elements('name', 'Button');9 console.log(els);10 await client.deleteSession();11})();
Using AI Code Generation
1const wdio = require('webdriverio');2const assert = require('assert');3const options = {4 capabilities: {5 },6};7const driver = wdio.remote(options);8driver.init();9 console.log(`Found ${elements.length} elements`);10 assert.equal(elements.length, 1);11});12driver.end();13[debug] [W3C (d2c2c2b2)] Encountered internal error running command: NoSuchDriverError: A session is either terminated or not started14[debug] [W3C (d2c2c2b2)] at XCUITestDriver.validateLocatorStrategy (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/basedriver/commands
Using AI Code Generation
1const wdio = require('webdriverio');2const opts = {3 desiredCapabilities: {4 }5};6async function runTest() {7 let client = await wdio.remote(opts);8 let locator = {9 };10 let element = await client.elements(locator);11 console.log(element);12 client.deleteSession();13}14runTest();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!