Best JavaScript code snippet using appium-android-driver
localstore.js
Source: localstore.js
...194 this.driver = w.localStorage;195 }196 Y.extend(HTML5Driver,BaseDriver,{197 clear:function(){198 this.driver.clear();199 },200 getItem:function(key){201 return this.driver.getItem(key);202 },203 setItem:function(key,value){204 this.driver.setItem(key,value);205 },206 removeItem:function(key){207 this.driver.removeItem(key);208 }209 });210 //DriverçGECKOåç±»211 function GECKODriver(config) {212 this.driver = w.globalStorage[w.location.hostname];...
basic.test.js
Source: basic.test.js
1import {2 describe,3 it4} from 'mocha';5import {6 expect7} from 'chai';8import {9 getDriver,10 testWrapper,11 releaseDriver12} from '../src/driverActions';13import {14 pressButtons,15 plus,16 minus,17 times,18 divide,19 equals,20 clear,21 point,22 divideChar,23 multiplyChar,24 multiply,25 pointChar26} from './utils';27describe('Basic calculator tests', async function () {28 let ctx;29 before(async () => {30 ctx = this.ctx;31 await getDriver(ctx);32 });33 after(async () => await releaseDriver(ctx));34 it('When a number is clicked it shows on the display', async () => {35 const numClicked = '1';36 let sum;37 await testWrapper(ctx, async () => {38 await pressButtons(ctx.driver, clear, 1);39 sum = await ctx.driver.elementByAccessibilityId('sum').text()40 });41 expect(sum).to.equal(numClicked);42 });43 44 it('When 123.4...5 is entered it displays 123.45', async () => {45 let sum;46 await testWrapper(ctx, async () => {47 await pressButtons(ctx.driver, clear, 1, 2, 3, point, 4, point, point, point, 5);48 sum = await ctx.driver.elementByAccessibilityId('sum').text();49 });50 expect(sum).to.equal(`123${pointChar}45`);51 });52 it(`When -2 ${multiplyChar} ${multiplyChar} 2 ${divideChar} ${divideChar} is entered it is displayed and equals -4`, async () => {53 let sum, result;54 await testWrapper(ctx, async () => {55 await pressButtons(ctx.driver, clear,minus, 2, multiply, multiply, 2, divide, divide);56 sum = await ctx.driver.elementByAccessibilityId('sum').text();57 await pressButtons(ctx.driver, equals);58 result = await ctx.driver.elementByAccessibilityId('sum').text();59 });60 expect(sum).to.equal(`-2 ${multiplyChar} 2 ${divideChar} `);61 expect(result).to.equal('-4');62 });63 it('When 2 + 3 is entered it displays and equals 5', async () => {64 let sum, result;65 await testWrapper(ctx, async () => {66 await pressButtons(ctx.driver, clear, '2', plus, '3');67 sum = await ctx.driver.elementByAccessibilityId('sum').text()68 await pressButtons(ctx.driver, equals);69 result = await ctx.driver.elementByAccessibilityId('sum').text();70 });71 expect(sum).to.equal('2 + 3');72 expect(result).to.equal('5');73 });74 it('When 5 * -5 is entered it displays and equals -25', async () => {75 let sum, result;76 await testWrapper(ctx, async () => {77 await pressButtons(ctx.driver,clear, '5', multiply, minus, '5');78 sum = await ctx.driver.elementByAccessibilityId('sum').text();79 await pressButtons(ctx.driver, equals);80 result = await ctx.driver.elementByAccessibilityId('sum').text();81 });82 expect(sum).to.equal(`5 ${multiplyChar} -5`);83 expect(result).to.equal('-25');84 });85 it('When a sum is cleared it displays 0', async () => {86 let sum;87 await testWrapper(ctx, async () => {88 await pressButtons(ctx.driver, '2', plus, '3');89 await pressButtons(ctx.driver, clear);90 sum = await ctx.driver.elementByAccessibilityId('sum').text();91 });92 expect(sum).to.equal('0');93 });94 it('When a result is cleared it displays 0', async () => {95 let result;96 await testWrapper(ctx, async () => {97 await pressButtons(ctx.driver, clear, '2', plus, '3', equals);98 await pressButtons(ctx.driver, clear);99 result = await ctx.driver.elementByAccessibilityId('sum').text();100 });101 expect(result).to.equal('0');102 });103 it('When a result is shown pressing a number clears it', async () => {104 let result;105 await testWrapper(ctx, async () => {106 await pressButtons(ctx.driver, clear, '2', minus, '3', equals);107 await pressButtons(ctx.driver, 1);108 result = await ctx.driver.elementByAccessibilityId('sum').text();109 });110 expect(result).to.equal('1');111 });112 113 it('When a result is shown arithmatic is appended to it', async () => {114 let result;115 await testWrapper(ctx, async () => {116 await pressButtons(ctx.driver, clear, '2', minus, '3', equals);117 await pressButtons(ctx.driver, multiply);118 result = await ctx.driver.elementByAccessibilityId('sum').text();119 });120 expect(result).to.equal(`-1 ${multiplyChar} `);121 });122 it(`When 0 ${divideChar} 0 is entered it is displays and equals NaN`, async () => {123 let sum, result;124 await testWrapper(ctx, async () => {125 await pressButtons(ctx.driver, clear, '0', divide, '0');126 sum = await ctx.driver.elementByAccessibilityId('sum').text();127 await pressButtons(ctx.driver, equals);128 result = await ctx.driver.elementByAccessibilityId('sum').text();129 });130 expect(sum).to.equal(`0 ${divideChar} 0`);131 expect(result).to.equal('NaN');132 });...
keyboard-specs.js
Source: keyboard-specs.js
...20 env.sendKeyStrategy.should.equal(21 process.env.REAL_DEVICE ? 'grouped' : 'oneByOne');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 });...
index.js
Source: index.js
1/*2** File: session.js3** Usage: use session at some special situation4** About: 5** support@mae.im6*/7module.exports = (function(driver){8 var $session=function(key,value)9 {10 if(value===undefined)11 {12 return driver.readSession($session.id, key);13 }14 driver.writeSession($session.id, key, value);15 };16 var newid = function(){return F.random.word(20);};17 $session.setTimeout = function(timeout)18 {19 driver.setTimeout($session.id, timeout);20 $session.timeout = timeout;21 };22 $session.clear = function()23 {24 driver.clearSession($session.id);25 };26 $session.timeout = 1200;27 $session.id = driver.getSessionid();28 if($session.id == "")29 {30 $session.id = newid();31 }32 else33 {34 var timeout = driver.getTimeout($session.id);35 if(typeof timeout=="number") $session.timeout = timeout;36 var time_start = driver.getStartTimeSpan($session.id);37 if(typeof time_start == "number")38 {39 if(F.timespan() - time_start >$session.timeout){40 driver.clearSession($session.id);41 $session.id = newid();42 }43 }44 else45 {46 $session.id = newid();47 }48 }49 driver.setStartTimeSpan($session.id, F.timespan());50 var badsession = driver.checkSession();51 while(badsession.length>0){52 driver.clearSession(badsession.pop());53 }54 return $session;55})((function(){56 /*session driver, you can use your own driver, such as IO, Database and so on...*/57 var driver = {};58 driver.writeSession = function(sessionid, key, value)59 {60 Application.Lock();61 Application(sessionid + ":" + key) = value;62 Application.UnLock();63 };64 driver.readSession = function(sessionid, key)65 {66 return Application(sessionid + ":" + key);67 };68 driver.checkSession = function()69 {70 var lists=[];71 F.each(Application.Contents, function(q) {72 if(F.string.endsWith(q,".timeout"))73 {74 var sessionid = q.substr(0,q.indexOf(".timeout"));75 if(F.timespan() - Application(sessionid) > Application(q)){76 lists.push(q);77 }78 }79 });80 return lists;81 };82 driver.clearSession = function(sessionid)83 {84 var lists=[];85 F.each(Application.Contents, function(q) {86 var l = q.substr(0,sessionid.length+1);87 if(q.length > sessionid.length+1 && (l == (sessionid + ":") || l == (sessionid + ".")))88 {89 lists.push(q);90 }91 });92 while(lists.length>0)93 {94 Application.Contents.Remove(lists.pop());95 }96 Application.Contents.Remove(sessionid);97 };98 99 driver.setTimeout = function(sessionid,timeout)100 {101 Application.Lock();102 Application(sessionid + ".timeout") = timeout;103 Application.UnLock();104 };105 106 driver.getTimeout = function(sessionid)107 {108 return Application(sessionid + ".timeout");109 };110 111 driver.getStartTimeSpan = function(sessionid)112 {113 return Application(sessionid);114 };115 116 driver.setStartTimeSpan = function(sessionid,timespan)117 {118 Application.Lock();119 Application(sessionid) = timespan;120 Application.UnLock();121 };122 123 driver.getSessionid = function()124 {125 return F.get("sessionid");126 };127 return driver; ...
daylightHarvesting.page.js
Source: daylightHarvesting.page.js
1'use strict';2import { mockCustomer as mockCustomer } from '../../variables';3const createDaylightHarvestingPage = function () {4 // elements5 this.popUp = $(".noty_text");6 this.daylightGrid = $('#Daylight-grid');7 this.addDaylightButton = $('.rubix-icon.icon-fontello-plus-circle');8 this.modal = $('.modal-dialog');9 this.name = $('#name');10 this.highLux = $('#highLux');11 this.lowLux = $('#lowLux');12 this.lowDriver = $('#lowDriver');13 this.minDriver = $('#minDriver');14 this.saveDhProfile = $('#saveDhProfile');15 this.groupsGrid = $('#Group-grid');16 this.showHideDetailsButton = $('#showDetailsGroups');17 this.gropsDetailPanel = $('#group-detail-panel');18 this.etdhprofileDropDown = $('#etdhprofile');19 this.saveGroupsInfo = $('#save-group-button');20 this.fillForm = function (data) {21 this.name.sendKeys(data.name);22 this.highLux.clear();23 this.highLux.sendKeys(data.highLux);24 this.lowLux.clear();25 this.lowLux.sendKeys(data.lowLux);26 this.lowDriver.clear();27 this.lowDriver.sendKeys(data.lowDriver);28 this.minDriver.clear();29 this.minDriver.sendKeys(data.minDriver);30 this.saveDhProfile.click();31 };32 this.searchGroup = function (data) {33 browser.wait(until.visibilityOf(this.groupsGrid), waitTimeout);34 $('.slick-headerrow-column:nth-child(2) input').sendKeys(data);35 $('.slick-row:first-child > .slick-cell:nth-child(2)').getText().then((data) => {36 expect(data).to.equal(data);37 });38 $('.grid-canvas .slick-row').click();39 };40};...
marquee.js
Source: marquee.js
1// helper function to marquee text across the screen2function measureText(text, driver) {3 let len = 0;4 for (let i = 0; i < text.length; i++) {5 const char = text[i];6 const letter = driver.font[char];7 len += letter[0].length + 1;8 }9 return len;10}11/**12 * Returns a function to cancel the marquee13 */14module.exports = function marquee(text, driver, speed = 1) {15 const changeDelay = 1500 / speed;16 const moveDelay = 500 / speed;17 let stop = false;18 const textLength = measureText(text, driver);19 if (textLength <= driver.dimensions.width) {20 driver.clearFrameBuffer();21 driver.drawString(text);22 driver.flushFrameBuffer();23 // no-op24 return () => {};25 } else {26 let timeoutHandle;27 let x = 0;28 function reset() {29 x = 0;30 driver.clearFrameBuffer();31 driver.drawString(text, { x, y: 0});32 driver.flushFrameBuffer();33 timeoutHandle = setTimeout(move, changeDelay);34 }35 function move() {36 if (stop) return;37 x -= 1;38 driver.clearFrameBuffer();39 driver.drawString(text, { x, y: 0});40 driver.flushFrameBuffer();41 if (x < -(textLength - driver.dimensions.width)) {42 timeoutHandle = setTimeout(reset, changeDelay);43 } else {44 timeoutHandle = setTimeout(move, moveDelay);45 }46 }47 reset();48 return () => {49 clearTimeout(timeoutHandle);50 stop = true;51 };52 }...
demo.js
Source: demo.js
1const ButtonDriver = require("../button/button_driver")2const DisplayDriver = require("../display/display_driver")3function demo() {4 const busNumber = 15 const displayAddress = 0x3c6 const displayDriver = new DisplayDriver(busNumber, displayAddress)7 const buttonsAddress = 0x208 const buttonDriver = new ButtonDriver(busNumber, buttonsAddress)9 buttonDriver.watchAllButtons(function(buttonPin) {10 if (buttonPin == 2) {11 displayDriver.clear()12 displayDriver.setQrCode("http://google.com")13 } else {14 displayDriver.clear()15 displayDriver.writeText("Clicked #" + buttonPin)16 }17 })18 displayDriver.writeText("Click me!")19 console.log("Check the display...")20}...
dumpLogs.js
Source: dumpLogs.js
1/* eslint no-magic-numbers: ["error", { "ignore": [0, 2, 1000] }] */2const getBrowserLogs = require('./getBrowserLogs');3function formatLogEntries(entries) {4 return entries5 .map(({ level: { name }, message }) => {6 let text = message.split(' ').slice(2).join(' ');7 if (text.length > 1000) {8 text = text.slice(0, 1000) + 'â¦';9 }10 return `ð [${name}] ${text}`;11 })12 .join('\n');13}14module.exports = async function dumpLogs(webDriver, { clear } = {}) {15 let logs;16 try {17 logs = await getBrowserLogs(webDriver, { clear });18 } catch (err) {19 logs = [];20 }21 logs.length && console.log(formatLogEntries(logs));...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').build();3driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');4driver.findElement(webdriver.By.name('btnG')).click();5driver.wait(function() {6 return driver.getTitle().then(function(title) {7 return title === 'webdriver - Google Search';8 });9}, 1000);10driver.findElement(webdriver.By.name('q')).clear();11driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');12driver.findElement(webdriver.By.name('btnG')).click();13driver.wait(function() {14 return driver.getTitle().then(function(title) {15 return title === 'webdriver - Google Search';16 });17}, 1000);18driver.quit();
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3driver.init({4}).then(function() {5 return driver.elementById('addContactButton');6}).then(function(el) {7 return el.click();8}).then(function() {9 return driver.elementById('contactNameEditText');10}).then(function(el) {11 return el.sendKeys('Test Contact');12}).then(function() {13 return driver.elementById('contactEmailEditText');14}).then(function(el) {15 return el.sendKeys('
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5var driver = wd.promiseChainRemote("localhost", 4723);6 .init(desiredCaps)7 .elementById('clearTest')8 .clear()9 .then(function() {10 return driver.elementById('clearTest');11 })12 .text()13 .then(function(text) {14 assert.equal(text, '');15 })16 .fin(function() {17 return driver.quit();18 })19 .done();20var wd = require('wd');21var assert = require('assert');22var desiredCaps = {23};24var driver = wd.promiseChainRemote("localhost", 4723);25 .init(desiredCaps)26 .elementById('clearTest')27 .clear()28 .then(function() {29 return driver.elementById('clearTest');30 })31 .text()32 .then(function(text) {33 assert.equal(text, '');34 })35 .fin(function() {36 return driver.quit();37 })38 .done();
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6driver.init(desiredCaps);7driver.sleep(5000);8driver.sleep(5000);9driver.quit();
Check out the latest blogs from LambdaTest on this topic:
Testing is a critical step in any web application development process. However, it can be an overwhelming task if you don’t have the right tools and expertise. A large percentage of websites still launch with errors that frustrate users and negatively affect the overall success of the site. When a website faces failure after launch, it costs time and money to fix.
The web development industry is growing, and many Best Automated UI Testing Tools are available to test your web-based project to ensure it is bug-free and easily accessible for every user. These tools help you test your web project and make it fully compatible with user-end requirements and needs.
Desired Capabilities is a class used to declare a set of basic requirements such as combinations of browsers, operating systems, browser versions, etc. to perform automated cross browser testing of a web application.
Manual cross browser testing is neither efficient nor scalable as it will take ages to test on all permutations & combinations of browsers, operating systems, and their versions. Like every developer, I have also gone through that ‘I can do it all phase’. But if you are stuck validating your code changes over hundreds of browsers and OS combinations then your release window is going to look even shorter than it already is. This is why automated browser testing can be pivotal for modern-day release cycles as it speeds up the entire process of cross browser compatibility.
Mobile devices and mobile applications – both are booming in the world today. The idea of having the power of a computer in your pocket is revolutionary. As per Statista, mobile accounts for more than half of the web traffic worldwide. Mobile devices (excluding tablets) contributed to 54.4 percent of global website traffic in the fourth quarter of 2021, increasing consistently over the past couple of years.
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!!