How to use driver.element method in Appium

Best JavaScript code snippet using appium

find-element-specs.js

Source:find-element-specs.js Github

copy

Full Screen

...93 });94 // TODO: CI hangs on those disabling, investigation needed95 describe('find elements using accessibility id locator strategy @skip-ci', function () {96 it('should find an element by name', function (done) {97 driver.element('accessibility id', 'UICatalog').then(function (el) {98 el.should.exist;99 }).nodeify(done);100 });101 it('should find a deeply nested element by name', function (done) {102 driver103 .element('accessibility id', 'Toolbar, Uses of UIToolbar').then(function (el) {104 el.should.exist;105 }).nodeify(done);106 });107 it('should find an element by name beneath another element', function (done) {108 driver.element('accessibility id', 'Empty list').then(function (el) {109 el.element('accessibility id', 'Controls, Various uses of UIControl').then(function (innerEl) {110 innerEl.should.exist;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 });130 describe('findElementsByClassName textfield case', function () {131 after(function (done) {132 driver.clickBack()133 .nodeify(done);134 });135 it('should find only one textfield', function (done) {136 driver137 .elementsByClassName('UIATableCell').then(function (els) { return els[2]; })138 .click()139 .elementByName('Rounded')140 .elementsByClassName('>', 'UIATextField')141 .should.eventually.have.length(1)142 .nodeify(done);143 });144 });145 describe('findElement(s) containing name', function () {146 after(function (done) {147 driver.clickBack()148 .nodeify(done);149 });150 it('should find one element', function (done) {151 driver152 .elementsByClassName('UIATableCell').then(function (els) { return els[2]; })153 .click()154 .elementByName('*Rounded*').getAttribute('name')155 .should.become('UITextField Rounded')156 .nodeify(done);157 });158 it('should find several element', function (done) {159 driver160 .elementsByClassName('UIATableCell').then(function (els) { return els[2]; })161 .click()162 .elementsByName('*Rounded*')163 .should.eventually.have.length.above(3)164 .nodeify(done);165 });166 });167 describe('findElement(s)ByXPath', function () {168 var setupXpath = function (driver) {169 return driver.elementByClassName('UIATableCell').click();170 };171 if (process.env.FAST_TESTS) {172 afterEach(function (done) {173 driver174 .back()175 .nodeify(done);176 });177 }178 it('should return the last button', function (done) {179 driver180 .resolve(setupXpath(driver))181 .elementByXPath("//UIAButton[last()]").text()182 .should.become("Add contact")183 .nodeify(done);184 });185 it('should return a single element', function (done) {186 driver187 .resolve(setupXpath(driver))188 .elementByXPath("//UIAButton").text()189 .should.become("Back")190 .nodeify(done);191 });192 it('should return multiple elements', function (done) {193 driver194 .resolve(setupXpath(driver))195 .elementsByXPath("//UIAButton")196 .should.eventually.have.length.above(5)197 .nodeify(done);198 });199 it('should filter by name', function (done) {200 driver201 .resolve(setupXpath(driver))202 .elementByXPath("//UIAButton[@name='Rounded']").text()203 .should.become("Rounded")204 .nodeify(done);205 });206 it('should know how to restrict root-level elements', function (done) {207 driver208 .resolve(setupXpath(driver))209 .elementByXPath("/UIAButton")210 .should.be.rejectedWith(/status: 7/)211 .nodeify(done);212 });213 it('should search an extended path by child', function (done) {214 driver215 .resolve(setupXpath(driver))216 .then(function () {217 return spinWait(function () {218 return driver.elementByXPath("//UIANavigationBar/UIAStaticText")219 .text().should.become('Buttons');220 });221 }).nodeify(done);222 });223 it('should search an extended path by descendant', function (done) {224 driver225 .resolve(setupXpath(driver))226 .elementsByXPath("//UIATableCell//UIAButton").then(function (els) {227 return Q.all(_(els).map(function (el) { return el.text(); }));228 }).then(function (texts) {229 texts.should.not.include("Button");230 texts.should.include("Gray");231 }).nodeify(done);232 });233 it('should filter by indices', function (done) {234 driver235 .resolve(setupXpath(driver))236 .then(function () {237 return spinWait(function () {238 return driver.elementByXPath("//UIATableCell[2]//UIAStaticText[1]").getAttribute('name')239 .should.become("ButtonsViewController.m:\r(UIButton *)grayButton");240 });241 }).nodeify(done);242 });243 it('should filter by partial text', function (done) {244 driver245 .resolve(setupXpath(driver))246 .elementByXPath("//UIATableCell//UIAButton[contains(@name, 'Gr')]").text()247 .should.become("Gray")248 .nodeify(done);249 });250 });251 describe('FindElement(s)ByUIAutomation', function () {252 var byUIA = '-ios uiautomation';253 var filterDisplayed = function (els) {254 return Q.all(_.map(els, function (el) { return el.isDisplayed(); }))255 .then(function (res) { return _.filter(els, function (el, i) { return res[i]; }); });256 };257 before(function (done) {258 driver259 .element(byUIA, '.navigationBars()[0]')260 .getAttribute('name').then(function (name) {261 if (name !== 'UICatalog') {262 return driver.back().delay(2000);263 } else {264 return Q.delay(500);265 }266 }267 ).nodeify(done);268 });269 it('should process most basic UIAutomation query', function (done) {270 driver271 .elements(byUIA, '.elements()').then(filterDisplayed)272 .should.eventually.have.length(2)273 .nodeify(done);274 });275 it('should process UIAutomation queries if user leaves out the first period', function (done) {276 driver277 .elements(byUIA, '$.mainWindow().elements()').then(filterDisplayed)278 .should.eventually.have.length(2)279 .nodeify(done);280 });281 it('should get a single element', function (done) {282 driver.element(byUIA, '.elements()[0]').getAttribute('name')283 .should.become('UICatalog')284 .nodeify(done);285 });286 it('should get a single element', function (done) {287 driver.element(byUIA, '.elements()[1]').getAttribute('name')288 .should.become('Empty list')289 .nodeify(done);290 });291 it('should get single element as array', function (done) {292 driver293 .elements(byUIA, '.tableViews()[0]')294 .should.eventually.have.length(1)295 .nodeify(done);296 });297 it('should find elements by index multiple times', function (done) {298 driver.element(byUIA, '.elements()[1].cells()[2]').getAttribute('name')299 .should.become('TextFields, Uses of UITextField')300 .nodeify(done);301 });302 it('should find elements by name', function (done) {303 driver.element(byUIA, '.elements()["UICatalog"]').getAttribute('name')304 .should.become('UICatalog')305 .nodeify(done);306 });307 it('should find elements by name and index', function (done) {308 driver.element(byUIA, '.elements()["Empty list"].cells()[3]').getAttribute('name')309 .should.become('SearchBar, Use of UISearchBar')310 .nodeify(done);311 });312 describe('start from a given context instead of root target', function () {313 it('should process a simple query', function (done) {314 driver.element(byUIA, '.elements()[1]').then(function (el) {315 el316 .elements(byUIA, '.elements()')317 .should.eventually.have.length(12)318 .nodeify(done);319 });320 });321 it('should find elements by name', function (done) {322 driver.element(byUIA, '.elements()[1]').then(function (el) {323 el324 .element(byUIA, '.elements()["Buttons, Various uses of UIButton"]')325 .should.eventually.exist326 .nodeify(done);327 });328 });329 });330 });...

