How to use driver.getText method in Appium Android Driver

Best JavaScript code snippet using appium-android-driver

orderLimitBuy_positive.js

Source:orderLimitBuy_positive.js Github

copy

Full Screen

1"use strict";2var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {3    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }4    return new (P || (P = Promise))(function (resolve, reject) {5        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }6        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }7        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }8        step((generator = generator.apply(thisArg, _arguments || [])).next());9    });10};11var __generator = (this && this.__generator) || function (thisArg, body) {12    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;13    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;14    function verb(n) { return function (v) { return step([n, v]); }; }15    function step(op) {16        if (f) throw new TypeError("Generator is already executing.");17        while (_) try {18            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;19            if (y = 0, t) op = [op[0] & 2, t.value];20            switch (op[0]) {21                case 0: case 1: t = op; break;22                case 4: _.label++; return { value: op[1], done: false };23                case 5: _.label++; y = op[1]; op = [0]; continue;24                case 7: op = _.ops.pop(); _.trys.pop(); continue;25                default:26                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }27                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }28                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }29                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }30                    if (t[2]) _.ops.pop();31                    _.trys.pop(); continue;32            }33            op = body.call(thisArg, _);34        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }35        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };36    }37};38exports.__esModule = true;39var selenium_webdriver_1 = require("selenium-webdriver");40Promise.resolve().then(function () { return require('chromedriver'); });41var webdriver = require('selenium-webdriver');42var chrome = require('selenium-webdriver/chrome');43var chromedriver = require('chromedriver');44var selectors = require('./datas/selectors');45var awaity = require('./datas/awaity');46// enter47var enterP = require('./enter');48(function name() {49    return __awaiter(this, void 0, void 0, function () {50        var driver, balancB, balancS, balancBStr, balancBstr, balancSStr, balancSstr, price, get, balancBAfterB_1, balancBAfterBStr_1, balancSAfterB_1, balancSAfterBStr_1, balancBAfterBstr, balancSAfterBstr, t, arrayData, i, min, max, price_1, get_1, totalB, balancBAfterB, balancBAfterBStr, balancSAfterB, balancSAfterBStr, price_decimal, get_decimal, balancBAfterB_decimal, balancBAfterBStr_decimal, balancSAfterB_decimal, balancSAfterBStr_decimal;51        return __generator(this, function (_a) {52            switch (_a.label) {53                case 0:54                    driver = new selenium_webdriver_1.Builder().forBrowser('chrome').build();55                    return [4 /*yield*/, enterP.enterThree(driver)];56                case 1:57                    _a.sent();58                    return [4 /*yield*/, awaity.market(driver)];59                case 2:60                    _a.sent();61                    return [4 /*yield*/, console.log('enter success')];62                case 3:63                    _a.sent();64                    //выбор пары65                    return [4 /*yield*/, driver.findElement(selenium_webdriver_1.By.className("SELECTOR-CHECK-PAIR-btc_usdt")).click()];66                case 4:67                    //выбор пары68                    _a.sent();69                    return [4 /*yield*/, awaity.market(driver)];70                case 5:71                    _a.sent();72                    return [4 /*yield*/, selectors.balancBuy(driver).getText()];73                case 6:74                    balancB = _a.sent();75                    return [4 /*yield*/, selectors.balancSell(driver).getText()];76                case 7:77                    balancS = _a.sent();78                    //перевод строк в числа79                    //перевод balancB80                    balancB = balancB.slice(0, -4);81                    balancBStr = balancB.replace(/[\s.]/g, '');82                    balancBStr = balancBStr.replace(/\,/g, '.');83                    balancBstr = +balancBStr;84                    //перевод balancS85                    balancS = balancS.slice(0, -4);86                    balancSStr = balancS.replace(/[\s.]/g, '');87                    balancSStr = balancSStr.replace(/\,/g, '.');88                    balancSstr = +balancSStr;89                    price = 1;90                    get = 1;91                    return [4 /*yield*/, selectors.trade_buy(driver, price, get)];92                case 8:93                    _a.sent(); //торговля94                    return [4 /*yield*/, driver.sleep(5000)];95                case 9:96                    _a.sent();97                    return [4 /*yield*/, selectors.balancBuy(driver).getText()];98                case 10:99                    balancBAfterB_1 = _a.sent();100                    balancBAfterB_1 = balancBAfterB_1.slice(0, -4);101                    balancBAfterBStr_1 = balancBAfterB_1.replace(/[\s.]/g, '');102                    balancBAfterBStr_1 = balancBAfterBStr_1.replace(/\,/g, '.');103                    balancBAfterB_1 = +balancBAfterB_1;104                    return [4 /*yield*/, selectors.balancSell(driver).getText()];105                case 11:106                    balancSAfterB_1 = _a.sent();107                    balancSAfterB_1 = balancSAfterB_1.slice(0, -4);108                    balancSAfterBStr_1 = balancSAfterB_1.replace(/[\s.]/g, '');109                    balancSAfterBStr_1 = balancSAfterBStr_1.replace(/\,/g, '.');110                    balancSAfterB_1 = +balancSAfterB_1;111                    t = 2;112                    arrayData = [];113                    i = 0;114                    _a.label = 12;115                case 12:116                    if (!(i < t)) return [3 /*break*/, 22];117                    min = 0.1;118                    max = 0.2;119                    price_1 = min - 0.05 + Math.random() * (max - min + 1);120                    get_1 = min - 0.05 + Math.random() * (max - min + 1);121                    totalB = get_1 * price_1;122                    return [4 /*yield*/, console.log(totalB, 'totalB')];123                case 13:124                    _a.sent();125                    if (!(balancBstr > totalB)) return [3 /*break*/, 19];126                    return [4 /*yield*/, console.log('trade_buy posible')];127                case 14:128                    _a.sent();129                    return [4 /*yield*/, selectors.trade_buy(driver, price_1, get_1)];130                case 15:131                    _a.sent(); //торговля132                    return [4 /*yield*/, driver.sleep(5000)];133                case 16:134                    _a.sent();135                    return [4 /*yield*/, selectors.balancBuy(driver).getText()];136                case 17:137                    balancBAfterB = _a.sent();138                    balancBAfterB = balancBAfterB.slice(0, -4);139                    balancBAfterBStr = balancBAfterB.replace(/[\s.]/g, '');140                    balancBAfterBStr = balancBAfterBStr.replace(/\,/g, '.');141                    balancBAfterBstr = +balancBAfterBStr;142                    return [4 /*yield*/, selectors.balancSell(driver).getText()];143                case 18:144                    balancSAfterB = _a.sent();145                    balancSAfterB = balancSAfterB.slice(0, -4);146                    balancSAfterBStr = balancSAfterB.replace(/[\s.]/g, '');147                    balancSAfterBStr = balancSAfterBStr.replace(/\,/g, '.');148                    balancSAfterBstr = +balancSAfterBStr;149                    return [3 /*break*/, 21];150                case 19:151                    if (!(balancBStr < totalB)) return [3 /*break*/, 21];152                    return [4 /*yield*/, console.log('totalB > balancB; trade_buy imposible')];153                case 20:154                    _a.sent();155                    _a.label = 21;156                case 21:157                    i++;158                    return [3 /*break*/, 12];159                case 22:160                    price_decimal = 0.00000001;161                    get_decimal = 0.00000001;162                    return [4 /*yield*/, selectors.trade_buy(driver, price_decimal, get_decimal)];163                case 23:164                    _a.sent(); //торговля165                    return [4 /*yield*/, driver.sleep(5000)];166                case 24:167                    _a.sent();168                    return [4 /*yield*/, selectors.balancBuy(driver).getText()];169                case 25:170                    balancBAfterB_decimal = _a.sent();171                    balancBAfterB_decimal = balancBAfterB_decimal.slice(0, -4);172                    balancBAfterBStr_decimal = balancBAfterB_decimal.replace(/[\s.]/g, '');173                    balancBAfterBStr_decimal = balancBAfterBStr_decimal.replace(/\,/g, '.');174                    balancBAfterB_decimal = +balancBAfterB_decimal;175                    return [4 /*yield*/, selectors.balancSell(driver).getText()];176                case 26:177                    balancSAfterB_decimal = _a.sent();178                    balancSAfterB_decimal = balancSAfterB_decimal.slice(0, -4);179                    balancSAfterBStr_decimal = balancSAfterB_decimal.replace(/[\s.]/g, '');180                    balancSAfterBStr_decimal = balancSAfterBStr_decimal.replace(/\,/g, '.');181                    balancSAfterB_decimal = +balancSAfterB_decimal;182                    // логи183                    console.log();184                    return [2 /*return*/];185            }186        });187    });...

