Best JavaScript code snippet using appium-android-driver
by-uiautomator-e2e-specs.js
Source:by-uiautomator-e2e-specs.js
...13 after(async () => {14 await driver.deleteSession();15 });16 it('should find elements with a boolean argument', async () => {17 await driver.findElOrEls('-android uiautomator', 'new UiSelector().clickable(true)', true)18 .should.eventually.have.length.at.least(10);19 });20 it('should find elements within the context of another element', async () => {21 let els = await driver22 .findElOrEls('-android uiautomator', 'new UiSelector().className("android.widget.TextView")', true);23 els.length.should.be.above(8);24 els.length.should.be.below(14);25 });26 it('should find elements without prepending "new UiSelector()"', async () => {27 await driver.findElOrEls('-android uiautomator', '.clickable(true)', true)28 .should.eventually.have.length.at.least(10);29 });30 it('should find elements without prepending "new UiSelector()"', async () => {31 await driver.findElOrEls('-android uiautomator', '.clickable(true)', true)32 .should.eventually.have.length.at.least(10);33 });34 it('should find elements without prepending "new UiSelector()"', async () => {35 await driver.findElOrEls('-android uiautomator', 'clickable(true)', true)36 .should.eventually.have.length.at.least(10);37 });38 it('should find elements without prepending "new "', async () => {39 await driver.findElOrEls('-android uiautomator', 'UiSelector().clickable(true)', true)40 .should.eventually.have.length.at.least(10);41 });42 it('should ignore trailing semicolons', async () => {43 await driver.findElOrEls('-android uiautomator', 'new UiSelector().clickable(true);', true)44 .should.eventually.have.length.at.least(10);45 });46 it('should find an element with an int argument', async () => {47 let el = await driver.findElOrEls('-android uiautomator', 'new UiSelector().index(0)', false);48 await driver.getName(el.ELEMENT).should.eventually.equal('android.widget.FrameLayout');49 });50 it('should find an element with a string argument', async () => {51 await driver52 .findElOrEls('-android uiautomator', 'new UiSelector().description("Animation")', false)53 .should.eventually.exist;54 });55 it('should find an element with an overloaded method argument', async () => {56 await driver.findElOrEls('-android uiautomator', 'new UiSelector().className("android.widget.TextView")', true)57 .should.eventually.have.length.at.least(10);58 });59 it('should find an element with a Class<T> method argument', async () => {60 await driver.findElOrEls('-android uiautomator', 'new UiSelector().className(android.widget.TextView)', true)61 .should.eventually.have.length.at.least(10);62 });63 it('should find an element with a long chain of methods', async () => {64 let el = await driver.findElOrEls('-android uiautomator', 'new UiSelector().clickable(true).className(android.widget.TextView).index(1)', false);65 await driver.getText(el.ELEMENT).should.eventually.equal('Accessibility');66 });67 it('should find an element with recursive UiSelectors', async function () {68 // TODO: figure out why this fails with 7.1.169 if (await driver.adb.getApiLevel() >= 24) return this.skip(); //eslint-disable-line curly70 await driver.findElOrEls('-android uiautomator', 'new UiSelector().childSelector(new UiSelector().clickable(true)).clickable(true)', true)71 .should.eventually.have.length(1);72 });73 it('should not find an element with bad syntax', async () => {74 await driver.findElOrEls('-android uiautomator', 'new UiSelector().clickable((true)', true)75 .should.eventually.be.rejectedWith(/resource could not be found/);76 });77 it('should not find an element with bad syntax', async () => {78 await driver.findElOrEls('-android uiautomator', 'new UiSelector().drinkable(true)', true)79 .should.eventually.be.rejectedWith(/resource could not be found/);80 });81 it('should not find an element which does not exist', async () => {82 await driver.findElOrEls('-android uiautomator', 'new UiSelector().description("chuckwudi")', true)83 .should.eventually.have.length(0);84 });85 it('should allow multiple selector statements and return the Union of the two sets', async () => {86 let clickable = await driver.findElOrEls('-android uiautomator', 'new UiSelector().clickable(true)', true);87 clickable.length.should.be.above(0);88 let notClickable = await driver.findElOrEls('-android uiautomator', 'new UiSelector().clickable(false)', true);89 notClickable.length.should.be.above(0);90 let both = await driver.findElOrEls('-android uiautomator', 'new UiSelector().clickable(true); new UiSelector().clickable(false);', true);91 both.should.have.length(clickable.length + notClickable.length);92 });93 it('should allow multiple selector statements and return the Union of the two sets', async () => {94 let clickable = await driver.findElOrEls('-android uiautomator', 'new UiSelector().clickable(true)', true);95 clickable.length.should.be.above(0);96 let clickableClickable = await driver.findElOrEls('-android uiautomator', 'new UiSelector().clickable(true); new UiSelector().clickable(true);', true);97 clickableClickable.length.should.be.above(0);98 clickableClickable.should.have.length(clickable.length);99 });100 it('should find an element in the second selector if the first finds no elements', async () => {101 let selector = 'new UiSelector().className("not.a.class"); new UiSelector().className("android.widget.TextView")';102 await driver.findElOrEls('-android uiautomator', selector, true)103 .should.eventually.exist;104 });105 it('should scroll to, and return elements using UiScrollable', async () => {106 let selector = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0))';107 let el = await driver.findElOrEls('-android uiautomator', selector, false);108 await driver.getText(el.ELEMENT).should.eventually.equal('Views');109 });110 it('should allow chaining UiScrollable methods', async () => {111 let selector = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).setMaxSearchSwipes(10).scrollIntoView(new UiSelector().text("Views").instance(0))';112 let el = await driver.findElOrEls('-android uiautomator', selector, false);113 await driver.getText(el.ELEMENT).should.eventually.equal('Views');114 });115 it('should allow UiScrollable scrollIntoView', async () => {116 let selector = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("Views").instance(0));';117 let el = await driver.findElOrEls('-android uiautomator', selector, false);118 await driver.getText(el.ELEMENT).should.eventually.equal('Views');119 });120 it('should error reasonably if a UiScrollable does not return a UiObject', async () => {121 let selector = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).setMaxSearchSwipes(10)';122 await driver.findElOrEls('-android uiautomator', selector, false)123 .should.eventually.be.rejectedWith(/resource could not be found/);124 });125 it('should allow UiScrollable with unicode string', async () => {126 await driver.startActivity('io.appium.android.apis', '.text.Unicode');127 let selector = 'new UiSelector().text("عربÙ").instance(0);';128 let el = await driver.findElOrEls('-android uiautomator', selector, false);129 await driver.getText(el.ELEMENT).should.eventually.equal('عربÙ');130 });...
drag-e2e-specs.js
Source:drag-e2e-specs.js
...23 await driver.startActivity(caps.appPackage, caps.appActivity);24 });25 describe('drag', function () {26 it('should drag by element', async () => {27 let dot3 = await driver.findElOrEls('id', 'io.appium.android.apis:id/drag_dot_3', false);28 let dot2 = await driver.findElOrEls('id', 'io.appium.android.apis:id/drag_dot_2', false);29 let gestures = [30 {options: {element: dot3.ELEMENT}},31 {options: {element: dot2.ELEMENT}}32 ];33 await driver.doTouchDrag(gestures);34 let results = await driver.findElOrEls('id', 'io.appium.android.apis:id/drag_result_text', false);35 await driver.getText(results.ELEMENT).should.eventually.include('Dropped');36 });37 it('should drag by element with an offset', async () => {38 let dot3 = await driver.findElOrEls('id', 'io.appium.android.apis:id/drag_dot_3', false);39 let dot2 = await driver.findElOrEls('id', 'io.appium.android.apis:id/drag_dot_2', false);40 let gestures = [41 {options: {element: dot3.ELEMENT, x: 5, y: 5}},42 {options: {element: dot2.ELEMENT, x: 5, y: 5}}43 ];44 await driver.doTouchDrag(gestures);45 let results = await driver.findElOrEls('id', 'io.appium.android.apis:id/drag_result_text', false);46 await driver.getText(results.ELEMENT).should.eventually.include('Dropped');47 });48 });49 describe('performTouch', function () {50 it('should drag by element', async () => {51 let startEle = await driver.findElement("id", "io.appium.android.apis:id/drag_dot_3");52 let endEle = await driver.findElement("id", "io.appium.android.apis:id/drag_dot_2");53 let gestures = [{action: "longPress", options: {element: startEle.ELEMENT}},54 {action: "moveTo", options: {element: endEle.ELEMENT}},55 {action: "release", options: {}}];56 await driver.performTouch(gestures);57 let resultEle = await driver.findElement("id", "io.appium.android.apis:id/drag_result_text");58 await driver.getText(resultEle.ELEMENT).should.eventually.equal("Dropped!");59 });...
find-basic-e2e-specs.js
Source:find-basic-e2e-specs.js
...20 after(async () => {21 await driver.deleteSession();22 });23 it('should find a single element by content-description', async () => {24 let el = await driver.findElOrEls('accessibility id', 'Animation', false);25 await driver.getText(el.ELEMENT).should.eventually.equal('Animation');26 });27 it('should find an element by class name', async () => {28 let el = await driver.findElOrEls('class name', 'android.widget.TextView', false);29 await driver.getText(el.ELEMENT).should.eventually.equal('API Demos');30 });31 it('should find multiple elements by class name', async () => {32 await driver.findElOrEls('class name', 'android.widget.TextView', true)33 .should.eventually.have.length.at.least(10);34 });35 it('should not find an element that doesnt exist', async () => {36 await driver.findElOrEls('class name', 'blargimarg', false)37 .should.be.rejectedWith(/could not be located/);38 });39 it('should not find multiple elements that doesnt exist', async () => {40 await driver.findElOrEls('class name', 'blargimarg', true)41 .should.eventually.have.length(0);42 });43 it('should fail on empty locator', async () => {44 await driver.findElOrEls('class name', '', true).should.be.rejectedWith(/selector/);45 });46 it('should find a single element by string id @skip-android-all', async () => {47 let el = await driver.findElOrEls('id', 'activity_sample_code', false);48 await driver.getText(el.ELEMENT).should.eventually.equal('API Demos');49 });50 it('should find a single element by resource-id', async () => {51 await driver.findElOrEls('id', `android:id/${singleResourceId}`, false)52 .should.eventually.exist;53 });54 it('should find multiple elements by resource-id', async () => {55 await driver.findElOrEls('id', 'android:id/text1', true)56 .should.eventually.have.length.at.least(10);57 });58 it('should find multiple elements by resource-id even when theres just one', async () => {59 await driver.findElOrEls('id', `android:id/${singleResourceId}`, true)60 .should.eventually.have.length(1);61 });62 it('should find a single element by resource-id with implicit package', async () => {63 await driver.findElOrEls('id', singleResourceId, false)64 .should.eventually.exist;65 });66 it('should find a single element by resource-id with implicit package', async () => {67 await driver.findElOrEls('id', 'text1', true)68 .should.eventually.have.length.at.least(10);69 });70 it('should find multiple elements by resource-id with implicit package even when theres just one', async () => {71 await driver.findElOrEls('id', singleResourceId, true)72 .should.eventually.have.length(1);73 });74 describe('implicit wait', () => {75 let implicitWait = 5000;76 before(async () => {77 await driver.implicitWait(implicitWait);78 });79 it('should respect implicit wait with multiple elements', async () => {80 let beforeMs = Date.now();81 await driver.findElOrEls('id', 'there_is_nothing_called_this', true)82 .should.eventually.have.length(0);83 let afterMs = Date.now();84 (afterMs - beforeMs).should.be.below(implicitWait + 5000);85 (afterMs - beforeMs).should.be.above(implicitWait);86 });87 it('should respect implicit wait with a single element', async () => {88 let beforeMs = Date.now();89 await driver.findElOrEls('id', 'there_is_nothing_called_this', false)90 .should.eventually.be.rejectedWith(/could not be located/);91 let afterMs = Date.now();92 (afterMs - beforeMs).should.be.below(implicitWait + 5000);93 (afterMs - beforeMs).should.be.above(implicitWait);94 });95 });...
by-xpath-e2e-specs.js
Source:by-xpath-e2e-specs.js
...15 after(async () => {16 await driver.deleteSession();17 });18 it('should throw when matching nothing', async () => {19 await driver.findElOrEls('xpath', '//whatthat', false).should.eventually.be.rejectedWith(/could not be located/);20 });21 it('should throw with status 7 for hierarchy root', async () => {22 await driver.findElOrEls('xpath', '/*', false).should.eventually.be.rejectedWith(/could not be located/);23 });24 it('should find element by type', async () => {25 let el = await driver.findElOrEls('xpath', `//${atv}`, false);26 await driver.getText(el.ELEMENT).should.eventually.equal('API Demos');27 });28 it('should find element by text', async () => {29 let el = await driver.findElOrEls('xpath', `//${atv}[@text='Accessibility']`, false);30 await driver.getText(el.ELEMENT).should.eventually.equal('Accessibility');31 });32 it('should find exactly one element via elementsByXPath', async () => {33 let el = await driver.findElOrEls('xpath', `//${atv}[@text='Accessibility']`, true);34 el.length.should.equal(1);35 await driver.getText(el[0].ELEMENT).should.eventually.equal('Accessibility');36 });37 it('should find element by partial text', async () => {38 let el = await driver.findElOrEls('xpath', `//${atv}[contains(@text, 'Accessibility')]`, false);39 await driver.getText(el.ELEMENT).should.eventually.equal('Accessibility');40 });41 it('should find the last element', async () => {42 let el = await driver.findElOrEls('xpath', `(//${atv})[last()]`, false);43 let text = await driver.getText(el.ELEMENT);44 ["OS", "Text", "Views", "Preference"].should.include(text);45 });46 // TODO: Doesn't work on CI. Works locally on API_LEVEL 2347 //it('should find element by xpath index and child @skip-ci', async () => {48 // let alv = 'android.widget.ListView';49 // let el = await driver.findElOrEls('xpath', `//${f}[2]/${alv}[1]/${atv}[4]`, false);50 // await driver.getText(el.ELEMENT).should.eventually.equal('App');51 //});52 it('should find element by index and embedded desc', async () => {53 let el = await driver.findElOrEls('xpath', `//${f}//${atv}[5]`, false);54 await driver.getText(el.ELEMENT).should.eventually.equal('Content');55 });56 it('should find all elements', async () => {57 let el = await driver.findElOrEls('xpath', `//*`, true);58 el.length.should.be.above(2);59 });60 it('should find the first element when searching for all elements', async () => {61 let el = await driver.findElOrEls('xpath', `//*`, true);62 el[0].should.exist;63 });64 it('should find less elements with compression turned on', async () => {65 await driver.updateSettings({ignoreUnimportantViews: false});66 let elementsWithoutCompression = await driver.findElOrEls('xpath', `//*`, true);67 await driver.updateSettings({ignoreUnimportantViews: true});68 let elementsWithCompression = await driver.findElOrEls('xpath', `//*`, true);69 elementsWithoutCompression.length.should.be.greaterThan(elementsWithCompression.length);70 });...
find-specs.js
Source:find-specs.js
...28 });29 });30 describe('findElorEls', function () {31 it('should throw an error if there is no selector', async function () {32 await driver.findElOrEls('xpath', null, false, 'some context')33 .should.be.rejectedWith(/provide a selector/);34 });35 it('should be able to find element', async function () {36 let params = {strategy: 'xpath', selector: '//*[1]', context: 'context', multiple: false};37 driver.doFindElementOrEls.returns('el1');38 await driver.findElOrEls('xpath', '//*[1]', false, 'context').should.become('el1');39 driver.doFindElementOrEls.calledWithExactly(params).should.be.true;40 });41 it('should be able to find elements', async function () {42 let params = {strategy: 'xpath', selector: '//*[1]', context: 'context', multiple: true};43 driver.doFindElementOrEls.returns(['el1', 'el2']);44 await driver.findElOrEls('xpath', '//*[1]', true, 'context')45 .should.eventually.be.deep.equal(['el1', 'el2']);46 driver.doFindElementOrEls.calledWithExactly(params).should.be.true;47 });48 it('should not throws NoSuchElementError when searching multiple if element does not exist', async function () {49 driver.doFindElementOrEls.returns(null);50 await driver.findElOrEls('xpaht', '//*[1]', true)51 .should.eventually.be.deep.equal([]);52 });53 it('should throw NoSuchElementError if element does not exist', async function () {54 driver.doFindElementOrEls.throws(new errors.NoSuchElementError());55 await driver.findElOrEls('xpath', '//*[1]', false)56 .should.be.rejectedWith(errors.NoSuchElementError);57 });58 it('should fails if locator strategy is not valid', async function () {59 driver.validateLocatorStrategy.throws();60 await driver.findElOrEls().should.be.rejected;61 });62 it('should fails if gets unexpected error', async function () {63 driver.doFindElementOrEls.throws(new Error('unexpected_error'));64 await driver.findElOrEls('x', 'loc').should.be.rejectedWith('unexpected_error');65 });66 });...
driver-e2e-specs.js
Source:driver-e2e-specs.js
...47 title.should.equal('Appium: Mobile App Automation Made Awesome.');48 });49 it('finds elements by class name', async function () {50 await driver.setUrl('http://www.appium.io');51 let heading = await driver.findElOrEls('class name', 'jumbotron', false);52 let text = await driver.getText(heading);53 text.should.contain('Appium');54 });55 it('finds elements by css', async function () {56 await driver.setUrl('http://www.appium.io');57 let navBarLinks = await driver.findElOrEls('css', '.navbar-nav-center a', true);58 navBarLinks.length.should.equal(5);59 });...
from-el-e2e-specs.js
Source:from-el-e2e-specs.js
...15 after(async () => {16 await driver.deleteSession();17 });18 it('should find a single element by tag name', async () => {19 let el = await driver.findElOrEls('class name', alv, false);20 let innerEl = await driver.findElOrEls('class name', atv, false, el.ELEMENT);21 await driver.getText(innerEl.ELEMENT).should.eventually.equal("Access'ibility");22 });23 it('should find multiple elements by tag name', async () => {24 let el = await driver.findElOrEls('class name', alv, false);25 let innerEl = await driver.findElOrEls('class name', atv, true, el.ELEMENT);26 await driver.getText(innerEl[0].ELEMENT).should.eventually.have.length.above(10);27 });28 it('should not find an element that doesnt exist', async () => {29 let el = await driver.findElOrEls('class name', alv, false);30 await driver.findElOrEls('class name', 'blargimarg', false, el.ELEMENT)31 .should.be.rejectedWith(/could not be located/);32 });33 it('should not find multiple elements that dont exist', async () => {34 let el = await driver.findElOrEls('class name', alv, true);35 await driver.findElOrEls('class name', 'blargimarg', false, el.ELEMENT)36 .should.be.rejectedWith(/could not be located/);37 });...
by-accessibility-id-e2e-specs.js
Source:by-accessibility-id-e2e-specs.js
...13 after(async () => {14 await driver.deleteSession();15 });16 it('should find an element by name', async () => {17 await driver.findElOrEls('accessibility id', 'Animation', false).should.eventually.exist;18 });19 it('should return an array of one element if the `multi` param is true', async () => {20 let els = await driver.findElOrEls('accessibility id', 'Animation', true);21 els.should.be.an.instanceof(Array);22 els.should.have.length(1);23 });24 it('should find an element with a content-desc property containing an apostrophe', async () => {25 await driver.findElOrEls('accessibility id', "Access'ibility", false).should.eventually.exist;26 });...
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var should = chai.should();7var expect = chai.expect;8var driver = wd.promiseChainRemote("localhost", 4723);9driver.init({10}).then(function() {11 return driver.sleep(10000);12}).then(function() {13 return driver.findElOrEls('id', 'com.appiumdemoapp:id/enterText', true);14}).then(function(el) {15 console.log('element found');16 return driver.elementById('com.appiumdemoapp:id/enterText').sendKeys('Hello');17}).then(function() {18 return driver.findElOrEls('id', 'com.appiumdemoapp:id/enterText', true);19}).then(function(el) {20 console.log('element found');21 return driver.elementById('com.appiumdemoapp:id/enterText').sendKeys('Hello');22}).then(function() {23 return driver.findElOrEls('id', 'com.appiumdemoapp:id/enterText', true);24}).then(function(el) {25 console.log('element found');26 return driver.elementById('com.appiumdemoapp:id/enterText').sendKeys('Hello');27}).then(function() {28 return driver.findElOrEls('id', 'com.appiumdemoapp:id/enterText', true);29}).then(function(el) {30 console.log('element found');31 return driver.elementById('com.appiumdemoapp:id/enterText').sendKeys('Hello');32}).then(function() {33 return driver.findElOrEls('id', 'com.appiumdemoapp:id/enterText', true);34}).then(function(el) {35 console.log('element found');36 return driver.elementById('com.appiumdemoapp:id/enterText').sendKeys('Hello');37}).then(function() {38 return driver.findElOrEls('id', 'com
Using AI Code Generation
1var assert = require('assert');2var wd = require('wd');3var caps = {4};5var driver = wd.remote('localhost', 4723);6driver.init(caps, function(err, sessionID) {7 if (err) {8 console.log(err);9 } else {10 console.log("Session ID: " + sessionID);11 driver.elementByAccessibilityId('Add Contact', function(err, el) {12 if (err) {13 console.log(err);14 } else {15 el.click(function(err) {16 if (err) {17 console.log(err);18 } else {19 driver.elementByName('Save', function(err, el) {20 if (err) {21 console.log(err);22 } else {23 console.log("Found element by name");24 }25 });26 driver.elementsByName('Save', function(err, els) {27 if (err) {28 console.log(err);29 } else {30 console.log("Found elements by name");31 }32 });33 driver.elementByAccessibilityId('Save', function(err, el) {34 if (err) {35 console.log(err);36 } else {37 console.log("Found element by accessibility id");38 }39 });40 driver.elementsByAccessibilityId('Save', function(err, els) {41 if (err) {42 console.log(err);43 } else {44 console.log("Found elements by accessibility id");45 }46 });47 }48 });49 }50 });51 }52});53import io.appium.java_client.AppiumDriver;54import io.appium.java_client.android.AndroidDriver;55import java.io.File;56import java.net.URL;57import java.util.List;58import org.openqa.selenium.By;59import org.openqa.selenium.WebElement;60import org.openqa.selenium.remote.CapabilityType;61import org.openqa.selenium.remote.DesiredCapabilities;62import org.testng.Assert;63import org.testng.annotations.Test;64public class TestAppium {
Using AI Code Generation
1var wd = require('wd');2var driver = wd.promiseChainRemote('localhost', 4723);3var desired = {4};5 .init(desired)6 .then(function () {7 return driver.findElOrEls('name', 'Add Contact', false);8 })9 .then(function (el) {10 console.log(el);11 })12 .fin(function () { return driver.quit(); })13 .done();14var wd = require('wd');15var driver = wd.promiseChainRemote('localhost', 4723);16var desired = {17};18 .init(desired)19 .then(function () {20 return driver.findElOrEls('name', 'Add', false);21 })22 .then(function (el) {23 console.log(el);24 })25 .fin(function () { return driver.quit(); })26 .done();27var wd = require('wd');28var driver = wd.promiseChainRemote('localhost', 4723);29var desired = {30};31 .init(desired)32 .then(function () {33 return driver.findElOrEls('name', 'Add Contact', false);34 })35 .then(function (el) {36 console.log(el);37 })38 .fin(function () { return driver.quit(); })39 .done();
Using AI Code Generation
1driver.init({2}).then(function() {3 return driver.findElOrEls("accessibility id", "Animation", false);4}).then(function(el) {5 return driver.clickElement(el.ELEMENT);6}).then(function() {7 console.log("Clicked on the animation element");8}).fin(function() { return driver.quit(); })9 .done();
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!!