Best JavaScript code snippet using appium-android-driver
tracking-functionality.spec.js
Source:tracking-functionality.spec.js
1import { CountryDetailScreenDriver } from './utils/country-detail-screen-driver'2import { initialState, reducer } from '../redux/reducer'3import { applyMiddleware, createStore } from 'redux'4import thunk from 'redux-thunk'5import { HomeScreenDriver } from './utils/home-screen-driver'6import { ASYNC_STORAGE_TRACKED_KEY } from '../strings'7import AsyncStorage from '@react-native-community/async-storage'8import covidApi from '../api/covid-api'9import { ACTIONS, setCountryTracked } from '../redux/actions'10const testCountry = {11 Country: 'Lithuania',12 CountryCode: 'LT',13 Slug: 'lithuania',14 NewConfirmed: 15,15 TotalConfirmed: 1562,16 NewDeaths: 1,17 TotalDeaths: 60,18 NewRecovered: 28,19 TotalRecovered: 1025,20 Date: '2020-05-20T09:10:49Z'21}22covidApi.getSummary = jest.fn().mockResolvedValue({ globalData: {}, countries: [testCountry] })23describe('Country tracking functionality', () => {24 let driver25 let store26 let storeDispatchSpy27 beforeEach(async () => {28 store = createStore(reducer, initialState, applyMiddleware(...[thunk]))29 storeDispatchSpy = jest.spyOn(store, 'dispatch')30 driver = new CountryDetailScreenDriver(store, { country: testCountry })31 await driver.renderAsync()32 await AsyncStorage.clear()33 })34 describe('Tests without persistence', () => {35 it('should toggle switch state on press', () => {36 expect(driver.getSwitchValue()).toBeFalsy()37 driver.tapSwitch()38 expect(driver.getSwitchValue()).toBeTruthy()39 })40 it('should change global tracking state on action dispatch', () => {41 driver.dispatchCountryTrackedState(testCountry.Slug, true)42 expect(driver.countryIsTracked(testCountry.Slug)).toBeTruthy()43 })44 it('should alter the global list of tracked countries on switch toggle', () => {45 expect(driver.countryIsTracked(testCountry.Slug)).toBeFalsy()46 driver.tapSwitch() // enable47 expect(driver.countryIsTracked(testCountry.Slug)).toBeTruthy()48 driver.tapSwitch() // disable49 expect(driver.countryIsTracked(testCountry.Slug)).toBeFalsy()50 })51 describe('integration with home screen', () => {52 let homeDriver53 beforeEach(async () => {54 homeDriver = new HomeScreenDriver(store)55 await homeDriver.renderAsync()56 })57 it('should display a flat list for tracked countries', () => {58 expect(homeDriver.containsTrackedCountryList()).toBeTruthy()59 })60 it('should display the country in a list when action dispatched', () => {61 expect(driver.countryIsTracked(testCountry.Slug)).toBeFalsy()62 driver.dispatchCountryTrackedState(testCountry.Slug, true)63 expect(homeDriver.containsCountry(testCountry.Slug)).toBeTruthy()64 })65 it('should show a tracked country on the home screen on switch toggle', async () => {66 expect(driver.countryIsTracked(testCountry.Slug)).toBeFalsy()67 driver.tapSwitch() // enable68 expect(homeDriver.containsCountry(testCountry.Slug)).toBeTruthy()69 })70 })71 })72 describe('Testing persistence', () => {73 it('should save data to async storage on state.tracked change', () => {74 const jsonSpy = jest.spyOn(JSON, 'stringify')75 const expectedSave = [testCountry.Slug]76 const expectedJson = JSON.stringify(expectedSave)77 expect(driver.countryIsTracked(testCountry.Slug)).toBeFalsy()78 driver.dispatchCountryTrackedState(testCountry.Slug, true)79 expect(jsonSpy).toHaveBeenCalledWith(expectedSave)80 expect(AsyncStorage.setItem).toBeCalledWith(ASYNC_STORAGE_TRACKED_KEY, expectedJson)81 })82 it('should restore data from async storage on re-render', async () => {83 expect(driver.countryIsTracked(testCountry.Slug)).toBeFalsy()84 driver.tapSwitch()85 expect(driver.countryIsTracked(testCountry.Slug)).toBeTruthy()86 // Clear existing store87 store = createStore(reducer, initialState, applyMiddleware(...[thunk]))88 // Async storage gets fetched and set in state on home screen render89 await new HomeScreenDriver(store).renderAsync()90 expect(AsyncStorage.getItem).toHaveBeenCalledWith(ASYNC_STORAGE_TRACKED_KEY)91 await expect(driver.countryIsTracked(testCountry.Slug)).toBeTruthy()92 })93 })...
Main.js
Source:Main.js
1Ext.define('HatioBB.controller.Main', {2 extend: 'Ext.app.Controller',3 requires : ['HatioBB.view.Setting', 'HatioBB.view.driver.Driver', 'HatioBB.view.vehicle.Vehicle'],4 5 config: {6 routes : {7 map : 'onMap',8 info : 'onInfo',9 incident : 'onIncident'10 },11 12 refs: {13 main: 'main',14 nav: 'nav',15 content: 'content',16 header : 'header'17 },18 control: {19 '#ext-viewport':{20 orientationchange: 'onOC'21 },22 '#content' : {23 painted : 'onHome'24 },25 'header #map' : {26 tap: 'onMap'27 },28 'header #info' : {29 tap: 'onInfo'30 },31 'header #incident' : {32 tap: 'onIncident'33 },34 'header #collapse' : {35 tap : 'onCollapse'36 },37 'header #setting' : {38 tap : 'onSetting'39 },40 'header #refresh' : {41 tap : 'onRefresh'42 },43 44 'monitor_map' : {45 drivertap : 'onMapDriverTap',46 vehicletap : 'onMapVehicleTap',47 tracktap : 'onMapTrackTap'48 },49 'monitor_info #incidents button' : {50 tap : 'onIncident'51 },52 'monitor_info image' : {53 tap : 'onImage'54 },55 'monitor_incident image' : {56 tap : 'onImage'57 },58 59 'vehicle_summary' : {60 showMap : 'onShowMap',61 showTrack : 'onShowTrack'62 },63 'driver_summary' : {64 showMap : 'onShowMap',65 showTrack : 'onShowTrack'66 }67 }68 },69 onOC : function(me, newOrient,w,h) {70 if(newOrient === 'portrait') {71 this.getNav().setDocked(null).hide();72 } else {73 this.getNav().setDocked(HatioBB.setting.get('dockPosition')).show();74 }75 },76 77 onHome : function() {78 HatioBB.nav.monitor('monitor_map');79 },80 81 onMap: function(button, e) {82 HatioBB.nav.monitor('monitor_map');83 },84 onInfo: function(button, e) {85 HatioBB.nav.monitor('monitor_info');86 },87 88 onIncident: function(comp, e) {89 var view = HatioBB.nav.monitor('monitor_incident');90 /* ì¬ë¬ ê²½ë¡ì buttonëìì íµí´ì ë¤ì´ì¤ë ê²ì ê°ìí¨. */91 if(comp && comp.config && comp.config.incident)92 view.setIncident(comp.config.incident);93 else94 view.setIncident();95 },96 onCollapse : function(button, e) {97 if(this.getNav().getDocked()) {98 this.getNav().setDocked(null).hide();99 } else {100 this.getNav().setDocked(HatioBB.setting.get('dockPosition')).show();101 }102 },103 onSetting : function(button, e) {104 Ext.create('HatioBB.view.Setting', {}).showBy(button);105 },106 107 onRefresh : function(button, e) {108 var active = this.getContent().getActiveItem();109 if(typeof(active.refresh) === 'function')110 active.refresh();111 },112 113 onMapTrackTap: function(vehicle) {114 HatioBB.nav.monitor('monitor_info');115 HatioBB.setting.set('monitoring_vehicle', vehicle.get('id'));116 HatioBB.setting.set('vehicle', vehicle.get('id'));117 HatioBB.setting.set('driver', vehicle.get('driver_id'));118 },119 onMapDriverTap: function(driver) {120 HatioBB.setting.set('driver', driver.get('id'));121 HatioBB.nav.driver();122 },123 onMapVehicleTap: function(vehicle) {124 HatioBB.setting.set('vehicle', vehicle.get('id'));125 HatioBB.nav.vehicle();126 },127 onImage : function(comp) {128 if(comp.config.itemId === 'driverImage')129 HatioBB.nav.driver();130 else131 HatioBB.nav.vehicle();132 },133 onShowMap: function(vehicle) {134 HatioBB.nav.monitor('monitor_map');135 HatioBB.setting.set('vehicle', vehicle);136 },137 onShowTrack: function(vehicle) {138 HatioBB.nav.monitor('monitor_info');139 HatioBB.setting.set('vehicle', vehicle);140 }...
touch-specs.js
Source:touch-specs.js
1"use strict";2var okIfAlert = require('../../../helpers/alert').okIfAlert,3 setup = require("../../common/setup-base"),4 desired = require('./desired'),5 TouchAction = require('wd').TouchAction,6 MultiAction = require('wd').MultiAction;7describe('testapp - touch actions', function () {8 var driver;9 setup(this, desired).then(function (d) { driver = d; });10 function goToMap() {11 return driver12 .elementByXPathOrNull('//UIAMapView')13 .then(function (el) {14 if (!el) {15 return driver.elementsByClassName('UIAButton').at(5)16 .then(function (el) {17 var tap = (new TouchAction(driver)).tap({el: el});18 return driver.performTouchAction(tap);19 }).sleep(500)20 .then(function () { okIfAlert(driver); })21 .sleep(500);22 }23 });24 }25 describe('tap', function () {26 it('should tap on a specified element', function (done) {27 driver28 .elementsByClassName('UIAButton').at(3)29 .then(function (el) {30 var tap = (new TouchAction()).tap({el: el});31 return driver.performTouchAction(tap);32 }).sleep(1000).then(function () { okIfAlert(driver); })33 .elementsByClassName('UIAButton').at(3)34 .then(function (el) {35 var tap = (new TouchAction(driver)).tap({el: el});36 return tap.perform();37 }).sleep(1000).then(function () { okIfAlert(driver); })38 .nodeify(done);39 });40 });41 describe('swipe', function () {42 it('should move the page', function (done) {43 driver44 .resolve(goToMap())45 .elementByXPath('//UIAMapView')46 .then(function (el) {47 return driver.performTouchAction((new TouchAction())48 .press({el: el}).moveTo({el: el, x: 0, y: 100 }).release());49 }).sleep(5000)50 .nodeify(done);51 });52 });53 describe('wait', function () {54 it('should move the page and wait a bit', function (done) {55 driver56 .resolve(goToMap())57 .elementByXPath('//UIAMapView')58 .then(function (el) {59 return driver.performTouchAction(60 new TouchAction().press({el: el}).moveTo({el: el, x: 0, y: 100 })61 .wait({ ms: 5000 }).moveTo({el: el, x: 0, y: 0 }).release());62 }).sleep(5000)63 .nodeify(done);64 });65 });66 describe('pinch', function () {67 it('should do some pinching', function (done) {68 driver69 .resolve(goToMap())70 .elementByXPath('//UIAMapView')71 .then(function (el) {72 var multiAction = (new MultiAction()).add(73 (new TouchAction()).press({el: el}).moveTo({el: el, x: 0, y: 0 }).release(),74 (new TouchAction()).press({el: el}).moveTo({el: el, x: 100, y: 100 }).release()75 );76 return driver77 .performMultiAction(multiAction);78 })79 .sleep(5000)80 .nodeify(done);81 });82 it('should do more involved pinching in and out', function (done) {83 driver84 .resolve(goToMap())85 .elementByXPath('//UIAMapView')86 .then(function (el) {87 var multiAction = (new MultiAction()).add(88 (new TouchAction()).press({el: el}).moveTo({el: el, x: 25, y: 25 })89 .wait(3000).moveTo({el: el, x: 100, y: 100 }).release(),90 (new TouchAction()).press({el: el}).moveTo({el: el, x: 100, y: 0 })91 .wait({ ms: 3000 }).moveTo({el: el, x: 0, y: 0 }).release()92 );93 return driver.performMultiAction(multiAction);94 })95 .sleep(5000)96 .nodeify(done);97 });98 });...
myset.js
Source:myset.js
1var frame = require("ui/frame");2var Observable = require("data/observable").Observable;3var cache = require("nativescript-cache");4var observable_1 = require("data/observable");5var api = require('../../../shared/api');6var config = require("../../../shared/config");7var areaLabel;8var portrait; //ç¨æ·å¤´å9function onBackTap(args) {10 frame.topmost().goBack();11}12exports.loaded = function (args) {13 page = args.object.page;14 page = args.object.page;15 var portrait = page.getViewById("portrait");16 var userInfo = cache.get("userInfo");17 if (userInfo) { 18 var info = JSON.parse(userInfo);19 portrait.src = info["portrait"];20 }21 "å·²éç5ãå¸8ãåº52";22 areaLabel = args.object.getViewById("selectedAreaLabel");23 areaLabel.bindingContext = new observable_1.Observable({24 selectedAreaText: ""25 });26 // queryAreaNum();27}28// function queryAreaNum(){29// api.call(config.apiUrl,{30// name:"",31// }).ok().fail();32// }33function onBackTap(args) {34 frame.topmost().goBack();35}36/**æ´æ¢å¤´å */37function onChange(args) {38 var navigationEntry = {39 moduleName: 'views/my/changehead/changehead',40 }41 frame.topmost().navigate(navigationEntry)42}43/**å®åè®¤è¯ */44function onDriverTap(args) {45 api.call(config.apiUrl, {46 name: "userController.queryIfUserIdAuth",47 args: []48 }).ok(data => {49 var whetherAuth = new Observable({50 authState: data.result.hasIdentify51 });52 var navigationEntry = {53 moduleName: 'views/my/driver/driver',54 };55 var navigationEntryAuthed = {56 moduleName: 'views/my/driver_message/driver_message',57 };58 if (whetherAuth.authState) {59 frame.topmost().navigate(navigationEntryAuthed)60 } else {61 frame.topmost().navigate(navigationEntry)62 }63 }).fail(failed => {64 });65 // var navigationEntry = {66 // moduleName: 'views/my/driver/driver',67 // };68 // var navigationEntryAuthed = {69 // moduleName: 'views/my/driver_message/driver_message',70 // };71 // if (whetherAuth.authState) {72 // frame.topmost().navigate(navigationEntryAuthed)73 // } else {74 // frame.topmost().navigate(navigationEntry)75 // }76}77/**æå¡å°åº */78function onCityTap(args) {79 var navigationEntry = {80 moduleName: 'views/my/city_select_two/city_select_two',81 backstackVisible: false82 }83 frame.topmost().navigate(navigationEntry)84}85/**æå¡ç±»å */86function onServiceTypeTap(args) {87 var navigationEntry = {88 moduleName: 'views/my/server_type/server_type',89 context: {90 updateRightNow: true91 }92 // backstackVisible: false93 }94 frame.topmost().navigate(navigationEntry)95}96/**å¢å¼æå¡ */97function onIncrementServiceTap(args) {98 var navigationEntry = {99 moduleName: 'views/my/server_increment/server_increment',100 // backstackVisible: false101 }102 frame.topmost().navigate(navigationEntry)103}104exports.onBackTap = onBackTap105exports.onChange = onChange106exports.onDriverTap = onDriverTap107exports.onCityTap = onCityTap108exports.onServiceTypeTap = onServiceTypeTap...
tools.js
Source:tools.js
1// Copyright (c) 2019 by Audere2//3// Use of this source code is governed by an LGPL-3.0 license that4// can be found in the LICENSE file distributed with this file.5import wd from "wd";6import strings from "../../../src/i18n/locales/en.json";7import { multi_tap } from "./navigation";8import { Op } from "sequelize";9import axios from "axios";10//Go to version menu, change to demo mode (if specified), return installation id11export async function app_setup_for_automation(driver, deviceInfo, isDemo) {12 expect(await driver.hasElementByAccessibilityId("flu@home")).toBe(true);13 await new wd.TouchAction(driver)14 .tap({ x: deviceInfo.SCREEN_X * 0.95, y: deviceInfo.SCREEN_Y * 0.06 })15 .perform();16 expect(await driver.hasElementByAccessibilityId(strings.Version.title)).toBe(17 true18 );19 await driver.elementByAccessibilityId(strings.Version.title).click();20 expect(21 await driver.hasElementByAccessibilityId(strings.Version.description)22 ).toBe(true);23 if (isDemo) {24 await multi_tap(25 driver,26 deviceInfo,27 deviceInfo.SCREEN_X * 0.5,28 deviceInfo.SCREEN_Y * 0.13,29 330 );31 expect(await driver.hasElementByAccessibilityId("Demo Mode")).toBe(true);32 }33 let installation;34 while (!installation) {35 await driver36 .elementByAccessibilityId(strings.buildInfo.copy.toUpperCase())37 .click();38 const versionInfo = Buffer.from(39 await driver.getClipboard(),40 "base64"41 ).toString();42 installation = /Installation:\*\* (.*)/.exec(versionInfo);43 }44 await new wd.TouchAction(driver)45 .tap({ x: deviceInfo.SCREEN_X * 0.05, y: deviceInfo.SCREEN_Y * 0.06 })46 .perform();47 if (isDemo) {48 expect(await driver.hasElementByAccessibilityId("Demo Mode")).toBe(true);49 }50 return installation[1];51}52//Display stats from previous RDT capture53export async function display_rdt_stats(driver, models, installationId) {54 await driver.sleep(5000); // Let firestore sync55 const response = await axios.get(56 "http://localhost:3200/api/import/coughDocuments"57 );58 if (response.status !== 200) {59 throw new Error(`Expected 200, got ${response.status}`);60 }61 const dbRowsAndNum = await models.survey.findAndCountAll({62 where: {63 device: {64 installation: {65 [Op.eq]: installationId,66 },67 },68 },69 order: [["id", "ASC"]],70 });71 //gets most recent row with same installationId72 const dbRow = dbRowsAndNum["rows"][dbRowsAndNum["count"] - 1];73 if ("rdtReaderResult" in dbRow.survey.rdtInfo) {74 console.log(dbRow.survey.rdtInfo);75 }...
trivia.js
Source:trivia.js
1import driver from '../driver';2import capabilities from '../capabilities';3import waitForElement from '../waitForElement';4// eslint-disable-next-line no-undef5jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;6describe('HomeScreen', () => {7 beforeAll(async () => {8 await driver.init(capabilities);9 });10 afterAll(async () => {11 await driver.quit();12 });13 it('load the app', async () => {14 const homeScreen = await waitForElement('home-screen');15 expect(homeScreen).toBeDefined();16 });17 it('start the trivia', async () => {18 const startPlayingButton = await waitForElement('start-playing-button');19 expect(startPlayingButton).toBeDefined();20 await driver.tapElement(startPlayingButton);21 const triviaScreen = await waitForElement('trivia-screen');22 expect(triviaScreen).toBeDefined();23 });24 it('answer the 5 questions', async () => {25 for (let i = 0; i < 5; i++) {26 const answerOptionButton = await waitForElement('answer-option');27 expect(answerOptionButton).toBeDefined();28 await driver.tapElement(answerOptionButton);29 await driver.sleep(1000);30 }31 const triviaResultScreen = await waitForElement('trivia-result-screen');32 expect(triviaResultScreen).toBeDefined();33 });34 it('restarts trivia', async () => {35 const restartTriviaButton = await waitForElement('restart-trivia-button');36 expect(restartTriviaButton).toBeDefined();37 await driver.tapElement(restartTriviaButton);38 const homeScreen = await waitForElement('home-screen');39 expect(homeScreen).toBeDefined();40 });...
tracking.spec.js
Source:tracking.spec.js
1import { e2eDriver } from './utils/e2e-driver'2describe('Tracking functionality', () => {3 beforeEach(async () => {4 await device.uninstallApp()5 await device.installApp()6 await e2eDriver.relaunchApp()7 })8 const countrySlug = 'afghanistan'9 it('should show the tracked country on the home screen', async () => {10 await e2eDriver.openCountriesTab()11 await e2eDriver.tapOnCountryInList(countrySlug)12 await e2eDriver.toggleSwitch()13 await e2eDriver.openHomeTab()14 await e2eDriver.expectCountryCardToBeVisible(countrySlug)15 })16 it('should save the tracked list of items with app relaunch (persistence)', async () => {17 await e2eDriver.openCountriesTab()18 await e2eDriver.tapOnCountryInList(countrySlug)19 await e2eDriver.toggleSwitch()20 await e2eDriver.openHomeTab()21 await e2eDriver.expectCountryCardToBeVisible(countrySlug)22 await e2eDriver.relaunchApp()23 await e2eDriver.expectCountryCardToBeVisible(countrySlug)24 })...
driver_type.js
Source:driver_type.js
1var frame = require("ui/frame")2function onBackTap(args) {3 frame.topmost().goBack();4}5function onDriverTap(args) {6 var navigationEntry = {7 moduleName: 'views/my/driver/driver',8 }9 frame.topmost().navigate(navigationEntry)10}11function onDriverCPTap(args) {12 var navigationEntry = {13 moduleName: 'views/my/driver_company/driver_company',14 }15 frame.topmost().navigate(navigationEntry)16}17function onHelp(args) {18 var thisPage = args.object.page;19 thisPage.showModal('/views/my/views/phoneModal', function () {20 });21}22exports.onBackTap = onBackTap;23exports.onDriverTap = onDriverTap;24exports.onDriverCPTap = onDriverCPTap;...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');3driver.findElement(webdriver.By.name('btnG')).click();4driver.findElement(webdriver.By.id('resultStats')).getText().then(function(textValue) {5 console.log(textValue);6});7driver.quit();8Starting ChromeDriver (v2.8.0) on port 95159About 2,170,000,000 results (0.28 seconds)10var capabilities = {11};12info: Welcome to Appium v0.10.0 (REV 8c2b6e3f3d0b9
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desired = {4};5 .init(desired)6 .then(function () {7 })8 .then(function (el) {9 return driver.tap(el);10 })11 .fin(function () { return driver.quit(); })12 .done();13info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":{"ELEMENT":"1"},"status":0}14info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"7b8e3f3d-5a5b-4c7c-9e5a-7d9e2c0f7b2c"}15info: <-- POST /wd/hub/session/7b8e3f3d-5a5b-4c7c-9e5a-7d9e2c0f7b2c/element 200 136.628 ms - 87 {"status":0,"value":{"ELEMENT":"1"},"
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!