Full Screen

Full Screen

02_test_value_selection.android.js

Source:02_test_value_selection.android.js Github

copy

Full Screen

...56    //android.widget.FrameLayout[1]/android.widget.ListView[1]/57    android.widget.LinearLayout[4]/android.widget.TextView[1]58  `)59  try {60    const selectedItem11 = await driver.getText(dropdownValueIdFirst)61    const selectedItem21 = await driver.getText(dropdownValueIdSecond)62    t.equal('One', selectedItem11, 'User should see selected item "One" in first dropdown')63    t.equal('One', selectedItem21, 'User should see selected item "One" in second dropdown')64    await driver.click(dropdownIdFirst)65    await driver.waitForVisible(item12, 2000)66    await driver.click(item12)67    await driver.waitForVisible(dropdownValueIdFirst, 2000)68    const selectedItem12 = await driver.getText(dropdownValueIdFirst)69    const selectedItem22 = await driver.getText(dropdownValueIdSecond)70    t.equal('Two', selectedItem12, 'User should see selected item "Two" in first dropdown')71    t.equal('One', selectedItem22, 'User should see selected item "One" in second dropdown')72    await driver.waitForVisible(dropdownIdFirst).click(dropdownIdFirst)73    await driver.waitForVisible(item13, 2000)74    await driver.click(item13)75    await driver.waitForVisible(dropdownValueIdFirst, 2000)76    const selectedItem13 = await driver.getText(dropdownValueIdFirst)77    const selectedItem23 = await driver.getText(dropdownValueIdSecond)78    t.equal('Three', selectedItem13, 'User should see selected item "Three" in first dropdown')79    t.equal('One', selectedItem23, 'User should see selected item "One" in second dropdown')80    await driver.waitForVisible(dropdownIdFirst).click(dropdownIdFirst)81    await driver.waitForVisible(item14, 2000)82    await driver.click(item14)83    await driver.waitForVisible(dropdownValueIdFirst, 2000)84    const selectedItem14 = await driver.getText(dropdownValueIdFirst)85    const selectedItem24 = await driver.getText(dropdownValueIdSecond)86    t.equal('Four', selectedItem14, 'User should see selected item "Four" in first dropdown')87    t.equal('One', selectedItem24, 'User should see selected item "One" in second dropdown')88    await driver.waitForVisible(dropdownIdFirst).click(dropdownIdFirst)89    await driver.waitForVisible(item11, 2000)90    await driver.click(item11)91    await driver.waitForVisible(dropdownValueIdFirst, 2000)92    const selectedItem15 = await driver.getText(dropdownValueIdFirst)93    const selectedItem25 = await driver.getText(dropdownValueIdSecond)94    t.equal('One', selectedItem15, 'User should see selected item "One" in first dropdown')95    t.equal('One', selectedItem25, 'User should see selected item "One" in second dropdown')96    await driver.waitForVisible(dropdownIdSecond).click(dropdownIdSecond)97    await driver.waitForVisible(item22, 2000)98    await driver.click(item22)99    await driver.waitForVisible(dropdownValueIdSecond, 2000)100    const selectedItem16 = await driver.getText(dropdownValueIdFirst)101    const selectedItem26 = await driver.getText(dropdownValueIdSecond)102    t.equal('One', selectedItem16, 'User should see selected item "One" in first dropdown')103    t.equal('Two', selectedItem26, 'User should see selected item "Two" in second dropdown')104    await driver.waitForVisible(dropdownIdSecond).click(dropdownIdSecond)105    await driver.waitForVisible(item23, 2000)106    await driver.click(item23)107    await driver.waitForVisible(dropdownValueIdSecond, 2000)108    const selectedItem17 = await driver.getText(dropdownValueIdFirst)109    const selectedItem27 = await driver.getText(dropdownValueIdSecond)110    t.equal('One', selectedItem17, 'User should see selected item "One" in first dropdown')111    t.equal('Three', selectedItem27, 'User should see selected item "Three" in second dropdown')112    await driver.waitForVisible(dropdownIdSecond).click(dropdownIdSecond)113    await driver.waitForVisible(item24, 2000)114    await driver.click(item24)115    await driver.waitForVisible(dropdownValueIdSecond, 2000)116    const selectedItem18 = await driver.getText(dropdownValueIdFirst)117    const selectedItem28 = await driver.getText(dropdownValueIdSecond)118    t.equal('One', selectedItem18, 'User should see selected item "One" in first dropdown')119    t.equal('Four', selectedItem28, 'User should see selected item "Four" in second dropdown')120  } catch (error) {121    await helper.screenshot()122    await helper.source()123    throw error124  }...