Full Screen

Full Screen

element-e2e-specs.js

Source:element-e2e-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import _ from 'lodash';4import B from 'bluebird';5import { retryInterval } from 'asyncbox';6import { UICATALOG_CAPS } from '../desired';7import { initSession, deleteSession, MOCHA_TIMEOUT } from '../helpers/session';8chai.should();9chai.use(chaiAsPromised);10describe('XCUITestDriver - element(s)', function () {11 this.timeout(MOCHA_TIMEOUT);12 let driver;13 before(async () => {14 driver = await initSession(UICATALOG_CAPS);15 });16 after(async () => {17 await deleteSession();18 });19 describe('text', () => {20 it('should get the text of an element', async () => {21 let el = await driver.elementByAccessibilityId('Buttons');22 let text = await el.text();23 text.should.eql('Buttons');24 });25 it('should not mix up elements', async () => {26 let el1 = await driver.elementByAccessibilityId('Buttons');27 let text1 = await el1.text();28 text1.should.eql('Buttons');29 let el2 = await driver.elementByAccessibilityId('Image View');30 let text2 = await el2.text();31 text2.should.eql('Image View');32 });33 });34 describe('name', () => {35 it('should get the name of an element', async () => {36 let el = await driver.elementByAccessibilityId('Buttons');37 let name = await el.getTagName();38 name.should.eql('XCUIElementTypeStaticText');39 });40 });41 describe('displayed', () => {42 it('should get the displayed status for a displayed element', async () => {43 let el = await driver.elementByAccessibilityId('Buttons');44 let displayed = await el.isDisplayed();45 displayed.should.be.true;46 });47 it('should get the displayed status for an undisplayed element', async () => {48 let el = await driver.elementByAccessibilityId('Toolbars');49 let displayed = await el.isDisplayed();50 displayed.should.be.false;51 });52 });53 describe('location', () => {54 it('should get the location of an element', async () => {55 let el = await driver.elementByAccessibilityId('Buttons');56 let loc = await el.getLocation();57 loc.x.should.exist;58 loc.y.should.exist;59 });60 it('should not mix up locations', async () => {61 let el1 = await driver.elementByAccessibilityId('Buttons');62 let loc1 = await el1.getLocation();63 let el2 = await driver.elementByAccessibilityId('Image View');64 let loc2 = await el2.getLocation();65 loc1.x.should.eql(loc2.x);66 loc1.y.should.be.below(loc2.y);67 });68 });69 describe('location_in_view', () => {70 it('should get the location of an element', async () => {71 let el = await driver.elementByAccessibilityId('Buttons');72 let loc = await el.getLocation();73 loc.x.should.exist;74 loc.y.should.exist;75 });76 it('should not mix up locations', async () => {77 let el1 = await driver.elementByAccessibilityId('Buttons');78 let loc1 = await el1.getLocation();79 let el2 = await driver.elementByAccessibilityId('Image View');80 let loc2 = await el2.getLocation();81 loc1.x.should.eql(loc2.x);82 loc1.y.should.be.below(loc2.y);83 });84 });85 describe('size', () => {86 it('should get the size of the element', async () => {87 let el = await driver.elementByAccessibilityId('Buttons');88 let size = await el.getSize();89 size.width.should.exist;90 size.height.should.exist;91 });92 });93 describe('touch click', () => {94 it('should click an element', async () => {95 let el = await driver.elementByAccessibilityId('Buttons');96 await el.tap();97 (await driver.elementsByClassName('XCUIElementTypeButton')).should.have.length.above(4);98 await driver.back();99 });100 });101 describe('interactions', function () {102 describe('text fields', () => {103 let text1 = 'bunchoftext';104 let text2 = 'differenttext';105 let text3 = 'http://appium.io/';106 let secureText = _.map(new Array(text1.length), () => '•').join('');107 let phText = 'Placeholder text';108 beforeEach(async function () {109 let el = await driver.elementByAccessibilityId('Text Fields');110 await driver.execute('mobile: scroll', {element: el, toVisible: true});111 await el.click();112 });113 afterEach(async () => {114 await driver.back();115 });116 describe('set value', () => {117 it('should type in the text field', async () => {118 let el = await driver.elementByClassName('XCUIElementTypeTextField');119 await el.type(text1);120 let text = await el.text();121 text.should.eql(text1);122 });123 it('should type in the text field even before the keyboard is up', async () => {124 let el = await driver.elementByClassName('XCUIElementTypeTextField');125 await el.type(text1);126 let text = await el.text();127 text.should.eql(text1);128 });129 it('should type a url in the text field', async () => {130 // in Travis this sometimes gets the wrong text131 let retries = process.env.TRAVIS ? 5 : 1;132 await retryInterval(retries, 100, async () => {133 let el = await driver.elementByClassName('XCUIElementTypeTextField');134 await el.clear();135 await el.type(text3);136 let text = await el.text();137 text.should.eql(text3);138 });139 });140 it('should be able to type into two text fields', async () => {141 let els = await driver.elementsByClassName('XCUIElementTypeTextField');142 await els[0].type(text1);143 await driver.hideKeyboard();144 await els[1].type(text2);145 let text = await els[0].text();146 text.should.eql(text1);147 text = await els[1].text();148 text.should.eql(text2);149 });150 it('should type in a secure text field', async () => {151 let els = await driver.elementsByClassName('XCUIElementTypeSecureTextField');152 await els[0].type(text1);153 let text = await els[0].text();154 text.should.not.eql(text1);155 text.length.should.eql(text1.length);156 text.should.eql(secureText);157 });158 it('should type a backspace', async () => {159 let el = await driver.elementByClassName('XCUIElementTypeTextField');160 await driver.type(el, ['0123456789\uE003']);161 let text = await el.text();162 text.should.eql('012345678');163 });164 it('should type a delete', async () => {165 let el = await driver.elementByClassName('XCUIElementTypeTextField');166 await driver.type(el, ['0123456789\ue017']);167 let text = await el.text();168 text.should.eql('012345678');169 });170 it('should type a newline', async () => {171 let el = await driver.elementByClassName('XCUIElementTypeTextField');172 await driver.type(el, ['0123456789\uE006']);173 let text = await el.text();174 text.should.eql('0123456789');175 });176 });177 describe('clear', () => {178 it('should clear a text field', async () => {179 let el = await driver.elementByClassName('XCUIElementTypeTextField');180 await el.type(text1);181 let text = await el.text();182 text.should.eql(text1);183 await el.clear();184 text = await el.text();185 text.should.eql(phText);186 });187 it('should be able to clear two text fields', async () => {188 let els = await driver.elementsByClassName('XCUIElementTypeTextField');189 await els[0].type(text1);190 let text = await els[0].text();191 text.should.eql(text1);192 await driver.hideKeyboard();193 await els[1].type(text2);194 text = await els[1].text();195 text.should.eql(text2);196 await els[0].clear();197 text = await els[0].text();198 text.should.eql(phText);199 await driver.hideKeyboard();200 await els[1].clear();201 text = await els[1].text();202 text.should.eql(phText);203 });204 it('should clear a secure text field', async () => {205 let el = await driver.elementByClassName('XCUIElementTypeSecureTextField');206 await el.type(text1);207 let text = await el.text();208 text.should.eql(secureText);209 await el.clear();210 text = await el.text();211 text.should.eql(phText);212 });213 });214 describe('keys', () => {215 it('should be able to send text to the active element', async () => {216 let el = await driver.elementByClassName('XCUIElementTypeTextField');217 // make sure the keyboard is up218 await el.click();219 await driver.keys('this is a test');220 });221 it('should type a backspace', async () => {222 let el = await driver.elementByClassName('XCUIElementTypeTextField');223 // make sure the keyboard is up224 await el.click();225 await driver.keys('0123456789\uE003');226 let text = await el.text();227 text.should.eql('012345678');228 });229 it('should type a delete', async () => {230 let el = await driver.elementByClassName('XCUIElementTypeTextField');231 // make sure the keyboard is up232 await el.click();233 await driver.keys('0123456789\ue017');234 let text = await el.text();235 text.should.eql('012345678');236 });237 it('should type a newline', async () => {238 let el = await driver.elementByClassName('XCUIElementTypeTextField');239 // make sure the keyboard is up240 await el.click();241 await driver.keys('0123456789\uE006');242 let text = await el.text();243 text.should.eql('0123456789');244 });245 });246 describe('hide keyboard', () => {247 it('should be able to hide the keyboard', async () => {248 let el = await driver.elementByClassName('XCUIElementTypeTextField');249 await el.click();250 let db = await driver.elementByAccessibilityId('Done');251 (await db.isDisplayed()).should.be.true;252 await driver.hideKeyboard();253 // pause for a second to allow keyboard to go out of view254 // otherwise slow systems will reject the search for `Done` and255 // fast ones will get the element but it will be invisible256 await B.delay(1000);257 db = await driver.elementByAccessibilityId('Done').should.eventually.be.rejected;258 });259 });260 });261 describe('picker wheel', () => {262 it('should be able to set the value', async () => {263 let el = await driver.elementByAccessibilityId('Picker View');264 await el.click();265 let wheels = await driver.elementsByClassName('XCUIElementTypePickerWheel');266 let values = [65, 205, 120];267 for (let i = 0; i < 3; i++) {268 let wheel = wheels[i];269 let value = await wheel.getAttribute('value');270 parseInt(value, 10).should.eql(values[i]);271 await wheel.type(150);272 value = await wheel.getAttribute('value');273 parseInt(value, 10).should.eql(150);274 }275 });276 });277 });...

Full Screen

Full Screen

basics-base.js

Source:basics-base.js Github

copy

Full Screen

1"use strict";2var setup = require("../setup-base"),3 webviewHelper = require("../../../helpers/webview"),4 loadWebView = webviewHelper.loadWebView,5 isChrome = webviewHelper.isChrome,6 Q = require('q'),7 spinTitle = webviewHelper.spinTitle,8 spinWait = require('../../../helpers/spin.js').spinWait,9 skip = webviewHelper.skip;10module.exports = function (desired) {11 describe('basics', function () {12 var driver;13 setup(this, desired, {'no-reset': true}).then(function (d) { driver = d; });14 beforeEach(function (done) {15 loadWebView(desired, driver).nodeify(done);16 });17 it('should find a web element in the web view', function (done) {18 driver19 .elementById('i_am_an_id').should.eventually.exist20 .nodeify(done);21 });22 it('should find multiple web elements in the web view', function (done) {23 driver24 .elementsByTagName('a').should.eventually.have.length.above(0)25 .nodeify(done);26 });27 it('should fail gracefully to find multiple missing web elements in the web view', function (done) {28 driver29 .elementsByTagName('blar').should.eventually.have.length(0)30 .nodeify(done);31 });32 it('should find element from another element', function (done) {33 driver34 .elementByClassName('border')35 .elementByXPath('>', './form').should.eventually.exist36 .nodeify(done);37 });38 it('should be able to click links', function (done) {39 driver40 .elementByLinkText('i am a link').click()41 .then(function () { return spinTitle('I am another page title', driver); })42 .nodeify(done);43 });44 it('should retrieve an element attribute', function (done) {45 driver46 .elementById('i_am_an_id')47 .getAttribute("id").should.become('i_am_an_id')48 .elementById('i_am_an_id')49 .getAttribute("blar").should.not.eventually.exist50 .nodeify(done);51 });52 it('should retrieve implicit attributes', function (done) {53 driver54 .elementsByTagName('option')55 .then(function (els) {56 els.should.have.length(3);57 return els[2].getAttribute('index').should.become('2');58 }).nodeify(done);59 });60 it('should retrieve an element text', function (done) {61 driver62 .elementById('i_am_an_id').text().should.become('I am a div')63 .nodeify(done);64 });65 it('should check if two elements are equals', function (done) {66 Q.all([67 driver.elementById('i_am_an_id'),68 driver.elementByTagName('div')69 ]).then(function (els) {70 return els[0].equals(els[1]).should.be.ok;71 }).nodeify(done);72 });73 it('should return the page source', function (done) {74 driver75 .source()76 .then(function (source) {77 source.should.include('<html');78 source.should.include('I am a page title');79 source.should.include('i appear 3 times');80 source.should.include('</html>');81 }).nodeify(done);82 });83 it('should get current url', function (done) {84 driver85 .url().should.eventually.include("test/guinea-pig")86 .nodeify(done);87 });88 it('should send keystrokes to specific element', function (done) {89 driver90 .elementById('comments')91 .clear()92 .sendKeys("hello world")93 .getValue().should.become("hello world")94 .nodeify(done);95 });96 it('should send keystrokes to active element', function (done) {97 driver98 .elementById('comments')99 .clear()100 .click()101 .keys("hello world")102 .elementById('comments')103 .getValue().should.become("hello world")104 .nodeify(done);105 });106 it('should clear element', function (done) {107 driver108 .elementById('comments')109 .sendKeys("hello world")110 .getValue().should.eventually.have.length.above(0)111 .elementById('comments')112 .clear()113 .getValue().should.become("")114 .nodeify(done);115 });116 it('should say whether an input is selected', function (done) {117 driver118 .elementById('unchecked_checkbox')119 .selected().should.not.eventually.be.ok120 .elementById('unchecked_checkbox')121 .click()122 .selected().should.eventually.be.ok123 .nodeify(done);124 });125 it('should be able to retrieve css properties', function (done) {126 driver127 .elementById('fbemail').getComputedCss('background-color')128 .should.become("rgba(255, 255, 255, 1)")129 .nodeify(done);130 });131 it('should retrieve an element size', function (done) {132 driver133 .elementById('i_am_an_id').getSize()134 .then(function (size) {135 size.width.should.be.above(0);136 size.height.should.be.above(0);137 }).nodeify(done);138 });139 it('should get location of an element', function (done) {140 driver141 .elementById('fbemail')142 .getLocation()143 .then(function (loc) {144 loc.x.should.be.above(0);145 loc.y.should.be.above(0);146 }).nodeify(done);147 });148 it('should retrieve tag name of an element', function (done) {149 driver150 .elementById('fbemail').getTagName().should.become("input")151 .elementByCss("a").getTagName().should.become("a")152 .nodeify(done);153 });154 it('should retrieve a window size @skip-chrome', function (done) {155 driver156 .getWindowSize()157 .then(158 function (size) {159 size.height.should.be.above(0);160 size.width.should.be.above(0);161 }).nodeify(done);162 });163 it('should move to an arbitrary x-y element and click on it', function (done) {164 driver.elementByLinkText('i am a link')165 .moveTo(5, 15)166 .click()167 .then(function () { return spinTitle("I am another page title", driver); })168 .nodeify(done);169 });170 it('should submit a form', function (done) {171 driver172 .elementById('comments')173 .sendKeys('This is a comment')174 .submit()175 .then(function () {176 return spinWait(function () {177 return driver178 .elementById('your_comments')179 .text()180 .should.become('Your comments: This is a comment');181 });182 }183 ).nodeify(done);184 });185 it('should return true when the element is displayed', function (done) {186 driver187 .elementByLinkText('i am a link')188 .isDisplayed().should.eventually.be.ok189 .nodeify(done);190 });191 it('should return false when the element is not displayed', function (done) {192 driver193 .elementById('invisible div')194 .isDisplayed().should.not.eventually.be.ok195 .nodeify(done);196 });197 it('should return true when the element is enabled', function (done) {198 driver199 .elementByLinkText('i am a link')200 .isEnabled().should.eventually.be.ok201 .nodeify(done);202 });203 it('should return false when the element is not enabled', function (done) {204 driver205 .execute("$('#fbemail').attr('disabled', 'disabled');")206 .elementById('fbemail').isEnabled().should.not.eventually.be.ok207 .nodeify(done);208 });209 it("should return the active element", function (done) {210 var testText = "hi there";211 driver212 .elementById('i_am_a_textbox').sendKeys(testText)213 .active().getValue().should.become(testText)214 .nodeify(done);215 });216 it('should properly navigate to anchor', function (done) {217 driver218 .url().then(function (curl) {219 return driver.get(curl);220 }).nodeify(done);221 });222 it('should be able to refresh', function (done) {223 driver.refresh()224 .nodeify(done);225 });226 it('should be able to get performance logs', function (done) {227 if (!isChrome(desired)) return skip(228 "Performance logs aren't available except in Chrome", done);229 driver230 .logTypes()231 .should.eventually.include('performance')232 .log('performance').then(function (logs) {233 logs.length.should.be.above(0);234 }).nodeify(done);235 });236 });...

Full Screen

Full Screen

gesture-e2e-specs.js

Source:gesture-e2e-specs.js Github

copy

Full Screen

1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';3import B from 'bluebird';4import wd from 'wd';5import _ from 'lodash';6import { retryInterval } from 'asyncbox';7import { UICATALOG_CAPS } from '../desired';8import { initSession, deleteSession, MOCHA_TIMEOUT } from '../helpers/session';9import { APPIUM_IMAGE } from '../web/helpers';10chai.should();11chai.use(chaiAsPromised);12let expect = chai.expect;13describe('XCUITestDriver - gestures', function () {14 this.timeout(MOCHA_TIMEOUT);15 let driver;16 describe('dynamic gestures', () => {17 before(async () => {18 driver = await initSession(UICATALOG_CAPS);19 });20 beforeEach(async () => {21 await driver.back();22 });23 after(async () => {24 await deleteSession();25 });26 afterEach(async () => {27 // wait a moment to allow anything to happen28 await B.delay(500);29 });30 describe('tap, press, longpress', () => {31 beforeEach(async () => {32 let el = await driver.elementByAccessibilityId('Action Sheets');33 await driver.execute('mobile: scroll', {element: el, toVisible: true});34 await el.click();35 });36 describe('tap', () => {37 it('should tap on the element', async () => {38 let el1 = await driver.elementByAccessibilityId('Okay / Cancel');39 let action = new wd.TouchAction(driver);40 action.tap({el: el1});41 await action.perform();42 let el2 = await driver.elementByAccessibilityId('OK');43 await el2.click();44 });45 it('should tap on arbitrary coordinates', async () => {46 let el1 = await driver.elementByAccessibilityId('Okay / Cancel');47 let loc = await el1.getLocation();48 let action = new wd.TouchAction(driver);49 action.tap(loc);50 await action.perform();51 let el2 = await driver.elementByAccessibilityId('OK');52 await el2.click();53 });54 });55 it('should long press on an element', async () => {56 let el1 = await driver.elementByAccessibilityId('Okay / Cancel');57 let action = new wd.TouchAction(driver);58 action.longPress({el: el1});59 await action.perform();60 let el2 = await driver.elementByAccessibilityId('Cancel');61 await el2.click();62 });63 it('should long press on an element with duration through press-wait-release', async () => {64 let el1 = await driver.elementByAccessibilityId('Okay / Cancel');65 let action = new wd.TouchAction(driver);66 action.press({el: el1}).wait(1200).release();67 await action.perform();68 let el2 = await driver.elementByAccessibilityId('Cancel');69 await el2.click();70 });71 it('should long press on an element with duration through pressOpts.duration', async () => {72 let el1 = await driver.elementByAccessibilityId('Okay / Cancel');73 let action = new wd.TouchAction(driver);74 action.longPress({el: el1, duration: 1200});75 await action.perform();76 let el2 = await driver.elementByAccessibilityId('Cancel');77 await el2.click();78 });79 it('should long press on arbitrary coordinate', async () => {80 let el1 = await driver.elementByAccessibilityId('Okay / Cancel');81 let loc = await el1.getLocation();82 let action = new wd.TouchAction(driver);83 action.press(loc).wait(500).release();84 await action.perform();85 let el2 = await driver.elementByAccessibilityId('OK');86 await el2.click();87 });88 });89 it('should scroll using touch actions', async function () {90 let el1 = await driver.elementByAccessibilityId('Action Sheets');91 let el2 = await driver.elementByAccessibilityId('Text Fields');92 let action = new wd.TouchAction(driver);93 action.press({el: el1}).moveTo({el: el2}).release();94 await action.perform();95 let el3 = await driver.elementByAccessibilityId('Text Fields');96 await el3.click().should.not.be.rejected;97 });98 it('should double tap on an element', async () => {99 let el = await driver.elementByAccessibilityId('Steppers');100 await driver.execute('mobile: scroll', {element: el, toVisible: true});101 await el.click();102 let stepper = await driver.elementByAccessibilityId('Increment');103 let action = new wd.TouchAction(driver);104 action.tap({el: stepper, count: 2});105 await action.perform();106 await driver.elementByAccessibilityId('2').should.not.be.rejected;107 });108 it(`should swipe the table and the bottom cell's Y position should change accordingly`, async () => {109 let winEl = await driver.elementByClassName('XCUIElementTypeWindow');110 let toolbarsEl = await driver.elementByAccessibilityId('Toolbars');111 let yInit = (await toolbarsEl.getLocation()).y;112 await driver.execute('mobile: swipe', {element: winEl, direction: 'up'}).should.not.be.rejected;113 expect((await toolbarsEl.getLocation()).y).to.be.above(yInit);114 await driver.execute('mobile: swipe', {element: winEl, direction: 'down'}).should.not.be.rejected;115 expect((await toolbarsEl.getLocation()).y).to.equal(yInit);116 });117 describe('pinch and zoom', () => {118 beforeEach(async () => {119 let el = await driver.elementByAccessibilityId('Web View');120 await driver.execute('mobile: scroll', {element: el, toVisible: true});121 await el.click();122 });123 // at this point this test relies on watching it happen, nothing is asserted124 // in automation, this just checks that errors aren't thrown125 it('should be able to pinch', async () => {126 let ctxs;127 await retryInterval(10, 1000, async () => {128 // on some systems (like Travis) it takes a while to load the webview129 ctxs = await driver.contexts();130 if (ctxs.length === 1) {131 throw new Error('No webview context found');132 }133 });134 await driver.context(ctxs[1]);135 await driver.get(APPIUM_IMAGE);136 await driver.context(ctxs[0]);137 async function doZoom () {138 let el = await driver.elementByClassName('XCUIElementTypeApplication');139 let thumb = new wd.TouchAction(driver);140 thumb.press({el, x: 100, y: 0}).moveTo({el, x: 50, y: 0}).release();141 let foreFinger = new wd.TouchAction(driver);142 foreFinger.press({el, x: 100, y: 0}).moveTo({el, x: 105, y: 0}).release();143 let zoom = new wd.MultiAction(driver);144 zoom.add(thumb, foreFinger);145 await zoom.perform();146 }147 await doZoom();148 async function doPinch () {149 let el = await driver.elementByClassName('XCUIElementTypeApplication');150 let thumb = new wd.TouchAction(driver);151 thumb.press({el, x: 50, y: 0}).moveTo({el, x: 100, y: 0}).release();152 let foreFinger = new wd.TouchAction(driver);153 foreFinger.press({el, x: 100, y: 0}).moveTo({el, x: 50, y: 0}).release();154 let pinch = new wd.MultiAction(driver);155 pinch.add(thumb, foreFinger);156 await pinch.perform();157 }158 await doPinch();159 });160 });161 });162 describe('tap with tapWithShortPressDuration cap', () => {163 // needs a special cap, so has to be in its own session164 before(async () => {165 driver = await initSession(_.defaults({166 tapWithShortPressDuration: 0.01167 }, UICATALOG_CAPS));168 });169 after(async () => {170 await deleteSession();171 });172 it('should tap on the element', async () => {173 let el1 = await driver.elementByAccessibilityId('Action Sheets');174 let action = new wd.TouchAction(driver);175 action.tap({el: el1});176 action.perform();177 // pause a moment so the alert can animate178 await B.delay(500);179 let el2 = await driver.elementByAccessibilityId('Okay / Cancel');180 el2.should.exist;181 });182 });...

Full Screen

Full Screen

touch-id-e2e-specs.js

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

copy

Full Screen

1// transpile:mocha2import chai from 'chai';3import chaiAsPromised from 'chai-as-promised';4import { TOUCHIDAPP_CAPS } from '../desired';5import { initSession, deleteSession, MOCHA_TIMEOUT } from '../helpers/session';6import B from 'bluebird';7import { killAllSimulators } from 'appium-ios-simulator';8chai.should();9chai.use(chaiAsPromised);10describe('touchID() ', function () {11 this.timeout(MOCHA_TIMEOUT);12 let caps, driver;13 beforeEach(async () => {14 await killAllSimulators();15 });16 afterEach(async () => {17 await deleteSession();18 await B.delay(500);19 });20 after(async () => {21 await killAllSimulators();22 });23 it('should throw an error if allowTouchIdEnroll desired capability is not set', async () => {24 await killAllSimulators();25 caps = Object.assign(TOUCHIDAPP_CAPS);26 caps.allowTouchIdEnroll = false;27 driver = await initSession(caps);28 await driver.toggleTouchIdEnrollment().should.be.rejectedWith(/enroll touchId/);29 });30 describe('touchID enrollment functional tests applied to TouchId sample app', function () {31 beforeEach(async () => {32 caps = Object.assign(TOUCHIDAPP_CAPS);33 caps.allowTouchIdEnroll = true;34 driver = await initSession(caps);35 await B.delay(2000); // Give the app a couple seconds to open36 });37 it('should not support touchID if not enrolled', async () => {38 let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');39 await authenticateButton.click();40 await driver.elementByName('TouchID not supported').should.eventually.exist;41 });42 it('should accept matching fingerprint if touchID is enrolled or it should not be supported if phone doesn\'t support touchID', async () => {43 await driver.toggleTouchIdEnrollment();44 let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');45 await authenticateButton.click();46 await driver.touchId(true);47 try {48 await driver.elementByName('Authenticated Successfully').should.eventually.exist;49 } catch (ign) {50 await driver.elementByName('TouchID not supported').should.eventually.exist;51 }52 await driver.toggleTouchIdEnrollment();53 });54 it('should reject not matching fingerprint if touchID is enrolled or it should not be supported if phone doesn\'t support touchID', async () => {55 await driver.toggleTouchIdEnrollment();56 let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');57 await authenticateButton.click();58 await driver.touchId(false);59 try {60 await driver.elementByName('Try Again').should.eventually.exist;61 } catch (ign) {62 await driver.elementByName('TouchID not supported').should.eventually.exist;63 }64 await driver.toggleTouchIdEnrollment();65 });66 it('should enroll touchID and accept matching fingerprints then unenroll touchID and not be supported', async () => {67 // Don't enroll68 let authenticateButton = await driver.elementByName(' Authenticate with Touch ID');69 await authenticateButton.click();70 await driver.elementByName('TouchID not supported').should.eventually.exist;71 let okButton = await driver.elementByName('OK');72 await okButton.click();73 await B.delay(1000);74 // Enroll75 await driver.toggleTouchIdEnrollment();76 await authenticateButton.click();77 await driver.touchId(true);78 try {79 await driver.elementByName('Authenticated Successfully').should.eventually.exist;80 } catch (ign) {81 return await driver.elementByName('TouchID not supported').should.eventually.exist;82 }83 okButton = await driver.elementByName('OK');84 await okButton.click();85 await B.delay(1000);86 // Unenroll87 await driver.toggleTouchIdEnrollment();88 authenticateButton = await driver.elementByName(' Authenticate with Touch ID');89 await authenticateButton.click();90 await driver.elementByName('TouchID not supported').should.eventually.exist;91 });92 });...

Full Screen

Full Screen

follows.test.js

Source:follows.test.js Github

copy

Full Screen

1import it from '../helpers/appium';2import server from '../helpers/server';3import fixtures from '../helpers/fixtures';4import bootstrap from '../helpers/bootstrap';5describe("Follows", () => {6 it("should show my follows", function* (driver, done) {7 server.get("/api/follows/tester", fixtures.myFollows());8 yield bootstrap().login().nav("dashboard/follows").launch(driver);9 10 yield driver.elementById('Dashboard');11 yield driver.elementById('friend');12 yield driver.elementById('follow2');13 done();14 });15 it("should show an empty list", function* (driver, done) {16 server.get("/api/follows/tester", { username: "tester", follows: [] });17 yield bootstrap().login().nav("dashboard/follows").launch(driver);18 yield driver.elementById('Follows');19 yield driver.elementById('No items');20 done();21 });22 it("should my friends's follows", function* (driver, done) {23 server.get("/api/follows/friend", fixtures.friendFollows());24 yield bootstrap().login().nav("dashboard/follows/friend/follows").launch(driver);25 yield driver.elementById('friend');26 yield driver.elementById('tester');27 yield driver.elementById('follow4');28 done();29 });30 it("should navigate follows recursively", function* (driver, done) {31 server.get("/api/posts/tester", fixtures.home());32 server.get("/api/posts/friend", fixtures.friend());33 server.get("/api/posts/follow4", { 34 username: "follow4", 35 posts: [ { id: 1000, username: 'follow4', content: 'post1000' }]36 });37 server.get("/api/follows/friend", fixtures.friendFollows());38 server.get("/api/follows/tester", fixtures.myFollows());39 server.get("/api/follows/follow4", { username: "follow4", follows: [ { id: 123, username: 'tester' }] });40 yield bootstrap().login().launch(driver);41 yield driver.elementById("Dashboard");42 yield driver.elementById("post1"); // my post43 // yield driver.sleep(90000000);44 yield driver.elementById("segFollows_tester").click(); // open my follows45 yield driver.elementById('friend').click(); // click on friend46 yield driver.elementById("friend"); // friend's list47 yield driver.elementById("post4"); // friend's post48 yield driver.elementById("segFollows_friend").click(); // open friend's follows49 yield driver.elementById('follow4').click(); // click on other50 yield driver.elementById("follow4"); // other's list51 yield driver.elementById("post100"); // other's post52 yield driver.elementById("segFollows_follow4").click(); // open other's follows53 yield driver.elementById('tester').click(); // click on me54 // TODO: it should NOT say "Dashboard" 55 yield driver.elementById("tester"); // my list56 yield driver.elementById("post1"); // my post57 // Now pop everything58 yield driver.elementById("back").click(); // back59 yield driver.elementById("follow4");60 yield driver.elementById("back").click(); // back61 yield driver.elementById("friend");62 yield driver.elementById("back").click(); // back63 yield driver.elementById("Dashboard");64 done();65 });...

Full Screen

Full Screen

posts.test.js

Source:posts.test.js Github

copy

Full Screen

1import it, {itOnly} from '../helpers/appium';2import server from '../helpers/server';3import fixtures from '../helpers/fixtures';4import bootstrap from '../helpers/bootstrap';5describe("Posts", () => {6 it("should show my posts", function* (driver, done) {7 server.get("/api/posts/tester", fixtures.home());8 yield bootstrap().login().nav("dashboard").launch(driver);9 10 yield driver.elementById('Dashboard');11 yield driver.elementById('post1');12 done();13 });14 it("should show an empty list", function* (driver, done) {15 server.get("/api/posts/tester", { username: "tester", posts: [] });16 yield bootstrap().login().nav("dashboard").launch(driver);17 yield driver.elementById('Dashboard');18 yield driver.elementById('No items');19 done();20 });21 it("should my friends's posts", function* (driver, done) {22 server.get("/api/posts/friend", fixtures.friend());23 yield bootstrap().login().nav("dashboard/follows/friend").launch(driver);24 yield driver.elementById('friend');25 yield driver.elementById('post3');26 done();27 });28 it("should create a new post", function* (driver, done) {29 var list = fixtures.home();30 server.get("/api/posts/tester", list);31 server.post("/api/posts",32 {id: 100, content: 'new post here', username: 'tester'}, // return this content33 {content: 'new post here'} // expect this content34 );35 yield bootstrap().login().launch(driver);36 yield driver.elementById('+').click(); // new post!37 yield driver.elementById('New Post');38 yield driver.execute("target.frontMostApp().keyboard().typeString('new post here')");39 yield driver.elementById('Submit').click();40 yield driver.elementById('Dashboard');41 yield driver.elementById('new post here'); // it's there!42 done();43 });...

Full Screen

Full Screen

authentication.test.js

Source:authentication.test.js Github

copy

Full Screen

1import it from '../helpers/appium';2import server from '../helpers/server';3import fixtures from '../helpers/fixtures';4describe("Authentication", () => {5 beforeEach(() => {6 server.get("/api/posts/tester", fixtures.home());7 });8 it("should sign up the user and show dashboard", function* (driver, done) {9 server.post("api/signup", fixtures.signup());10 11 var username = yield driver.elementById('Username');12 var password = yield driver.elementById('Password');13 var button = yield driver.elementById('Sign up');14 yield username.setImmediateValue("tester");15 yield password.setImmediateValue("sample");16 yield button.click();17 // make sure logged in18 yield driver.elementById('Dashboard');19 yield driver.elementById('post1');20 done();21 });22 it("should log in and out", function* (driver, done) {23 server.post("api/login", fixtures.signup());24 yield driver.elementById('Already a user? Login here.').click();25 26 var username = yield driver.elementById('Username');27 var password = yield driver.elementById('Password');28 var button = yield driver.elementById('Log in');29 yield username.setImmediateValue("tester");30 yield password.setImmediateValue("sample");31 yield button.click();32 // make sure logged in33 yield driver.elementById('Dashboard');34 yield driver.elementById('post1');35 // show settings, log out36 yield driver.elementByXPath('//UIAApplication[1]/UIAWindow[1]/UIAElement[4]').click(); // "Me"37 yield driver.elementById('Settings');38 yield driver.elementById('Log out').click();39 // back on signup40 yield driver.elementById('Already a user? Login here.');41 done();42 });...

Full Screen

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();13var webdriver = require('selenium-webdriver');14var driver = new webdriver.Builder()15 .forBrowser('chrome')16 .build();17driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');18driver.findElement(webdriver.By.name('btnG')).click();19driver.wait(function() {20 return driver.getTitle().then(function(title) {21 return title === 'webdriver - Google Search';22 });23}, 1000);24driver.quit();25These are the methods that perform an action on the webpage. For example, the method driver.findElement() finds an element on the webpage. The method driver.quit() closes the browser window. The method driver.getTitle() returns the title of the current webpage. These methods are called commands because

Full Screen

Using AI Code Generation

copy

Full Screen

1const driver = wd.promiseChainRemote({2});3driver.init({4}).then(function() {5}).then(function(el) {6 return el.click();7}).catch(function(err) {8 console.log(err);9});10const driver = wd.promiseChainRemote({11});12driver.init({13}).then(function() {14}).then(function(els) {15 return els[0].click();16}).catch(function(err) {17 console.log(err);18});19const driver = wd.promiseChainRemote({20});21driver.init({22}).then(function() {23}).then(function(el) {24 return el.click();25}).catch(function(err) {26 console.log(err);27});28const driver = wd.promiseChainRemote({29});30driver.init({

Full Screen

Using AI Code Generation

copy

Full Screen

1exports.driver = driver;2exports.element = driver.element;3exports.elementById = driver.elementById;4exports.elementByName = driver.elementByName;5exports.elementByClassName = driver.elementByClassName;6exports.elementByXPath = driver.elementByXPath;7exports.elementByCssSelector = driver.elementByCssSelector;8exports.elementByLinkText = driver.elementByLinkText;9exports.elementByPartialLinkText = driver.elementByPartialLinkText;10exports.elementByTagName = driver.elementByTagName;11exports.elementByAndroidUIAutomator = driver.elementByAndroidUIAutomator;12exports.elementByIosUIAutomation = driver.elementByIosUIAutomation;13exports.elementByAccessibilityId = driver.elementByAccessibilityId;14exports.elements = driver.elements;15exports.elementsById = driver.elementsById;16exports.elementsByName = driver.elementsByName;17exports.elementsByClassName = driver.elementsByClassName;18exports.elementsByXPath = driver.elementsByXPath;19exports.elementsByCssSelector = driver.elementsByCssSelector;20exports.elementsByLinkText = driver.elementsByLinkText;21exports.elementsByPartialLinkText = driver.elementsByPartialLinkText;22exports.elementsByTagName = driver.elementsByTagName;23exports.elementsByAndroidUIAutomator = driver.elementsByAndroidUIAutomator;24exports.elementsByIosUIAutomation = driver.elementsByIosUIAutomation;25exports.elementsByAccessibilityId = driver.elementsByAccessibilityId;26exports.waitForElement = driver.waitForElement;27exports.waitForElementById = driver.waitForElementById;28exports.waitForElementByName = driver.waitForElementByName;29exports.waitForElementByClassName = driver.waitForElementByClassName;30exports.waitForElementByXPath = driver.waitForElementByXPath;31exports.waitForElementByCssSelector = driver.waitForElementByCssSelector;32exports.waitForElementByLinkText = driver.waitForElementByLinkText;33exports.waitForElementByPartialLinkText = driver.waitForElementByPartialLinkText;34exports.waitForElementByTagName = driver.waitForElementByTagName;35exports.waitForElementByAndroidUIAutomator = driver.waitForElementByAndroidUIAutomator;36exports.waitForElementByIosUIAutomation = driver.waitForElementByIosUIAutomation;37exports.waitForElementByAccessibilityId = driver.waitForElementByAccessibilityId;38exports.waitForElements = driver.waitForElements;39exports.waitForElementsById = driver.waitForElementsById;40exports.waitForElementsByName = driver.waitForElementsByName;

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.element('id', 'com.example.android.contactmanager:id/addContactButton', function(err, el) {2 if (err) throw err;3 el.click();4});5driver.elements('id', 'com.example.android.contactmanager:id/addContactButton', function(err, el) {6 if (err) throw err;7 el.click();8});9driver.elementBy('id', 'com.example.android.contactmanager:id/addContactButton', function(err, el) {10 if (err) throw err;11 el.click();12});13driver.elementsBy('id', 'com.example.android.contactmanager:id/addContactButton', function(err, el) {14 if (err) throw err;15 el.click();16});17driver.elementById('com.example.android.contactmanager:id/addContactButton', function(err, el) {18 if (err) throw err;19 el.click();20});21driver.elementsById('com.example.android.contactmanager:id/addContactButton', function(err, el) {22 if (err) throw err;23 el.click();24});25driver.elementByName('Add Contact', function(err, el) {26 if (err) throw err;27 el.click();28});29driver.elementsByName('Add Contact', function(err, el) {30 if (err) throw err;31 el.click();32});33driver.elementByClassName('android.widget.Button', function(err, el) {34 if (err) throw err;35 el.click();36});37driver.elementsByClassName('android.widget.Button', function(err, el) {38 if (err) throw err;39 el.click();40});41driver.elementByCssSelector('android.widget.Button', function(err, el) {42 if (err) throw err;43 el.click();44});45driver.elementsByCssSelector('android.widget.Button', function(err, el) {

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