Best JavaScript code snippet using appium
js-wdio.js
Source:js-wdio.js
...183 codeFor_toggleTouchIdEnrollment (varNameIgnore, varIndexIgnore, enroll) {184 return `await driver.toggleTouchIdEnrollment(${enroll});`;185 }186 codeFor_openNotifications () {187 return `await driver.openNotifications();`;188 }189 codeFor_getDeviceTime () {190 return `let time = await driver.getDeviceTime();`;191 }192 codeFor_fingerprint (varNameIgnore, varIndexIgnore, fingerprintId) {193 return `await driver.fingerprint(${fingerprintId});`;194 }195 codeFor_sessionCapabilities () {196 return `let caps = await driver.session('c8db88a0-47a6-47a1-802d-164d746c06aa');`;197 }198 codeFor_setPageLoadTimeout (varNameIgnore, varIndexIgnore, ms) {199 return `await driver.timeouts('page load', ${ms})`;200 }201 codeFor_setAsyncScriptTimeout (varNameIgnore, varIndexIgnore, ms) {...
CommonPage.js
Source:CommonPage.js
1import { Given, When, Then } from "cucumber";2import { expect, assert } from "chai";3class CommonPage extends PageObject {4 botonAtrasClass = $("android.widget.ImageButton");5 dismissWarning = $("#android:id/button1");6 static teclaLabel = "Teclado Clave Tecla ";7 btnContinue = $("~Continuar");8 static addSquadToEmailAddress(mail) {9 //ESTA IMPLEMENTACION YA NO ES NECESARIA10 cell = process.env("testing.squad");11 atIndex = mail.indexOf("@") - 1;12 if (cell == null || cell == "") return mail;13 newString = "";14 for (i = 0; i < mail.length(); i++) {15 newString += mail.charAt(i);16 if (i == atIndex) {17 newString += cell;18 }19 }20 newMail = newString.replaceAll("-", "");21 return newMail;22 }23 static getWebInstitutional(url) {24 androidAppiumDriver = new AndroidAppiumDriver();25 androidAppiumDriver.newDriver().get(url);26 }27 static randomizeMail(mail) {28 uuid = UUID.randomUUID().toString();29 atIndex = mail.indexOf("@") - 1;30 newString = "";31 for (i = 0; i < mail.length(); i++) {32 newString += mail.charAt(i);33 if (i == atIndex) {34 newString += "+" + uuid;35 }36 }37 return newString;38 }39 static findElement(method, value) {40 if (process.env("testing.driver").equalsIgnoreCase("android-web")) {41 return AndroidAppiumDriver.getDriver().findElement(method, value);42 } else {43 return IOSAppiumDriver.getDriver().findElement(method, value);44 }45 }46 goBack() {47 this.botonAtrasClass.click();48 }49 dismissWarning() {50 try {51 this.dismissWarning.click();52 } catch (e) {}53 }54 openNotifications() {55 AndroidAppiumDriver.getDriver().openNotifications();56 }57 enterPasscode(pass) {58 for (i = 0; i < pass.length(); i++) {59 c = Character.toString(pass.charAt(i));60 $(teclaLabel + c).click();61 }62 }63 creoUnDebin(mail, passcode) {64 token = AgendaService.getToken(mail, passcode);65 account = AccountsMeService.accountsMe(token);66 // account = AddMovementsToAccount.accountsMe(token);67 accountNumber = account.get(0).toString();68 refNo = AddMovementsToAccount.newDebin();69 AddMovementsToAccount.authDebin(refNo, accountNumber);70 }71 takeScreenshot() {72 file = AndroidAppiumDriver.getDriver().getScreenshotAs(OutputType.FILE);73 try {74 FileUtils.copyFile(file, new File("Screenshot.png"));75 } catch (e) {76 console.log(e.message);77 }78 }79 validateURL(URLtoCompare) {80 waitForPageLoaded();81 currentURL = AndroidAppiumDriver.getDriver().getCurrentUrl();82 if (!currentURL.equals(URLtoCompare)) {83 assert.fail("No se encontró en la pagina correcta");84 }85 }86 closeWindow() {87 tabs2 =88 new ArrayList() <89 String >90 AndroidAppiumDriver.getDriver().getWindowHandles();91 AndroidAppiumDriver.getDriver()92 .switchTo()93 .window(tabs2.get(0));94 AndroidAppiumDriver.getDriver().close();95 AndroidAppiumDriver.getDriver()96 .switchTo()97 .window(tabs2.get(1));98 }99 waitForPageLoaded() {100 try {101 Thread.sleep(1000);102 wait = new WebDriverWait(AndroidAppiumDriver.getDriver(), 30);103 wait.until(expectation);104 } catch (error) {105 assert.fail("Timeout waiting for Page Load Request to complete.");106 }107 }108 pressContinue() {109 this.btnContinue.click();110 }111 userScrollDown() {112 // TODO Auto-generated method stub113 }114 usuario_ingresa_el_valor(valor) {115 try {116 Thread.sleep(3000);117 } catch (e) {118 console.log(e.message);119 }120 AndroidAppiumDriver.getDriver().getKeyboard();121 //valor.chars().forEachOrdered(i -> recorrerString((char) i));122 AndroidAppiumDriver.getDriver().hideKeyboard();123 }124 // Auxiliares125 recorrerString(valor) {126 caracter = Character.getNumericValue(valor);127 switch (caracter) {128 case 1:129 AndroidAppiumDriver.getDriver().pressKey(130 new KeyEvent(AndroidKey.DIGIT_1)131 );132 break;133 case 2:134 AndroidAppiumDriver.getDriver().pressKey(135 new KeyEvent(AndroidKey.DIGIT_2)136 );137 break;138 case 3:139 AndroidAppiumDriver.getDriver().pressKey(140 new KeyEvent(AndroidKey.DIGIT_3)141 );142 break;143 case 4:144 AndroidAppiumDriver.getDriver().pressKey(145 new KeyEvent(AndroidKey.DIGIT_4)146 );147 break;148 case 5:149 AndroidAppiumDriver.getDriver().pressKey(150 new KeyEvent(AndroidKey.DIGIT_5)151 );152 break;153 case 6:154 AndroidAppiumDriver.getDriver().pressKey(155 new KeyEvent(AndroidKey.DIGIT_6)156 );157 break;158 case 7:159 AndroidAppiumDriver.getDriver().pressKey(160 new KeyEvent(AndroidKey.DIGIT_7)161 );162 break;163 case 8:164 AndroidAppiumDriver.getDriver().pressKey(165 new KeyEvent(AndroidKey.DIGIT_8)166 );167 break;168 case 9:169 AndroidAppiumDriver.getDriver().pressKey(170 new KeyEvent(AndroidKey.DIGIT_9)171 );172 break;173 case 0:174 AndroidAppiumDriver.getDriver().pressKey(175 new KeyEvent(AndroidKey.DIGIT_0)176 );177 break;178 default:179 break;180 }181 }...
sensor.test.js
Source:sensor.test.js
...64 });65 // it('airplane mode', async () => {66 67 // await delay(2000);68 // await driver.openNotifications();69 // await delay(2000);70 // await driver.toggleAirplaneMode(); 71 // await delay(3000);72 // let status_airplane_on = await (await sensorPage.Airplane_).getText()73 // expect(status_airplane_on).equal('On')74 // console.log('turnedon airplane mode')75 // await driver.toggleAirplaneMode();76 // await delay(3000);77 // let status_airplane_off = await (await sensorPage.Airplane_).getText()78 // expect(status_airplane_off).equal('Off')79 // console.log('turnedoff airplane mode')80 // });81 it(' data', async () => {82 83 // await delay(2000);84 await driver.openNotifications();85 await delay(3000);86 await driver.toggleData(); 87 await delay(3000);88 let status_Mdata_on = await (await sensorPage.Mdata_).getText()89 expect(status_Mdata_on).equal('On')90 console.log('turnedon data ')91 await delay(3000);92 await driver.toggleData();93 await delay(3000);94 let status_Mdata_off = await (await sensorPage.Mdata_).getText()95 expect(status_Mdata_off).equal('Off')96 console.log('turnedoff data ')97 await driver.back()98 99 });100 it(' location', async () => {101 // await delay(2000);102 await driver.openNotifications();103 await delay(2000);104 // await driver.toggleLocationServices();105 await (await sensorPage.location_).click()106 await delay(3000); 107 let status_location_on = await (await sensorPage.location_).getText()108 expect(status_location_on).equal('On')109 console.log('turnedon data ')110 await delay(3000);111 // await driver.toggleLocationServices();112 await (await sensorPage.location_).click()113 await delay(3000);114 let status_location_off = await (await sensorPage.location_).getText()115 expect(status_location_off).equal('Off')116 console.log('turnedoff data ')...
Notification.js
Source:Notification.js
...7const UIObject = require('./UIObject');8class Notification{9 // Just support for Android until now10 static openNotification(driver){11 driver.openNotifications();12 }13 static getAllNotification(driver){14 let notificationElements = [];15 let elements = new UIObject(ALL_NOTIFICATION_TITLE, driver).getElements();16 return elements;17 }18 static getNotification(title, driver){19 let notificationTitleSelector = notificationTitle.replace('%s', title);20 return new UIObject(notificationTitleSelector, driver).getElement();21 }22 static clickNotification(title, driver){23 let notificationTitleSelector = notificationTitle.replace('%s', title);24 new UIObject(notificationTitleSelector, driver).click();25 }...
notifications-e2e-specs.js
Source:notifications-e2e-specs.js
...31 let el = await driver.findElement('accessibility id', ':-|');32 await driver.click(el.ELEMENT);33 // give the app a second to catch up before opening notifications34 await B.delay(1000);35 await driver.openNotifications();36 await retry(4, async () => {37 let textViews = await driver.findElements('class name', 'android.widget.TextView');38 let text = [];39 for (let view of textViews) {40 text.push(await driver.getText(view.ELEMENT));41 }42 text.should.include('Mood ring');43 });44 // go back to the app45 await driver.keyevent(4);46 await driver.getText(el.ELEMENT).should.become(':-|');47 });...
notification_steps.js
Source:notification_steps.js
...15 if(!_driver.isAndroid){16 console.log("Push notification test just work for Android platform only. IOS is not supported for this type for verification");17 return;18 }19 _driver.openNotifications();20 let notificationElement = Notification.getNotification('hayylo', _driver);21 Notification.checkIfNotificationDisplayed(notificationElement, 30, 1, _driver);22 console.log("Click back button");23 _driver.pressKeyCode(4);24 // _driver.pause(5000);25 // notificationElement.click();...
exercice3.js
Source:exercice3.js
1// https://webdriver.io/docs/api/appium.html2describe('Exercice 3', function() {3 it('Can open notifications center', function() {4 driver.openNotifications()5 driver.pause(3000)6 })7 it('Can lock device', function() {8 driver.lock()9 driver.pause(3000)10 expect(driver.isLocked()).toBe(true)11 driver.unlock()12 })13 it('Can open settings app', function() {14 // android15 // adb shell dumpsys window windows | grep -E 'mCurrentFocus'16 driver.startActivity('com.android.settings', 'com.android.settings.Settings')17 driver.pause(3000)18 // ios...
App.e2e.js
Source:App.e2e.js
...3 await driver.tapElement(button[0])4 const contexts = await driver.contexts()5 console.log(contexts)6 await driver.context(contexts[0])7 await driver.openNotifications()8 await sleep(2000)9 const notifications = await driver.elementByXPath('//*[@text="It\'s a notification!"]')10 console.log(notifications)...
Using AI Code Generation
1driver.openNotifications();2driver.closeApp();3driver.launchApp();4driver.startActivity("com.android.calculator2", "com.android.calculator2.Calculator");5driver.resetApp();6driver.backgroundApp(5);7driver.isAppInstalled("com.android.calculator2");8driver.installApp("C:\\Users\\Downloads\\Calculator.apk");9driver.removeApp("com.android.calculator2");10driver.startRecordingScreen();11driver.stopRecordingScreen();12driver.lock(5);13driver.unlock();14driver.isLocked();15driver.hideKeyboard("Done");16driver.getDeviceTime();17driver.getOrientation();18driver.setOrientation("LANDSCAPE");19driver.getGeoLocation();20driver.setGeoLocation(12.12345, 34.12345, 10.0);21driver.getNetworkConnection();22driver.setNetworkConnection(6);23driver.rotate(90);24driver.pinch(10, 10);25driver.zoom(10, 10);26driver.touchAction([{"action":"press", "options":{"x":100
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2 withCapabilities({3 build();4driver.openNotifications();5driver.quit();6var webdriver = require('selenium-webdriver');7 withCapabilities({8 build();9driver.openNotifications();10driver.quit();11var webdriver = require('selenium-webdriver');12 withCapabilities({13 build();14driver.openNotifications();15driver.quit();16var webdriver = require('selenium-webdriver');
Using AI Code Generation
1driver.openNotifications();2driver.isKeyboardShown();3driver.hideKeyboard();4driver.getOrientation();5driver.setOrientation();6driver.getGeoLocation();7driver.setGeoLocation();8driver.getPerformanceData();9driver.getPerformanceDataTypes();
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6driver.init(desiredCaps)7 .then(function () {8 return driver.openNotifications();9 })10 .then(function () {11 return driver.sleep(5000);12 })13 .then(function () {14 return driver.quit();15 })16 .done();17info: [debug] [ADB] 1 device(s) connected18info: [debug] [ADB] 1 device(s) connected
Using AI Code Generation
1driver.openNotifications();2driver.sleep(5000);3driver.openNotifications();4driver.sleep(5000);5driver.openNotifications();6driver.sleep(5000);7driver.openNotifications();8driver.sleep(5000);9driver.openNotifications();10driver.openNotifications();11driver.sleep(5000);12driver.openNotifications();13driver.sleep(5000);14driver.openNotifications();15driver.sleep(5000);16driver.openNotifications();17driver.sleep(5000);18driver.openNotifications();19driver.openNotifications();20driver.sleep(5000);21driver.openNotifications();22driver.sleep(5000);23driver.openNotifications();24driver.sleep(5000);25driver.openNotifications();26driver.sleep(5000);27driver.openNotifications();28driver.openNotifications();29driver.sleep(5000);30driver.openNotifications();31driver.sleep(5000);32driver.openNotifications();33driver.sleep(5000);34driver.openNotifications();35driver.sleep(5000);36driver.openNotifications();37driver.openNotifications();38driver.sleep(5000);39driver.openNotifications();40driver.sleep(5000);41driver.openNotifications();42driver.sleep(5000);43driver.openNotifications();44driver.sleep(5000);45driver.openNotifications();46driver.openNotifications();47driver.sleep(5000);48driver.openNotifications();49driver.sleep(5000);50driver.openNotifications();51driver.sleep(5000);52driver.openNotifications();53driver.sleep(5000);54driver.openNotifications();55driver.openNotifications();56driver.sleep(5000);57driver.openNotifications();58driver.sleep(5000);59driver.openNotifications();60driver.sleep(5000);61driver.openNotifications();62driver.sleep(5000);63driver.openNotifications();64driver.openNotifications();65driver.sleep(5000);66driver.openNotifications();67driver.sleep(5000);68driver.openNotifications();69driver.sleep(5000);70driver.openNotifications();71driver.sleep(5000);72driver.openNotifications();73driver.openNotifications();74driver.sleep(5000);75driver.openNotifications();76driver.sleep(5000);77driver.openNotifications();78driver.sleep(5000);79driver.openNotifications();80driver.sleep(5000);81driver.openNotifications();
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!!