How to use driver.getAttribute method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

element-specs.js

Source:element-specs.js Github

copy

Full Screen

...23 });24 describe('getAttribute', () => {25 it('should get element attribute', async () => {26 driver.bootstrap.sendAction.withArgs('element:getAttribute').returns('attr_value');27 await driver.getAttribute('attr', 'el1').should.become('attr_value');28 driver.bootstrap.sendAction29 .calledWithExactly('element:getAttribute', {attribute: 'attr', elementId: 'el1'})30 .should.be.true;31 });32 });33 describe('getName', () => {34 it('should get element name', async () => {35 sandbox.stub(driver, 'getAttribute');36 driver.getAttribute.returns('el_name');37 await driver.getName('el1').should.become('el_name');38 driver.getAttribute.calledWithExactly('className', 'el1').should.be.true;39 });40 });41 describe('elementDisplayed', () => {...

Full Screen

Full Screen

image-element-specs.js

Source:image-element-specs.js Github

copy

Full Screen

1import _ from 'lodash';2import chai from 'chai';3import chaiAsPromised from 'chai-as-promised';4import BaseDriver, { ImageElement } from '../..';5import { makeImageElementCache, getImgElFromArgs } from '../../lib/basedriver/image-element';6import { IMAGE_ELEMENT_PREFIX } from '../../lib/constants';7import sinon from 'sinon';8chai.should();9chai.use(chaiAsPromised);10const defRect = {x: 100, y: 110, width: 50, height: 25};11const defTemplate = 'iVBORasdf';12describe('ImageElement', function () {13 const driver = new BaseDriver();14 describe('.size', function () {15 it('should return the width and height of the image el', function () {16 const el = new ImageElement(defTemplate, defRect);17 el.size.should.eql({width: defRect.width, height: defRect.height});18 });19 });20 describe('.location', function () {21 it('should return the location of the image el', function () {22 const el = new ImageElement(defTemplate, defRect);23 el.location.should.eql({x: defRect.x, y: defRect.y});24 });25 });26 describe('.center', function () {27 it('should return the center location of the image el', function () {28 const el = new ImageElement(defTemplate, defRect);29 el.center.should.eql({30 x: defRect.x + defRect.width / 2,31 y: defRect.y + defRect.height / 232 });33 });34 });35 describe('.asElement', function () {36 it('should get the webdriver object representation of the element', function () {37 const el = new ImageElement(defTemplate, defRect);38 el.asElement('ELEMENT').ELEMENT.should.match(/^appium-image-el/);39 });40 });41 describe('.equals', function () {42 it('should say two image elements with same rect are equal', function () {43 const el1 = new ImageElement('foo', defRect);44 const el2 = new ImageElement('bar', defRect);45 el1.equals(el2).should.be.true;46 el2.equals(el1).should.be.true;47 });48 it('should say two image elements with different rect are not equal', function () {49 const el1 = new ImageElement(defTemplate, {...defRect, x: 0});50 const el2 = new ImageElement(defTemplate, defRect);51 el1.equals(el2).should.be.false;52 el2.equals(el1).should.be.false;53 });54 });55 describe('.click', function () {56 it('should reject an invalid tap strategy', async function () {57 const d = new BaseDriver();58 const el = new ImageElement(defTemplate, defRect);59 await d.settings.update({imageElementTapStrategy: 'bad'});60 await el.click(d).should.eventually.be.rejectedWith(/Incorrect imageElementTapStrategy/);61 });62 it('should try to check for image element staleness, and throw if stale', async function () {63 const d = new BaseDriver();64 sinon.stub(d, 'findByImage').throws();65 const el = new ImageElement(defTemplate, defRect);66 // we need to check for staleness if explicitly requested to do so67 await d.settings.update({68 checkForImageElementStaleness: true,69 autoUpdateImageElementPosition: false70 });71 await el.click(d).should.eventually.be.rejectedWith(/no longer attached/);72 // and also if we are updating the element position73 await d.settings.update({74 checkForImageElementStaleness: false,75 autoUpdateImageElementPosition: true76 });77 await el.click(d).should.eventually.be.rejectedWith(/no longer attached/);78 });79 it('should auto-update element position if requested', async function () {80 const d = new BaseDriver();81 d.performActions = _.noop;82 sinon.stub(d, 'performActions');83 const el = new ImageElement(defTemplate, defRect);84 const newRect = {...defRect, x: defRect.x + 10, y: defRect.y + 5};85 const elPos2 = new ImageElement(defTemplate, newRect);86 sinon.stub(d, 'findByImage').returns(elPos2);87 await d.settings.update({88 autoUpdateImageElementPosition: true,89 });90 el.rect.should.not.eql(newRect);91 await el.click(d);92 el.rect.should.eql(newRect);93 });94 it('should tap the center of an element using w3c actions by default', async function () {95 const d = new BaseDriver();96 d.performActions = _.noop;97 const actionStub = sinon.stub(d, 'performActions');98 const el = new ImageElement(defTemplate, defRect);99 // skip the staleness check for this test100 await d.settings.update({101 checkForImageElementStaleness: false,102 });103 await el.click(d);104 const pointerMoveAction = actionStub.args[0][0][0].actions[0];105 pointerMoveAction.x.should.equal(el.center.x);106 pointerMoveAction.y.should.equal(el.center.y);107 });108 it('should fall back to touchactions if w3c actions do not exist on driver', async function () {109 const d = new BaseDriver();110 d.performTouch = _.noop;111 const actionStub = sinon.stub(d, 'performTouch');112 const el = new ImageElement(defTemplate, defRect);113 // skip the staleness check for this test114 await d.settings.update({115 checkForImageElementStaleness: false,116 });117 await el.click(d);118 const action = actionStub.args[0][0][0].options;119 action.x.should.equal(el.center.x);120 action.y.should.equal(el.center.y);121 });122 it('should use touchactions if requested', async function () {123 const d = new BaseDriver();124 d.performActions = _.noop;125 const w3cStub = sinon.stub(d, 'performActions');126 d.performTouch = _.noop;127 const touchStub = sinon.stub(d, 'performTouch');128 const el = new ImageElement(defTemplate, defRect);129 // skip the staleness check for this test130 await d.settings.update({131 checkForImageElementStaleness: false,132 imageElementTapStrategy: 'touchActions',133 });134 await el.click(d);135 const action = touchStub.args[0][0][0].options;136 action.x.should.equal(el.center.x);137 action.y.should.equal(el.center.y);138 w3cStub.callCount.should.eql(0);139 });140 it('should throw if driver does not implement any type of action', async function () {141 const d = new BaseDriver();142 const el = new ImageElement(defTemplate, defRect);143 // skip the staleness check for this test144 await d.settings.update({145 checkForImageElementStaleness: false,146 });147 await el.click(d).should.eventually.be.rejectedWith(/did not implement/);148 });149 });150 describe('#execute', function () {151 // aGFwcHkgdGVzdGluZw== is 'happy testing'152 const imgEl = new ImageElement(defTemplate, defRect, 0, 'aGFwcHkgdGVzdGluZw==');153 const clickStub = sinon.stub(imgEl, 'click');154 before(function () {155 driver._imgElCache.set(imgEl.id, imgEl);156 clickStub.returns(true);157 });158 after(function () {159 driver._imgElCache.reset();160 clickStub.restore();161 });162 it('should reject executions on elements not in the cache', async function () {163 await ImageElement.execute(driver, 'click', 'appium-image-element-foo')164 .should.eventually.be.rejectedWith(/element could not be located/);165 });166 it('should reject executions for unsupported commands', async function () {167 await ImageElement.execute(driver, 'foobar', imgEl.id)168 .should.eventually.be.rejectedWith(/not yet been implemented/);169 });170 it('should get displayed status of element', async function () {171 await ImageElement.execute(driver, 'elementDisplayed', imgEl.id)172 .should.eventually.be.true;173 });174 it('should get size of element', async function () {175 await ImageElement.execute(driver, 'getSize', imgEl.id)176 .should.eventually.eql({width: defRect.width, height: defRect.height});177 });178 it('should get location of element', async function () {179 await ImageElement.execute(driver, 'getLocation', imgEl.id)180 .should.eventually.eql({x: defRect.x, y: defRect.y});181 });182 it('should get location in view of element', async function () {183 await ImageElement.execute(driver, 'getLocation', imgEl.id)184 .should.eventually.eql({x: defRect.x, y: defRect.y});185 });186 it('should get rect of element', async function () {187 await ImageElement.execute(driver, 'getElementRect', imgEl.id)188 .should.eventually.eql(defRect);189 });190 it('should get score of element', async function () {191 await ImageElement.execute(driver, 'getAttribute', imgEl.id, 'score')192 .should.eventually.eql(0);193 });194 it('should get visual of element', async function () {195 await ImageElement.execute(driver, 'getAttribute', imgEl.id, 'visual')196 .should.eventually.eql('aGFwcHkgdGVzdGluZw==');197 });198 it('should get null as visual of element by default', async function () {199 const imgElement = new ImageElement(defTemplate, defRect);200 driver._imgElCache.set(imgElement.id, imgElement);201 await ImageElement.execute(driver, 'getAttribute', imgElement.id, 'visual')202 .should.eventually.eql(null);203 });204 it('should not get other attribute', async function () {205 await ImageElement.execute(driver, 'getAttribute', imgEl.id, 'content-desc')206 .should.eventually.rejectedWith('Method has not yet been implemented');207 });208 it('should click element', async function () {209 await ImageElement.execute(driver, 'click', imgEl.id)210 .should.eventually.be.true;211 });212 });213});214describe('image element LRU cache', function () {215 it('should accept and cache image elements', function () {216 const el1 = new ImageElement(defTemplate, defRect);217 const el2 = new ImageElement(defTemplate, defRect);218 const cache = makeImageElementCache();219 cache.set(el1.id, el1);220 el1.equals(cache.get(el1.id)).should.be.true;221 _.isUndefined(cache.get(el2.id)).should.be.true;222 cache.has(el1.id).should.be.true;223 cache.has(el2.id).should.be.false;224 });225 it('once cache reaches max size, should eject image elements', function () {226 const el1 = new ImageElement(defTemplate, defRect);227 const el2 = new ImageElement(defTemplate, defRect);228 const cache = makeImageElementCache(defTemplate.length + 1);229 cache.set(el1.id, el1);230 cache.has(el1.id).should.be.true;231 cache.set(el2.id, el2);232 cache.has(el2.id).should.be.true;233 cache.has(el1.id).should.be.false;234 });235});236describe('getImgElFromArgs', function () {237 it('should return the image element id from json obj in args', function () {238 const imgEl = `${IMAGE_ELEMENT_PREFIX}foo`;239 const args = [1, 'foo', imgEl];240 getImgElFromArgs(args).should.eql(imgEl);241 });242 it('should not return anything if image element id not in args', function () {243 const args = [1, 'foo'];244 _.isUndefined(getImgElFromArgs(args)).should.be.true;245 });246 it('should not find image element id in anything but prefix', function () {247 const notImgEl = `foo${IMAGE_ELEMENT_PREFIX}`;248 const args = [1, 'foo', notImgEl];249 _.isUndefined(getImgElFromArgs(args)).should.be.true;250 });...

Full Screen

Full Screen

localstorage.js

Source:localstorage.js Github

copy

Full Screen

1/*2localStorage3IE 8+4Firefox 3.5+5Safari 4+6Chrome 4+7Opera 10.5+8iPhone 2+9Android 2+10sessionStorage11IE 8+12Firefox 2+13Safari 4+14Chrome15Opera 10.5+16iPhone 2+17Android 2+18globalStorage19Firefox 2+20Firefox 2.x 21Firefox 3.0.x22Database Storage23Safari 3.1 24Safari 3.225userData26IE 5 - 727https://github.com/rgrove/storage-lite28http://amplifyjs.com/api/store/29author yao.zhou@dianping.com 30*/31(function (WIN) {32 var NOOP = function () { },33 DOC = document,34 DB_NAME = 'html5_storage',35 DB_DISPLAYNAME = 'html5 storage data',36 DB_MAXSIZE = 1048576,37 DB_VERSION = '1.0',38 USERDATA_PATH = 'html5_storage',39 USERDATA_NAME = 'data',40 MODE_NOOP = 0,41 MODE_HTML5 = 1,42 MODE_GECKO = 2,43 MODE_DB = 3,44 MODE_USERDATA = 445 ;46 var 47 data = {},48 readys = [],49 storageDriver,50 storageMode51 ;52 function _mix(r, s) {53 var key;54 for (key in s) {55 r[key] = s[key];56 }57 return r;58 };59 try {60 if (WIN.localStorage) {61 storageMode = MODE_HTML5;62 } else if (WIN.globalStorage) {63 // Gecko globalStorage methods. Supported by Firefox 2 and 3.0.64 storageMode = MODE_GECKO;65 } else if (WIN.openDatabase && navigator.userAgent.indexOf('Chrome') === -1) {66 // Database storage methods. Supported by Safari 3.1 and 3.2.67 storageMode = MODE_DB;68 } else if (D.UA.ie >= 5) {69 // userData storage methods. Supported by IE5, 6, and 7.70 storageMode = MODE_USERDATA;71 } else {72 storageMode = MODE_NOOP;73 };74 } catch (ex) {75 storageMode = MODE_NOOP;76 };77 var Storage = {78 /**79 * @public80 * @method clear81 * @description 全部清除82 */83 clear: NOOP,84 /**85 * @public86 * @method length87 * @description 获存储数量88 * @return {Number}89 */90 length: function () { return 0; },91 /**92 * @public93 * @method getItem94 * @param key {string}95 * @param json {bool}96 * @description 获取值97 * @return {Object}98 */99 getItem: NOOP,100 /**101 * @public102 * @method removeItem103 * @param key {string}104 * @description 移除值105 */106 removeItem: NOOP,107 /**108 * @public109 * @method setItem110 * @param key {string}111 * @param value {object}112 * @description 存储值113 */114 setItem: NOOP,115 /**116 * @public117 * @method ready118 * @description 组件准备完毕119 */120 ready: function (fn) {121 if (Storage.isReady) {122 fn();123 } else {124 readys.push(fn);125 };126 },127 isReady: false128 };129 function _doReady() {130 DOC.body.appendChild(storageDriver);131 storageDriver.load(USERDATA_PATH);132 try {133 data = JSON.parse(storageDriver.getAttribute(USERDATA_NAME) || '{}');134 } catch (ex) {135 data = {};136 };137 Storage.isReady = true;138 };139 if (storageMode === MODE_HTML5 || storageMode === MODE_GECKO) {140 _mix(Storage, {141 length: function () {142 return storageDriver.length;143 },144 removeItem: function (key) {145 storageDriver.removeItem(key);146 },147 setItem: function (key, value, json) {148 if (value === undefined || value === null) {149 Storage.removeItem(key);150 } else {151 storageDriver.setItem(key, json ? JSON.stringify(value) : value);152 };153 }154 });155 if (storageMode === MODE_HTML5) {156 storageDriver = WIN.localStorage;157 _mix(Storage, {158 clear: function () {159 storageDriver.clear();160 },161 getItem: function (key, json) {162 try {163 return json ? JSON.parse(storageDriver.getItem(key)) :164 storageDriver.getItem(key);165 } catch (ex) {166 return null;167 };168 }169 });170 } else if (storageMode === MODE_GECKO) {171 storageDriver = WIN.globalStorage[WIN.location.hostname];172 _mix(Storage, {173 clear: function () {174 for (var key in storageDriver) {175 if (storageDriver.hasOwnProperty(key)) {176 storageDriver.removeItem(key);177 delete storageDriver[key];178 };179 };180 },181 getItem: function (key, json) {182 try {183 return json ? JSON.parse(storageDriver[key].value) :184 storageDriver[key].value;185 } catch (ex) {186 return null;187 };188 }189 });190 };191 Storage.isReady = true;192 } else if (storageMode === MODE_DB || storageMode === MODE_USERDATA) {193 _mix(Storage, {194 clear: function () {195 data = {};196 Storage._save();197 },198 getItem: function (key, json) {199 return data.hasOwnProperty(key) ? data[key] : null;200 },201 length: function () {202 var count = 0, key;203 for (key in data) {204 if (data.hasOwnProperty(key)) {205 count += 1;206 }207 };208 return count;209 },210 removeItem: function (key) {211 delete data[key];212 Storage._save();213 },214 setItem: function (key, value, json) {215 if (value === undefined || value === null) {216 Storage.removeItem(key);217 } else {218 data[key] = value.toString();219 Storage._save();220 };221 }222 });223 if (storageMode === MODE_DB) {224 storageDriver = WIN.openDatabase(DB_NAME, DB_VERSION, DB_DISPLAYNAME, DB_MAXSIZE);225 _mix(Storage, {226 _save: function () {227 storageDriver.transaction(function (t) {228 t.executeSql("REPLACE INTO " + DB_NAME + " (name, value) VALUES ('data', ?)", [JSON.stringify(data)]);229 });230 }231 });232 storageDriver.transaction(function (t) {233 t.executeSql("CREATE TABLE IF NOT EXISTS " + DB_NAME + "(name TEXT PRIMARY KEY, value TEXT NOT NULL)");234 t.executeSql("SELECT value FROM " + DB_NAME + " WHERE name = 'data'", [], function (t, results) {235 if (results.rows.length) {236 try {237 data = JSON.parse(results.rows.item(0).value);238 } catch (ex) {239 data = {};240 };241 };242 Storage.isReady = true;243 });244 });245 } else if (storageMode === MODE_USERDATA) {246 storageDriver = DOC.createElement('span');247 storageDriver.addBehavior('#default#userData');248 _mix(Storage, {249 _save: function () {250 var _data = JSON.stringify(data);251 try {252 storageDriver.setAttribute(USERDATA_NAME, _data);253 storageDriver.save(USERDATA_PATH);254 } catch (ex) { };255 }256 });257 if ($.isReady) {258 _doReady();259 } else {260 $(document).ready(_doReady);261 };262 };263 } else {264 Storage.isReady = true;265 };266 var interval = WIN.setInterval(function () {267 if (Storage.isReady) {268 readys.forEach(function (fn) {269 try { fn() } catch (e) { };270 });271 WIN.clearInterval(interval);272 interval = null;273 readys = [];274 };275 }, 100);276 WIN.Storage = Storage;...

Full Screen

Full Screen

find-specs.js

Source:find-specs.js Github

copy

Full Screen

1import sinon from 'sinon';2import XCUITestDriver from '../../..';3describe('general commands', function () {4 const driver = new XCUITestDriver();5 const proxySpy = sinon.stub(driver, 'proxyCommand');6 afterEach(function () {7 proxySpy.reset();8 });9 describe('findNativeElementOrElements', function () {10 async function verifyFind (strategy, selector, modSelector, modStrategy = null, mult = false) {11 try {12 await driver.findNativeElementOrElements(strategy, selector, mult);13 } catch (ign) {}14 proxySpy.calledOnce.should.be.true;15 proxySpy.firstCall.args[0].should.eql(`/element${mult ? 's' : ''}`);16 proxySpy.firstCall.args[1].should.eql('POST');17 proxySpy.firstCall.args[2].should.eql({18 using: modStrategy || strategy,19 value: modSelector20 });21 proxySpy.reset();22 }23 it('should convert class names from UIA to XCUI', async function () {24 await verifyFind('class name', 'UIAButton', 'XCUIElementTypeButton');25 await verifyFind('class name', 'UIAMapView', 'XCUIElementTypeMap');26 await verifyFind('class name', 'UIAScrollView', 'XCUIElementTypeScrollView');27 await verifyFind('class name', 'UIACollectionView', 'XCUIElementTypeCollectionView');28 await verifyFind('class name', 'UIATextView', 'XCUIElementTypeTextView');29 await verifyFind('class name', 'UIAWebView', 'XCUIElementTypeWebView');30 });31 it('should convert xpaths from UIA to XCUI', async function () {32 await verifyFind('xpath', '//UIAButton', '//XCUIElementTypeButton');33 await verifyFind('xpath',34 '//UIAButton/UIATextField',35 '//XCUIElementTypeButton/XCUIElementTypeTextField');36 await verifyFind('xpath',37 'UIAButton//UIATextField',38 'XCUIElementTypeButton//XCUIElementTypeTextField');39 await verifyFind('xpath',40 '//UIAButton[@name="foo"]',41 '//XCUIElementTypeButton[@name="foo"]');42 await verifyFind('xpath',43 '//UIAButton/Weird',44 '//XCUIElementTypeButton/Weird');45 await verifyFind('xpath',46 '//UIAMapView/UIAScrollView',47 '//XCUIElementTypeMap/XCUIElementTypeScrollView');48 await verifyFind('xpath',49 '//UIAMapView/UIAScrollView[@name="UIADummyData"]',50 '//XCUIElementTypeMap/XCUIElementTypeScrollView[@name="UIADummyData"]');51 await verifyFind('xpath',52 '//XCUIElementTypeMap[@name="UIADummyData"]',53 '//XCUIElementTypeMap[@name="UIADummyData"]');54 });55 it('should reject request for first visible child with no context', async function () {56 await driver.findNativeElementOrElements(57 'xpath', '/*[@firstVisible="true"]', false)58 .should.eventually.be.rejectedWith(/without a context element/);59 });60 it('should reject request for multiple first visible children', async function () {61 await driver.findNativeElementOrElements(62 'xpath', '/*[@firstVisible="true"]', true)63 .should.eventually.be.rejectedWith(/Cannot get multiple/);64 });65 it('should convert magic first visible child xpath to class chain', async function () {66 const variants = [67 '/*[@firstVisible="true"]',68 "/*[@firstVisible='true']",69 "/*[@firstVisible = 'true']"70 ];71 let attribSpy = sinon.stub(driver, 'getAttribute');72 for (const variant of variants) {73 proxySpy.withArgs(74 '/element/ctx/element',75 'POST',76 {using: 'class chain', value: '*[1]'}77 ).returns({ELEMENT: 1});78 proxySpy.withArgs(79 '/element/ctx/element',80 'POST',81 {using: 'class chain', value: '*[2]'}82 ).returns({ELEMENT: 2});83 attribSpy.withArgs('visible', {ELEMENT: 1}).returns('false');84 attribSpy.withArgs('visible', {ELEMENT: 2}).returns('true');85 let el = await driver.findNativeElementOrElements('xpath',86 variant, false, {ELEMENT: 'ctx'});87 proxySpy.calledTwice.should.be.true;88 proxySpy.firstCall.args[2].should.eql({89 using: 'class chain',90 value: '*[1]',91 });92 proxySpy.secondCall.args[2].should.eql({93 using: 'class chain',94 value: '*[2]',95 });96 attribSpy.calledTwice.should.be.true;97 el.should.eql({ELEMENT: 2});98 proxySpy.reset();99 attribSpy.reset();100 }101 });102 it('should convert magic is scrollable xpath to class chain', async function () {103 const multSel = '**/*[`type == "XCUIElementTypeScrollView" OR ' +104 'type == "XCUIElementTypeTable" OR ' +105 'type == "XCUIElementTypeCollectionView" OR ' +106 'type == "XCUIElementTypeWebView"`]';107 const singleSel = `${multSel}[1]`;108 await verifyFind('xpath',109 '//*[@scrollable="true"]',110 singleSel,111 'class chain');112 await verifyFind('xpath',113 `//*[@scrollable='true']`,114 singleSel,115 'class chain');116 await verifyFind('xpath',117 `//*[@scrollable = 'true']`,118 singleSel,119 'class chain');120 await verifyFind('xpath',121 '//*[@scrollable="true"]',122 multSel,123 'class chain',124 true);125 });126 });...

Full Screen

Full Screen

webpage.selenium.test.js

Source:webpage.selenium.test.js Github

copy

Full Screen

1import Browser from '../../src/browsers/selenium'2describe('selenium/webpage', () => {3 let browser4 let webpage5 let spy6 beforeAll(() => {7 browser = new Browser()8 spy = jest.fn()9 browser.constructor.webdriver = {10 By: {11 css: (...args) => spy('By.css', ...args)12 },13 until: {14 elementIsVisible: (...args) => spy('until.elementIsVisible', ...args),15 elementLocated: (...args) => spy('until.elementLocated', ...args)16 }17 }18 const getAttribute = jest.fn()19 const findElement = jest.fn().mockReturnValue({ getAttribute })20 const findElements = jest.fn().mockReturnValue([{ getAttribute }, { getAttribute }])21 browser.driver = {22 get: (...args) => spy('get', ...args),23 wait: (...args) => spy('wait', ...args),24 getPageSource: (...args) => spy('getPageSource', ...args),25 getAttribute,26 findElement,27 findElements,28 executeScript: (...args) => spy('executeScript', ...args),29 executeAsyncScript: (...args) => spy('executeAsyncScript', ...args)30 }31 })32 afterEach(() => jest.clearAllMocks())33 test('should open page', async () => {34 const webPath = '/'35 webpage = await browser.page(webPath)36 expect(spy).toHaveBeenCalledTimes(4)37 expect(spy).toHaveBeenCalledWith('get', webPath)38 expect(spy).toHaveBeenCalledWith('until.elementLocated', undefined)39 expect(spy).toHaveBeenCalledWith('By.css', 'body')40 expect(spy).toHaveBeenCalledWith('until.elementIsVisible', undefined)41 })42 test('should implement getHtml', () => {43 webpage.getHtml()44 expect(spy).toHaveBeenCalledWith('getPageSource')45 })46 test('should implement runScript', () => {47 const fn = () => true48 webpage.runScript(fn)49 expect(spy).toHaveBeenCalledWith('executeScript', expect.stringMatching('return true;'))50 })51 test('should run sync script in runAsyncScript and fix blockless bodies', () => {52 // runAsync fixes blockless bodies & sync scripts in async53 const callback = jest.fn()54 const fn = () => true55 webpage.runAsyncScript(fn, true)56 expect(spy).toHaveBeenCalledWith('executeAsyncScript', expect.any(String), true)57 expect(spy.mock.calls[0][1]).toContain('then(callback)')58 expect(spy.mock.calls[0][1]).toMatchSnapshot();59 (function runEval() {60 expect(() => eval(spy.mock.calls[0][1])).not.toThrow() // eslint-disable-line no-eval61 })(callback)62 expect(callback).toHaveBeenCalledTimes(1)63 })64 test('should run async script in runAsyncScript', async () => {65 const callback = jest.fn()66 const fn = () => { return Promise.resolve(true) }67 webpage.runAsyncScript(fn, true)68 expect(spy).toHaveBeenCalledWith('executeAsyncScript', expect.any(String), true)69 expect(spy.mock.calls[0][1]).toContain('then(callback)')70 expect(spy.mock.calls[0][1]).toMatchSnapshot()71 await new Promise((resolve) => {72 (function runEval() {73 expect(() => eval(spy.mock.calls[0][1])).not.toThrow() // eslint-disable-line no-eval74 })(() => { callback(); resolve() })75 })76 expect(callback).toHaveBeenCalledTimes(1)77 })78 test('should implement getWebElement', async () => {79 await webpage.getWebElement()80 expect(browser.driver.findElement).toHaveBeenCalledTimes(1)81 })82 test('should implement getWebElements', async () => {83 await webpage.getWebElements()84 expect(browser.driver.findElements).toHaveBeenCalledTimes(1)85 })86 test('should implement getWebAttribute', async () => {87 await webpage.getWebAttribute()88 expect(browser.driver.findElement).toHaveBeenCalledTimes(1)89 expect(browser.driver.getAttribute).toHaveBeenCalledTimes(1)90 })91 test('should implement getWebAttributes', async () => {92 await webpage.getWebAttributes()93 expect(browser.driver.findElements).toHaveBeenCalledTimes(1)94 expect(browser.driver.getAttribute).toHaveBeenCalledTimes(2)95 })...

Full Screen

Full Screen

attribute-e2e-specs.js

Source:attribute-e2e-specs.js Github

copy

Full Screen

...16 after(async () => {17 await driver.deleteSession();18 });19 it('should be able to find resourceId attribute', async () => {20 await driver.getAttribute('resourceId', animationEl).should.eventually.become('android:id/text1');21 });22 it('should be able to find text attribute', async () => {23 await driver.getAttribute('text', animationEl).should.eventually.become('Animation');24 });25 it('should be able to find name attribute', async () => {26 await driver.getAttribute('name', animationEl).should.eventually.become('Animation');27 });28 it('should be able to find name attribute, falling back to text', async () => {29 await driver.click(animationEl);30 let textView = await driver.findElOrEls('class name', 'android.widget.TextView', true);31 let textViewEl = textView[1].ELEMENT;32 await driver.getAttribute('name', textViewEl).should.eventually.become('Bouncing Balls');33 await driver.back();34 });35 it('should be able to find content description attribute', async () => {36 await driver.getAttribute('contentDescription', animationEl).should.eventually.become("Animation");37 });38 it('should be able to find displayed attribute', async () => {39 await driver.getAttribute('displayed', animationEl).should.eventually.become('true');40 });41 it('should be able to find displayed attribute through normal func', async () => {42 await driver.elementDisplayed(animationEl).should.eventually.become(true);43 });44 it('should be able to get element location using getLocation', async () => {45 let location = await driver.getLocation(animationEl);46 location.x.should.be.at.least(0);47 location.y.should.be.at.least(0);48 });49 it('should be able to get element location using getLocationInView', async () => {50 let location = await driver.getLocationInView(animationEl);51 location.x.should.be.at.least(0);52 location.y.should.be.at.least(0);53 });...

Full Screen

Full Screen

driver.js

Source:driver.js Github

copy

Full Screen

...14const btn_toggle_driver = document.querySelector("#btn_toggle_driver")15if (btn_toggle_driver) {16 btn_toggle_driver.addEventListener('click', (e) => {17 e.preventDefault()18 const id = btn_toggle_driver.getAttribute("data")19 deleteSwalUser(id, saveData)20 .then((result) => {21 if (result.value) {22 const data = result.value23 swal.fire({24 type: "success",25 titleText: data.msg,26 showConfirmButton: false,27 timer: 100028 })29 window.location.reload()30 }31 })32 })...

Full Screen

Full Screen

getLabel.js

Source:getLabel.js Github

copy

Full Screen

1import helper from 'tipsi-appium-helper'2helper.extend('getLabel', async (id) => {3 const { driver, platform } = helper4 const attributeName = platform('ios') ? 'label' : 'text'5 const label = await driver.getAttribute(id, attributeName)6 return label.trim()...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');3driver.findElement(webdriver.By.name('btnG')).click();4driver.wait(function() {5 return driver.getTitle().then(function(title) {6 return title === 'webdriver - Google Search';7 });8}, 1000);9driver.quit();10[Appium] Welcome to Appium v1.6.0-beta3 (REV 6e1d1f7c6e4d1d8b6b0a6f7c6b4d6d8f6e3f6c2e)

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var AndroidDriver = require('appium-android-driver');3var driver = new AndroidDriver();4driver.getAttribute('testElement', 'text').then(function (text) {5 console.log(text);6});7driver.quit();8var webdriver = require('selenium-webdriver');9var AndroidDriver = require('appium-android-driver');10var driver = new AndroidDriver();11driver.getAttribute('testElement', 'text').then(function (text) {12 console.log(text);13});14driver.quit();15var webdriver = require('selenium-webdriver');16var AndroidDriver = require('appium-android-driver');17var driver = new AndroidDriver();18driver.getCssProperty('testElement', 'color').then(function (color) {19 console.log(color);20});21driver.quit();22Method Description getLocation(loc

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.id('lst-ib')).sendKeys('test');6driver.findElement(webdriver.By.id('lst-ib')).getAttribute('value').then(function(text){7 console.log(text);8});9driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.getAttribute("myText", "text").then(function(text) {2 console.log(text);3});4driver.getText("myText").then(function(text) {5 console.log(text);6});7driver.getText("myText").then(function(text) {8 console.log(text);9});10driver.getTagName("myText").then(function(tagName) {11 console.log(tagName);12});13driver.getLocation("myText").then(function(location) {14 console.log(location);15});16driver.getSize("myText").then(function(size) {17 console.log(size);18});19driver.getRect("myText").then(function(rect) {20 console.log(rect);21});22driver.isDisplayed("myText").then(function(displayed) {23 console.log(displayed);24});25driver.isEnabled("myText").then(function(enabled) {26 console.log(enabled);27});28driver.isSelected("myText").then(function(selected) {29 console.log(selected);30});

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