Full Screen

Full Screen

frames-specs.js

Source:frames-specs.js Github

copy

Full Screen

...25    it('should switch to frame by name', async function () {26      await driver.setFrame('first');27      (await driver.title()).should.be.equal(FRAMESET_TITLE);28      let h1 = await driver.findElement('tag name', 'h1');29      (await driver.getText(h1)).should.be.equal(SUB_FRAME_1_TITLE);30    });31    it('should switch to frame by index', async function () {32      await driver.setFrame(1);33      (await driver.title()).should.be.equal(FRAMESET_TITLE);34      let h1 = await driver.findElement('tag name', 'h1');35      (await driver.getText(h1)).should.be.equal(SUB_FRAME_2_TITLE);36    });37    it('should switch to frame by id', async function () {38      await driver.setFrame('frame3');39      (await driver.title()).should.be.equal(FRAMESET_TITLE);40      let h1 = await driver.findElement('tag name', 'h1');41      (await driver.getText(h1)).should.be.equal(SUB_FRAME_3_TITLE);42    });43    it('should switch back to default content from frame', async function () {44      await driver.setFrame('first');45      (await driver.title()).should.be.equal(FRAMESET_TITLE);46      let h1 = await driver.findElement('tag name', 'h1');47      (await driver.getText(h1)).should.be.equal(SUB_FRAME_1_TITLE);48      await driver.setFrame(null);49      (await driver.findElement('tag name', 'frameset')).should.exist;50    });51    it('should switch to child frames', async function () {52      await driver.setFrame('third');53      (await driver.title()).should.be.equal(FRAMESET_TITLE);54      await driver.setFrame('childframe');55      (await driver.findElement('id', 'only_on_page_2')).should.exist;56    });57    it('should execute javascript in frame', async function () {58      await driver.setFrame('first');59      (await driver.execute(GET_ELEM_SYNC)).should.be.equal(SUB_FRAME_1_TITLE);60    });61    it('should execute async javascript in frame', async function () {62      await driver.setFrame('first');63      (await driver.executeAsync(GET_ELEM_ASYNC)).should.be.equal(SUB_FRAME_1_TITLE);64    });65    it('should get source within a frame', async function () {66      let pageSource = await driver.getPageSource();67      pageSource.should.include(FRAMESET_TITLE);68      await driver.setFrame('first');69      let frameSource = await driver.getPageSource();70      frameSource.should.include(SUB_FRAME_1_TITLE);71      frameSource.should.not.include(FRAMESET_TITLE);72    });73  });74  describe('iframes', function () {75    beforeEach(async function () {76      return await loadWebView(77        desired,78        driver,79        `${env.TEST_END_POINT}iframes.html`,80        'Iframe guinea pig'81      );82    });83    it('should switch to iframe by name', async function () {84      await driver.setFrame('iframe1');85      (await driver.title()).should.be.equal(IFRAME_FRAMESET_TITLE);86      let h1 = await driver.findElement('tag name', 'h1');87      (await driver.getText(h1)).should.be.equal(SUB_FRAME_1_TITLE);88    });89    it('should switch to iframe by index', async function () {90      await driver.setFrame(1);91      (await driver.title()).should.be.equal(IFRAME_FRAMESET_TITLE);92      let h1 = await driver.findElement('tag name', 'h1');93      (await driver.getText(h1)).should.be.equal(SUB_FRAME_2_TITLE);94    });95    it('should switch to iframe by id', async function () {96      await driver.setFrame('id-iframe3');97      (await driver.title()).should.be.equal(IFRAME_FRAMESET_TITLE);98      let h1 = await driver.findElement('tag name', 'h1');99      (await driver.getText(h1)).should.be.equal(SUB_FRAME_3_TITLE);100    });101    it('should switch to iframe by element', async function () {102      let frame = await driver.findElement('id', 'id-iframe3');103      await driver.setFrame(frame);104      (await driver.title()).should.be.equal(IFRAME_FRAMESET_TITLE);105      let h1 = await driver.findElement('tag name', 'h1');106      (await driver.getText(h1)).should.be.equal(SUB_FRAME_3_TITLE);107    });108    it('should not switch to iframe by element of wrong type', async function () {109      let h1 = await driver.findElement('tag name', 'h1');110      await driver.setFrame(h1).should.eventually.be.rejected;111    });112    it('should switch back to default content from iframe', async function () {113      await driver.setFrame('iframe1');114      (await driver.title()).should.be.equal(IFRAME_FRAMESET_TITLE);115      let h1 = await driver.findElement('tag name', 'h1');116      (await driver.getText(h1)).should.be.equal(SUB_FRAME_1_TITLE);117      await driver.setFrame(null);118      (await driver.findElements('tag name', 'iframe')).should.have.length(3);119    });120    it('should get source within an iframe', async function () {121      let pageSource = await driver.getPageSource();122      pageSource.should.include(IFRAME_FRAMESET_TITLE);123      await driver.setFrame('iframe1');124      let frameSource = await driver.getPageSource();125      frameSource.should.include(SUB_FRAME_1_TITLE);126      frameSource.should.not.include(IFRAME_FRAMESET_TITLE);127    });128  });...

