Best JavaScript code snippet using appium-xcuitest-driver
runTests.js
Source:runTests.js
...124 }125 throw unknownProviderError;126 }).then(function() {127 console.log('Inputting username');128 return driver.elementByCss(actions[provider].emailInputSelector);129 }).delay(briefWaitTime).clear().sendKeys(argv.username).delay(briefWaitTime).then(function() {130 if (actions[provider].emailSubmitSelector) {131 return driver.elementByCss(actions[provider].emailSubmitSelector);132 }133 }).then(function(emailSubmitButton) {134 if (emailSubmitButton) {135 console.log('Sumitting username');136 emailSubmitButton.click();137 }138 }).delay(briefWaitTime).then(function() {139 console.log('Inputting password');140 return driver.elementByCss(actions[provider].passwordInputSelector);141 }).delay(briefWaitTime).clear().sendKeys(password).then(function() {142 console.log('Submitting form');143 }).then(function() {144 return driver.elementByCss(actions[provider].passwordSubmitSelector);145 }).delay(briefWaitTime).click().then(function() {146 console.log('Submitted form');147 }).then(function() {148 ++loginCount;149 console.log(provider + ' login successful!');150 console.log('Providers processed so far: ' + loginCount);151 setTimeout(function() {152 login();153 }, loginWindowWaitTime);154 }, function(error) {155 var retry;156 if (error === unknownProviderError) {157 console.log('Selected window is not a supported provider window.');158 retry = true;...
by-css-e2e-specs.js
Source:by-css-e2e-specs.js
...12 after(async function () {13 await deleteSession();14 });15 it('should find an element by id (android resource-id)', async function () {16 await driver.elementByCss('#text1').should.eventually.exist;17 await driver.elementByCss('*[id="android:id/text1"]').should.eventually.exist;18 await driver.elementByCss('*[resource-id="text1"]').should.eventually.exist;19 });20 it('should find an element by content description', async function () {21 await driver.elementByCss('*[description="Animation"]').should.eventually.exist;22 });23 it('should return an array of one element if the `multi` param is true', async function () {24 let els = await driver.elementsByCss('*[content-desc="Animation"]');25 els.should.be.an.instanceof(Array);26 els.should.have.length(1);27 });28 it('should find an element with a content-desc property containing an apostrophe', async function () {29 await driver.elementByCss('*[content-description="Access\'ibility"]').should.eventually.exist;30 });31 it('should find an element by class name', async function () {32 let el = await driver.elementByCss('android.widget.TextView');33 const text = await el.text();34 text.toLowerCase().should.equal('api demos');35 });36 it('should find an element with a chain of attributes and pseudo-classes', async function () {37 let el = await driver.elementByCss('android.widget.TextView[clickable=true]:nth-child(1)');38 await el.text().should.eventually.equal('Accessibility');39 });40 it('should find an element with recursive UiSelectors', async function () {41 await driver.elementsByCss('*[focused=true] *[clickable=true]')42 .should.eventually.have.length(1);43 });44 it('should allow multiple selector statements and return the Union of the two sets', async function () {45 let clickableEls = await driver.elementsByCss('*[clickable]');46 clickableEls.length.should.be.above(0);47 let notClickableEls = await driver.elementsByCss('*[clickable=false]');48 notClickableEls.length.should.be.above(0);49 let both = await driver.elementsByCss('*[clickable=true], *[clickable=false]');50 both.should.have.length(clickableEls.length + notClickableEls.length);51 });52 it('should find an element by a non-fully qualified class name using CSS tag name', async function () {53 const els = await driver.elementsByCss('android.widget.TextView');54 els.length.should.be.above(0);55 });56 it('should find an element in the second selector if the first finds no elements (when finding multiple elements)', async function () {57 let selector = 'not.a.class, android.widget.TextView';58 const els = await driver.elementsByCss(selector);59 els.length.should.be.above(0);60 });61 it('should find elements using starts with attribute', async function () {62 await driver.elementByCss('*[description^="Animation"]').should.eventually.exist;63 });64 it('should find elements using ends with attribute', async function () {65 await driver.elementByCss('*[description$="Animation"]').should.eventually.exist;66 });67 it('should find elements using word match attribute', async function () {68 await driver.elementByCss('*[description~="Animation"]').should.eventually.exist;69 });70 it('should find elements using wildcard attribute', async function () {71 await driver.elementByCss('*[description*="Animation"]').should.eventually.exist;72 });73 it('should allow UiScrollable with unicode string', async function () {74 await driver.startActivity({appPackage: 'io.appium.android.apis', appActivity: '.text.Unicode'});75 let selector = '*[text="عربÙ"]:instance(0)';76 let el = await driver.elementByCss(selector);77 await el.text().should.eventually.equal('عربÙ');78 });...
web-e2e-specs.js
Source:web-e2e-specs.js
...32 it('should send text to html text inputs', async function () {33 const html = await driver.source();34 html.should.match(/Selenium/);35 // Chrome 83 must be W3C36 const textbox = await driver.elementByCss('#i_am_a_textbox');37 await textbox.clear();38 await textbox.type('Text contents');39 await textbox.getAttribute('value').should.eventually.equal('Text contents');40 await textbox.clear();41 await textbox.text().should.eventually.equal('');42 });43 it('should navigate between webview pages', async function () {44 const anchorLink = await driver.elementByCss('[id="i am a link"]');45 await anchorLink.click();46 const bodyEl = await driver.elementByTagName('body');47 bodyEl.getAttribute('value').should.eventually.equal(/I am some other page content/);48 await driver.back();49 await driver.elementByCss('[id="i am a link"]').should.eventually.exist;50 });51 it('should be able to switch from webview back to native, navigate to a different webview and then switch back to web context', async function () {52 // Switch to webview53 let contexts = await driver.contexts();54 await driver.context(contexts[1]);55 await driver.title().should.eventually.equal('I am a page title');56 // Switch to native and go to different activity57 await driver.context(contexts[0]);58 await driver.startActivity({59 appPackage: 'io.appium.android.apis',60 appActivity: 'io.appium.android.apis.view.WebView3',61 });62 contexts = await driver.contexts();63 await driver.elementById('android:id/content').should.eventually.exist;...
CanLogin.uat.js
Source:CanLogin.uat.js
1/*jslint node: true */2"use strict";3require("../helpers/setup");4var wd = require("wd"),5 _ = require('underscore'),6 serverConfigs = require('../helpers/appium-servers'),7 path = require('path');8describe("Can Login", function () {9 this.timeout(300000);10 var driver;11 var allPassed = true,12 username = process.env.PRIVATE_USERNAME,13 password = process.env.PRIVATE_PASSWORD,14 platform = process.env.PLATFORM || 'ios',15 iOSDeviceUDID = process.env.IOS_UDID;16 function setupWithAppiumServer(serverConfig) {17 return wd.promiseChainRemote(serverConfig);18 }19 function setupLogging(driver) {20 require("../helpers/logging").configure(driver);21 }22 function addCapabilitiesAndInit(capabilities, driver) {23 var desired = _.clone(capabilities[platform]);24 desired.app = path.join('../../', require("../helpers/apps")[platform + 'Hybrid']);25 if (platform === 'ios' && iOSDeviceUDID) {26 desired.app = path.join('../../', require("../helpers/apps")[platform + 'Hybrid' + 'Device']);27 desired.udid = iOSDeviceUDID;28 }29 if (platform === 'android') {30 desired.appPackage = process.env.APP_PACKAGE;31 desired.appActivity = process.env.APP_ACTIVITY;32 }33 if (process.env.SAUCE) {34 desired.name = platform + ' - Can login';35 desired.tags = ['sample'];36 }37 return driver.init(desired);38 }39 function switchToUIWebViewContext(driver) {40 // instead of default NATIVE_APP context41 return driver.setImplicitWaitTimeout(3000)42 .contexts()43 .then(function (contexts) {44 var webViewContext = _.find(contexts, function (context) {45 return context.indexOf('WEBVIEW') !== -1;46 });47 console.log('webViewContext', webViewContext);48 return driver.context(webViewContext);49 });50 }51 before(function () {52 var serverConfig = process.env.SAUCE ? serverConfigs.sauce : serverConfigs.local;53 driver = setupWithAppiumServer(serverConfig);54 setupLogging(driver);55 driver = addCapabilitiesAndInit(require("../helpers/capabilities"), driver);56 return switchToUIWebViewContext(driver);57 });58 after(function () {59 return driver.quit().finally(function () {60 if (process.env.SAUCE) {61 return driver.sauceJobStatus(allPassed);62 }63 });64 });65 afterEach(function () {66 allPassed = allPassed && this.currentTest.state === 'passed';67 });68 it("should have an email field ", function () {69 return driver70 .elementByCss('input[type=\'email\']', 500)71 .should.eventually.exist;72 });73 it("should have a password field ", function () {74 return driver75 .elementByCss('input[type=\'password\']')76 .should.eventually.exist;77 });78 it("should login with correct name and password", function () {79 return driver80 .elementByCss('input[type=\'email\']')81 .sendKeys(username)82 .elementByCss('input[type=\'password\']')83 .sendKeys(password)84 .elementByCss('.sign-in').click()85 .waitForElementByCss('.app-title', 5000)86 .waitForElementByCss('.app-button', 5000)87 .text().should.eventually.include('+');88 });...
homepage.test.js
Source:homepage.test.js
1'use strict';2import Promise from 'bluebird';3import {4 webpackHelper5} from 'macaca-wd';6const {7 driver,8 BASE_URL9} = webpackHelper;10describe('./test/homepage.test.js', () => {11 describe('page func testing', () => {12 before(() => {13 return driver14 .initWindow({15 width: 375,16 height: 667,17 deviceScaleFactor: 218 });19 });20 beforeEach(() => {21 return driver22 .getUrl(BASE_URL);23 });24 afterEach(function () {25 return driver26 .coverage()27 .saveScreenshots(this);28 });29 after(() => {30 return driver31 .openReporter(true)32 .quit();33 });34 it('panel should be ok', () => {35 const elementGroup = `#simplest .btn-group`;36 const elementButton = `${elementGroup} button`;37 const elementRect = `document.querySelector('${elementGroup}').getClientRects()`;38 const height = `${elementRect}[0].y || ${elementRect}[0].top`;39 return driver40 .execute(`window.scrollTo(0, ${height})`)41 .elementsByCss(elementButton)42 .then(list => {43 const queue = list.map((item, key) => `${elementButton}:nth-child(${key + 1})`);44 return Promise.reduce([null].concat(queue), (i, selector) => {45 return driver46 .elementByCss(selector)47 .click()48 .sleep(500)49 .click()50 .sleep(500);51 });52 });53 });54 it('waterfall should be ok', () => {55 const element = `#waterfall .rc-autoresponsive-container`;56 const elementRect = `document.querySelector('${element}').getClientRects()`;57 const height = `${elementRect}[0].y || ${elementRect}[0].top`;58 return driver59 .sleep(1500)60 .execute(`window.scrollTo(0, ${height})`)61 .sleep(500)62 .elementsByCss(`${element} .item`)63 .then(list => {64 const queue = list.map((item, key) => `${element} > .item:nth-child(${key + 1})`);65 return Promise.reduce(queue, (i, selector) => {66 return driver67 .elementByCss(selector)68 .click()69 .sleep(1000)70 .click();71 });72 });73 });74 it('i18n should be ok', () => {75 return driver76 .elementByCss('div.i18n-buttons > div > button:nth-child(2)')77 .click()78 .sleep(1000)79 .elementByCss('div.i18n-buttons > div > button:nth-child(1)')80 .click()81 .getUrl(`${BASE_URL}?locale=zh`)82 .sleep(500);83 });84 it('resize should be ok', () => {85 return driver86 .setWindowSize(800, 600);87 });88 it('hash should be ok', () => {89 return driver90 .elementById('examples')91 .click()92 .sleep(500);93 });94 it('hash redirect should be ok', () => {95 return driver96 .getUrl(`${BASE_URL}/#usage`)97 .sleep(1000);98 });99 });...
todo.test.js
Source:todo.test.js
1'use strict';2import {3 webpackHelper4} from 'macaca-wd';5const {6 driver,7 BASE_URL8} = webpackHelper;9describe('test/todo.test.js', () => {10 before(() => {11 return driver12 .initWindow({13 width: 800,14 height: 600,15 deviceScaleFactor: 216 });17 });18 beforeEach(() => {19 return driver20 .getUrl(`${BASE_URL}/src`);21 });22 afterEach(function () {23 return driver24 .coverage()25 .saveScreenshots(this);26 });27 after(() => {28 return driver29 .openReporter(true)30 .quit();31 });32 describe('Page input testing', () => {33 it('Input todo task', () => {34 return driver35 .elementByCss('#new-todo')36 .formInput(`Create Medium article by formInput ${Date.now()}`)37 .elementByCss('#new-todo')38 .domEvent('keyup', {39 key: 'Enter',40 keyCode: 13,41 })42 .sleep(3000)43 .elementByCss('#new-todo')44 .clear()45 .sendKeys(`Create Medium article by sendKeys ${Date.now()}`)46 .elementByCss('#new-todo')47 .domEvent('keyup', {48 key: 'Enter',49 keyCode: 13,50 });51 });52 });53 describe('Page checked testing', () => {54 it('Click done one task', () => {55 return driver56 .elementByCss('#new-todo')57 .formInput(`Create Medium article by formInput ${Date.now()}`)58 .elementByCss('#new-todo')59 .domEvent('keyup', {60 key: 'Enter',61 keyCode: 13,62 })63 .sleep(1500)64 .elementByCss('.toggle')65 .click()66 .sleep(1500);67 });68 it('Click clear completed', () => {69 return driver70 .elementByCss('#new-todo')71 .formInput(`Create Medium article by formInput ${Date.now()}`)72 .elementByCss('#new-todo')73 .domEvent('keyup', {74 key: 'Enter',75 keyCode: 13,76 })77 .sleep(2000)78 .elementByCss('#new-todo')79 .clear()80 .sendKeys(`Create Medium article by sendKeys ${Date.now()}`)81 .elementByCss('#new-todo')82 .domEvent('keyup', {83 key: 'Enter',84 keyCode: 13,85 })86 .elementByCss('.toggle')87 .click()88 .sleep(1500)89 .elementByCss('#clear-completed')90 .click()91 .sleep(1500);92 });93 });...
sample.test.js
Source:sample.test.js
1'use strict';2const wd = require('macaca-wd');3describe('./test/sample.test.js', function() {4 this.timeout(5 * 60 * 1000);5 const driver = wd.promiseChainRemote({6 host: 'localhost',7 port: process.env.MACACA_SERVER_PORT || 34568 });9 before(() => {10 return driver.init({11 platformName: 'desktop',12 browserName: 'chrome',13 chromeOptions: {14 binary: '/Applications/macaca-electron-builder.app/Contents/MacOS/macaca-electron-builder' // å¡«åèªå·±çæ§è¡æ件路å²15 }16 }).sleep(2 * 1000)17 });18 after(() => {19 return driver20 .sleep(1000)21 .close();22 })23 it('click link', () => {24 return driver25 .waitForElementById('macacaId', 5000, 100)26 .click();27 })28 it('click button', () => {29 return driver30 .elementByCss('#app > div > header > div.sidebar-button')31 .click();32 })33 it('click title ', () => {34 return driver35 .elementByCss('#app > div > div.sidebar > nav > div:nth-child(2) > div > a > span.title')36 .sleep(2000)37 .click();38 })39 it('click title', () => {40 return driver41 .elementByCss('#app > div > div.sidebar > nav > div:nth-child(3) > div > a > span.title')42 .sleep(2000)43 .click();44 })45 it('input text', () => {46 return driver47 .elementByCss('#app > div > header > div.links > div > input')48 .sleep(2000)49 .click()50 .sendKeys('计ç®æº');51 })...
index.js
Source:index.js
...16 return driver.title().should.eventually.equals('hello tarifa');17 });18 it("should check the displayed product_name", function () {19 var p = config.product_name;20 return driver.elementByCss('#name').text().should.eventually.equals(p);21 });22 it("should check the displayed id", function () {23 var id = config.id;24 return driver.elementByCss('#id').text().should.eventually.equals(id);25 });...
Using AI Code Generation
1var wd = require('wd');2var asserters = wd.asserters;3 .init({4 })5 .then(function () {6 return driver.elementByCss('XCUIElementTypeNavigationBar');7 })8 .then(function (el) {9 return el.getAttribute('name');10 })11 .then(function (text) {12 console.log(text);13 })14 .fin(function () { return driver.quit(); })15 .done();
Using AI Code Generation
1driver.elementByCss('#myElement')2 .then(function (el) {3 });4driver.elementByCss('#myElement')5 .then(function (el) {6 });7driver.elementByCss('#myElement')8 .then(function (el) {9 });10driver.elementByCss('#myElement')11 .then(function (el) {12 });13driver.elementByCss('#myElement')14 .then(function (el) {15 });16driver.elementByCss('#myElement')17 .then(function (el) {18 });19driver.elementByCss('#myElement')20 .then(function (el) {21 });22driver.elementByCss('#myElement')23 .then(function (el) {24 });25driver.elementByCss('#myElement')26 .then(function (el) {27 });28driver.elementByCss('#myElement')29 .then(function (el) {30 });31driver.elementByCss('#myElement')
Using AI Code Generation
1var wd = require("wd");2require('colors');3var assert = require("assert");4var Q = require("q");5var _ = require("lodash");6var fs = require("fs");7var path = require("path");8var app = require("./app");9var desired = {10};11 .init(desired)12 .setImplicitWaitTimeout(10000)13 .then(function() {14 return driver.elementByCss("XCUIElementTypeButton");15 })16 .then(function(el) {17 return el.click();18 })19 .then(function() {20 return driver.elementByCss("XCUIElementTypeStaticText");21 })22 .then(function(el) {23 return el.text();24 })25 .then(function(text) {26 console.log(text);27 })28 .fin(function() {29 return driver.quit();30 })31 .done();
Using AI Code Generation
1var webdriver = require('webdriverio');2var desiredCaps = {3};4var driver = webdriver.remote({5});6 .init()7 .then(function () {8 return driver.elementByCss('XCUIElementTypeWindow[vis
Using AI Code Generation
1describe('Test', function () {2 it('should work', function () {3 return driver.elementByCss('#element_id')4 .click();5 });6});7describe('Test', function () {8 it('should work', function () {9 return driver.elementByCss('#element_id')10 .click();11 });12});13describe('Test', function () {14 it('should work', function () {15 return driver.elementByCss('#element_id')16 .click();17 });18});19describe('Test', function () {20 it('should work', function () {21 return driver.elementByCss('#element_id')22 .click();23 });24});25describe('Test', function () {26 it('should work', function () {27 return driver.elementByCss('#element_id')28 .click();29 });30});31describe('Test', function () {32 it('should work', function () {33 return driver.elementByCss('#element_id')34 .click();35 });36});37describe('Test', function () {38 it('should work', function () {39 return driver.elementByCss('#element_id')40 .click();41 });42});43describe('Test', function () {44 it('should work', function () {45 return driver.elementByCss('#element_id')
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!!