Full Screen

Full Screen

definitions.js

Source:definitions.js Github

copy

Full Screen

...293031Then("Test DONE -> Written {string} on the page", async function (arg1) {32    await driver.pause(maxRandomValue);33    // await driver.wait(until.driver.getText(`android=new UiSelector().textMatches("${arg1}")`), very_long_time);34    const texto_esperado = await driver.getText(`android=new UiSelector().textMatches("${arg1}")`);35    36    console.log(texto_esperado)3738  39});4041//***Encontra o botão pelo que está escrito nele***42When("I click on the button with the text {string}", async function (arg1) {43    await driver.pause(short_time);44    await driver.click(`android=new UiSelector().textMatches("${arg1}")`);45});4647Given("The field written {string} is filled with {string}", async function (arg1, arg2) {48    await driver.pause(long_time);49    await driver.setValue(`android=new UiSelector().textStartsWith("${arg1}")`, arg2);50});515253When("I click on the page", async function () {54    await driver.pause(long_time);55    await driver.touchPerform([{56        action: 'tap',57        options: {58            x: 100,59            y: 25060        }61    }]);62});636465Given("The field with the text {string} is filled with {string}", async function (arg1, arg2) {66    await driver.pause(long_time);67    await driver.setValue(`android=new UiSelector().textMatches("${arg1}")`, arg2);68}); 6970When("I move the page", async function () {71    await driver.pause(long_time);72    73    // Javascript74    // webdriver.io example75    await driver.touchPerform([76        { action: 'press', options: { x: 100, y: 250 } },77        { action: 'moveTo', options: { x: 400, y: 100 } },78        { action: 'release' }79    ]);80});8182Then("The data {string} will appear on top of the marker with classname {string} and index = {string}", async function (arg1, arg2, arg3) {83    await driver.pause(long_time);84    const texto_esperado = await driver.getText(`android=new UiSelector().className("${arg2}").enabled(true).instance(${arg3})`);85    const nova_Tela = await driver.getText().then((text) => {86        console.log(text, "segundo console ")87        resultado = text.substring(0, 6)88        assert.equal(resultado, arg1)8990    })91});9293Given("I wait {string} seconds", async function (arg1) {94    await driver.pause(arg1);95}); 96979899//PARA CLICAR - await driver.click('android=new UiSelector().textStartsWith("Digit")');100//<Text style={} accessibilityLavel="texto_Titulo_Selecione" resource-id="texto_Titulo_Selecione" >101//Selecione a estação102//</Text>103104// android:id/button2105// bounds	[450,1045][656,1189]106107// Identificador no botão entrar108//***Encontra botão pelo classname e pelo index***109Given("I click on the button with classname {string} and index = {string}", async function (arg1, arg2) {110    await driver.pause(short_time);111    await driver.click(`android=new UiSelector().className("${arg1}").enabled(true).instance(${arg2})`);112});113114Given("I click on the button with description{string} ,classname {string} and index = {string}", async function (arg1, arg2, arg3) {115    await driver.pause(short_time);116    await driver.click(`android=new UiSelector().description("${arg1}")className("${arg2}").enabled(true).instance(${arg3})`);117118});119Given("I click on the item with classname {string} and index = {string}, which has coordinates x = {string} and y = {string}", async function (arg1, arg2, arg3, arg4) {120    await driver.pause(short_time);121    // webdriver.io example122    //O ponto (0, 0) refere-se ao canto superior esquerdo da página. As coordenadas do elemento são retornadas como um objeto JSON com propriedades x e y123    let location = await driver.getLocation(`android=new UiSelector().className("${arg1}").enabled(true).instance(${arg2})`);124    console.log(location);125    await driver.pause(short_time);126    await driver.touchPerform([{127        action: 'tap',128        options: {129            x: arg3,130            y: arg4131        }132    }]);133});134135Then("Test finished: The {string} icon is on the screen", async function (arg1) {136137    await driver.pause(maxRandomValue);138    // await driver.wait(until.driver.getText(`android=new UiSelector().textMatches("${arg1}")`), very_long_time);139    const texto_esperado = await driver.getText(`android=new UiSelector().textMatches("${arg1}")`);140141    console.log(texto_esperado)142    143    assert.equal(resultado, arg1)144145});146147Given("The field with classname {string} and index {string} is filled with {string}", async function (arg1, arg2, arg3) {148149    await driver.pause(long_time);150    await driver.setValue(`android=new UiSelector().className("${arg1}").enabled(true).instance(${arg2})`, arg3);151
...

Full Screen

Full Screen

selectors.js

Source:selectors.js Github

copy

Full Screen

...16   	.pause(5000)17   	//Verify loaded page title contains “Get Schedules &amp; Times Near You”18   	//.expect.element('title').text.to.contain('Get Schedules & Times Near You | Weight Watchers')19/*20driver.getText("//title",function(result)21		{	 t = JSON.stringify(result);22			console.log('t: '+ t)23			//console.log('First result and the distance: '+ result.value)24		}25		)26		*/27	//In the search field, search for meetings for zip code: 1001128	driver29	.click("//input[@id='meetingSearch']")30	.setValue("//input[@id='meetingSearch']","10011")31	.keys(driver.Keys.ENTER)32	.pause(4000)33	// Print the title of the first result and the distance (located on the right of location title/name)34 	driver.getText("(//div[@class='location__top'])[1]",function(result)35		{	 res = result.value;36			console.log('First result and the distance: '+ res)37			//console.log('First result and the distance: '+ result.value)38		}39		)40	// Click on the first search result and then, verify displayed location name matches with the name of the first searched result that was clicked.41	.click("(//div[@class='location__top'])[1]")42	driver.getText("//div[@class='location__name']",function(result)43		{	res1 = result.value;44			//console.log('On clicking: '+ res1)45			//console.log('On clicking: '+ result.value)46			var i= res.includes(res1)47			//console.log("i = "+i)48			if(i==true)49				{50					console.log("Displayed location name matches with the name of the first searched result")51				}52			else53			{54				console.log("Displayed location name does not match with the name of the first searched result")55			}56		}57		58		)   59	60}61var getTodaysHours = function(driver)62{63	// From this location page, print TODAY’s hours of operation (located towards the bottom of the page)64	driver65	.execute('scrollTo(600,600)')66	.pause(1000)67	.useXpath()68	//get todays date69	var d= new Date();70	//get today's day value71	var n=d.getDay();72	//console.log(n);73	//if value is 1, the day is Saturday74	if(n==1)75	{76		driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[24]",function(result)77		{	78			console.log('Saturday '+ result.value);79		}80		)81	}82	//if value is 2, the day is Sunday83	else if(n==2)84{85driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[25]",function(result)86		{	87			console.log('Sunday '+ result.value);88		}89		)90}//if value is 3, the day is Monday91	else if(n==3)92{93driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[26]",function(result)94		{	95			console.log('Monday '+ result.value);96		}97		)98	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[27]",function(result)99		{	100			console.log('       '+ result.value);101		}102		)103	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[28]",function(result)104		{	105			console.log('       '+ result.value);106		}107		)108}109//if value is 4, the day is Tuesday110	else if(n==4){111	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[29]",function(result)112		{	113			console.log('Tuesday '+ result.value);114		}115		)116	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[30]",function(result)117		{	118			console.log('        '+ result.value);119		}120		)121}122//if value is 5, the day is Wednesday123else if(n==5)124{125driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[31]",function(result)126		{	127			console.log('Wednesday '+ result.value);128		}129		)130	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[32]",function(result)131		{	132			console.log('          '+ result.value);133		}134		)135}136//if value is 6, the day is Thursday137else if(n==6)138{139	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[33]",function(result)140		{	141			console.log('Thursday '+ result.value);142		}143		)144	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[34]",function(result)145		{	146			console.log('        '+ result.value);147		}148		)149	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[35]",function(result)150		{	151			console.log('        '+ result.value);152		}153		)154}155//if value is 7, the day is Friday156else if(n==7)157{158	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[36]",function(result)159		{	160			console.log('Friday '+ result.value);161		}162		)163	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[37]",function(result)164		{	165			console.log('       '+ result.value);166		}167		)168	driver.getText("(//div[@ng-repeat='meeting in day.meetings'])[38]",function(result)169		{	170			console.log('      '+ result.value);171		}172		)173}174}175module.exports={176	usingSelectorsDemo: usingSelectorsDemo,177	getTodaysHours: getTodaysHours...

Full Screen

Full Screen

keyboard-specs.js

Source:keyboard-specs.js Github

copy

Full Screen

...22        }23        let el = await driver.findElement('class name', 'UIATextField');24        await driver.clear(el);25        await driver.setValue(text, el);26        let text2 = await driver.getText(el);27        if (strategy === 'grouped') {28          text2.length.should.be.above(0);29        } else {30          text2.should.equal(text);31        }32      });33    });34  };35  _.each([undefined, 'oneByOne', 'grouped', 'setValue'], test);36  describe('typing', function () {37    let session = setup(this, desired);38    let driver = session.driver;39    describe('stability @skip-ci', function () {40      let runs = 10;41      let text = 'Delhi is New @@@ BREAKFAST-FOOD-0001';42      let test = function () {43        it('should send keys to a text field', async function () {44          let el = await driver.findElement('class name', 'UIATextField');45          await driver.clear(el);46          driver.setValue(text, el);47          (await driver.getText(el)).should.equal(text);48        });49      };50      for (let n = 0; n < runs; n++) {51        describe(`sendKeys test ${n + 1}`, test);52      }53    });54    it('should send accented text', async function () {55      let testText = unorm.nfd('é Œ ù ḍ');56      let els = await driver.findElements('class name', 'UIATextField');57      let el = els[1];58      await driver.clear(el);59      await driver.setValue(testText, el);60      (await driver.getText(el)).should.equal(testText);61    });62    it('should send backspace key', async function () {63      let els = await driver.findElements('class name', 'UIATextField');64      let el = els[1];65      await driver.clear(el);66      await driver.setValue('abcd', el);67      (await driver.getText(el)).should.equal('abcd');68      await driver.setValue('\uE003\uE003', el);69      (await driver.getText(el)).should.equal('ab');70    });71    it('should send delete key', async function () {72      let els = await driver.findElements('class name', 'UIATextField');73      let el = els[1];74      await driver.clear(el);75      await driver.setValue('abcd', el);76      await driver.setValue('\ue017\ue017', el);77      (await driver.getText(el)).should.equal('ab');78    });79    it('should send single quote text with setValue', async function () {80      let testText = "'";81      let els = await driver.findElements('class name', 'UIATextField');82      let el = els[1];83      await driver.clear(el);84      await driver.setValue(testText, el);85      (await driver.getText(el)).should.equal(testText);86    });87    it('should send single quote text with keys', async function () {88      let testText = "'";89      let els = await driver.findElements('class name', 'UIATextField');90      let el = els[1];91      await driver.clear(el);92      await driver.keys(testText);93      (await driver.getText(el)).should.equal(testText);94    });95    it('should send text with a newline', async function () {96      let testText = ['my string\n'];97      let els = await driver.findElements('class name', 'UIATextField');98      let el = els[1];99      await driver.clear(el);100      await driver.keys(testText);101      (await driver.getText(el)).should.equal('my string');102    });103  });...

Full Screen

Full Screen

by-xpath-e2e-specs.js

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

copy

Full Screen

...22    await driver.findElement('xpath', '/*').should.eventually.be.rejectedWith(/could not be located/);23  });24  it('should find element by type', async function () {25    let el = await driver.findElement('xpath', `//${atv}`);26    await driver.getText(el.ELEMENT).should.eventually.equal('API Demos');27  });28  it('should find element by text', async function () {29    let el = await driver.findElement('xpath', `//${atv}[@text='Accessibility']`);30    await driver.getText(el.ELEMENT).should.eventually.equal('Accessibility');31  });32  it('should find exactly one element via elementsByXPath', async function () {33    let el = await driver.findElements('xpath', `//${atv}[@text='Accessibility']`);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 function () {38    let el = await driver.findElement('xpath', `//${atv}[contains(@text, 'Accessibility')]`);39    await driver.getText(el.ELEMENT).should.eventually.equal('Accessibility');40  });41  it('should find the last element', async function () {42    let el = await driver.findElement('xpath', `(//${atv})[last()]`);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.findElement('xpath', `//${f}[2]/${alv}[1]/${atv}[4]`);50  //   await driver.getText(el.ELEMENT).should.eventually.equal('App');51  // });52  it('should find element by index and embedded desc', async function () {53    let el = await driver.findElement('xpath', `//${f}//${atv}[5]`);54    await driver.getText(el.ELEMENT).should.eventually.equal('Content');55  });56  it('should find all elements', async function () {57    let els = await driver.findElements('xpath', `//*`);58    els.length.should.be.above(2);59  });60  it('should find the first element when searching for all elements', async function () {61    let el = await driver.findElements('xpath', `//*`);62    el[0].should.exist;63  });64  it('should find less elements with compression turned on', async function () {65    await driver.updateSettings({ignoreUnimportantViews: false});66    let elementsWithoutCompression = await driver.findElements('xpath', `//*`);67    await driver.updateSettings({ignoreUnimportantViews: true});68    let elementsWithCompression = await driver.findElements('xpath', `//*`);...

Full Screen

Full Screen

05_test_card_text_field.js

Source:05_test_card_text_field.js Github

copy

Full Screen

...31    numberPlaceholder="XXXX XXXX XXXX XXXX"32    expirationPlaceholder="MM/YY"33    cvcPlaceholder="123"34  */35  const placeholder = await driver.getText(placeholderId)36  t.equal(placeholder, 'XXXX XXXX XXXX XXXX', 'Custom placeholder as expected')37  await driver.click(cardTextFieldId)38  t.pass('User should be able focus on `PaymentCardTextField` component')39  // Set card credentials40  await driver.keys('42424242424242421234123')41  // Wait for expiration date and cvc42  await driver.waitForVisible(inputExpData, 50000).waitForText(inputExpData)43  await driver.waitForVisible(inputCVC, 50000).waitForText(inputCVC)44  t.pass('User should be able write card data on `PaymentCardTextField` component')45  t.equal(46    await driver.getText(cardPramIds.number),47    'Number: 4242424242424242',48    'Number should be 4242424242424242'49  )50  t.equal(await driver.getText(cardPramIds.expMonth), 'Month: 12', 'Month should be 12')51  t.equal(await driver.getText(cardPramIds.expYear), 'Year: 34', 'Year should be 34')52  t.equal(await driver.getText(cardPramIds.cvc), 'CVC: 123', 'CVC should be 123')53  t.equal(await driver.getText(cardPramIds.valid), 'Valid: true', 'Field should be valid')...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'Chrome' } };3    .remote(options)4    .init()5    .getTitle().then(function(title) {6        console.log('Title was: ' + title);7    })8    .end();9var webdriver = require('webdriverio');10var options = { desiredCapabilities: { browserName: 'Chrome' } };11    .remote(options)12    .init()13    .getTitle().then(function(title) {14        console.log('Title was: ' + title);15    })16    .end();17var webdriver = require('webdriverio');18var options = { desiredCapabilities: { browserName: 'Chrome' } };19    .remote(options)20    .init()21    .getTitle().then(function(title) {22        console.log('Title was: ' + title);23    })24    .end();25var webdriver = require('webdriverio');26var options = { desiredCapabilities: { browserName: 'Chrome' } };27    .remote(options)28    .init()29    .getTitle().then(function(title) {30        console.log('Title was: ' + title);31    })32    .end();33var webdriver = require('webdriverio');34var options = { desiredCapabilities: { browserName: 'Chrome' } };35    .remote(options)36    .init()37    .getTitle().then(function(title) {38        console.log('Title was: ' + title);39    })40    .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new webdriver.Builder()2    .withCapabilities({'app': 'path/to/myapp.apk', 'deviceName': 'deviceName', 'platformName': 'Android', 'platformVersion': '4.4'})3    .build();4driver.findElement(webdriver.By.id('myElement')).getText().then(function(text) {5    console.log(text);6});7driver.quit();8driver.findElement(webdriver.By.id('myElement')).getText().then(function(text) {9    console.log(text);10});11driver.findElement(webdriver.By.id('myElement')).getAttribute('text').then(function(text) {12    console.log(text);13});

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new AndroidDriver();2driver.getText("id", "someId", function(err, text) {3  console.log(text);4});5var driver = new iOSDriver();6driver.getText("id", "someId", function(err, text) {7  console.log(text);8});9var driver = new WindowsDriver();10driver.getText("id", "someId", function(err, text) {11  console.log(text);12});13var driver = new SelendroidDriver();14driver.getText("id", "someId", function(err, text) {15  console.log(text);16});17var driver = new FirefoxOSDriver();18driver.getText("id", "someId", function(err, text) {19  console.log(text);20});21var driver = new ChromeDriver();22driver.getText("id", "someId", function(err, text) {23  console.log(text);24});25var driver = new SafariDriver();26driver.getText("id", "someId", function(err, text) {27  console.log(text);28});29var driver = new UIAutomator2Driver();30driver.getText("id", "someId", function(err, text) {31  console.log(text);32});33var driver = new YouiEngineDriver();34driver.getText("id", "someId", function(err, text) {35  console.log(text);36});37var driver = new MacDriver();38driver.getText("id", "someId", function(err, text) {39  console.log(text);40});41var driver = new TizenDriver();42driver.getText("id", "someId", function(err, text) {43  console.log(text);44});45var driver = new XCUITestDriver();46driver.getText("id", "someId", function(err, text) {

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.getText("id", "com.example.android.myapp:id/my_textview", function(err, text) {2    console.log(text);3});4driver.getText("id", "my_textview", function(err, text) {5    console.log(text);6});7driver.getText("id", "my_textview", function(err, text) {8    console.log(text);9});10driver.getText("id", "my_textview", function(err, text) {11    console.log(text);12});13driver.getText("css selector", "my_textview", function(err, text) {14    console.log(text);15});16driver.getText("id", "my_textview", function(err, text) {17    console.log(text);18});19driver.getText("id", "my_textview", function(err, text) {20    console.log(text);21});22driver.getText("id", "my_textview", function(err, text) {23    console.log(text);24});25driver.getText("id", "my_textview", function(err, text) {26    console.log(text);27});28driver.getText("id", "my_textview", function(err, text) {29    console.log(text);30});31driver.getText("id", "my_textview", function(err, text) {32    console.log(text);33});34driver.getText("id", "my_textview", function(err, text) {35    console.log(text);36});

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('webdriverio');2var options = {3    desiredCapabilities: {4    }5};6var client = webdriver.remote(options);7    .init()8    .elementByName('Edit Text').then(function (el) {9        return client.elementIdText(el.value.ELEMENT);10    }).then(function (text) {11        console.log(text);12    })13    .end();14var webdriver = require('webdriverio');15var options = {16    desiredCapabilities: {17    }18};19var client = webdriver.remote(options);20    .init()21    .elementByName('Edit Text').then(function (el) {22        return client.elementIdText(el.value.ELEMENT);23    }).then(function (text) {24        console.log(text);25    })26    .end();

Full Screen

Using AI Code Generation

copy

Full Screen

1  console.log("Text: " + text);2});3  console.log("Text: " + text);4});5  console.log("Text: " + text);6});

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.getText("id=android:id/title", function(err, text) {2  console.log(text);3});4driver.getText("id=android:id/title", function(err, text) {5  console.log(text);6});7driver.getText("id=android:id/title", function(err, text) {8  console.log(text);9});10driver.getText("id=android:id/title", function(err, text) {11  console.log(text);12});13driver.getText("id=android:id/title", function(err, text) {14  console.log(text);15});16driver.getText("id=android:id/title", function(err, text) {17  console.log(text);18});19driver.getText("id=android:id/title", function(err, text) {20  console.log(text);21});22driver.getText("id=android:id/title", function(err, text) {23  console.log(text);24});25driver.getText("id=android:id/title", function(err, text) {26  console.log(text);27});28driver.getText("id=android:id/title", function(err, text) {29  console.log(text);30});31driver.getText("id=android:id/title", function(err, text) {32  console.log(text);33});34driver.getText("id=android:id/title", function(err, text) {35  console.log(text);36});37driver.getText("id=android:id/title", function(err, text) {38  console.log(text);39});40driver.getText("id

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