Best JavaScript code snippet using appium-xcuitest-driver
follows.test.js
Source:follows.test.js
...6 it("should show my follows", function* (driver, done) {7 server.get("/api/follows/tester", fixtures.myFollows());8 yield bootstrap().login().nav("dashboard/follows").launch(driver);9 10 yield driver.elementById('Dashboard');11 yield driver.elementById('friend');12 yield driver.elementById('follow2');13 done();14 });15 it("should show an empty list", function* (driver, done) {16 server.get("/api/follows/tester", { username: "tester", follows: [] });17 yield bootstrap().login().nav("dashboard/follows").launch(driver);18 yield driver.elementById('Follows');19 yield driver.elementById('No items');20 done();21 });22 it("should my friends's follows", function* (driver, done) {23 server.get("/api/follows/friend", fixtures.friendFollows());24 yield bootstrap().login().nav("dashboard/follows/friend/follows").launch(driver);25 yield driver.elementById('friend');26 yield driver.elementById('tester');27 yield driver.elementById('follow4');28 done();29 });30 it("should navigate follows recursively", function* (driver, done) {31 server.get("/api/posts/tester", fixtures.home());32 server.get("/api/posts/friend", fixtures.friend());33 server.get("/api/posts/follow4", { 34 username: "follow4", 35 posts: [ { id: 1000, username: 'follow4', content: 'post1000' }]36 });37 server.get("/api/follows/friend", fixtures.friendFollows());38 server.get("/api/follows/tester", fixtures.myFollows());39 server.get("/api/follows/follow4", { username: "follow4", follows: [ { id: 123, username: 'tester' }] });40 yield bootstrap().login().launch(driver);41 yield driver.elementById("Dashboard");42 yield driver.elementById("post1"); // my post43 // yield driver.sleep(90000000);44 yield driver.elementById("segFollows_tester").click(); // open my follows45 yield driver.elementById('friend').click(); // click on friend46 yield driver.elementById("friend"); // friend's list47 yield driver.elementById("post4"); // friend's post48 yield driver.elementById("segFollows_friend").click(); // open friend's follows49 yield driver.elementById('follow4').click(); // click on other50 yield driver.elementById("follow4"); // other's list51 yield driver.elementById("post100"); // other's post52 yield driver.elementById("segFollows_follow4").click(); // open other's follows53 yield driver.elementById('tester').click(); // click on me54 // TODO: it should NOT say "Dashboard" 55 yield driver.elementById("tester"); // my list56 yield driver.elementById("post1"); // my post57 // Now pop everything58 yield driver.elementById("back").click(); // back59 yield driver.elementById("follow4");60 yield driver.elementById("back").click(); // back61 yield driver.elementById("friend");62 yield driver.elementById("back").click(); // back63 yield driver.elementById("Dashboard");64 done();65 });...
posts.test.js
Source:posts.test.js
...6 it("should show my posts", function* (driver, done) {7 server.get("/api/posts/tester", fixtures.home());8 yield bootstrap().login().nav("dashboard").launch(driver);9 10 yield driver.elementById('Dashboard');11 yield driver.elementById('post1');12 done();13 });14 it("should show an empty list", function* (driver, done) {15 server.get("/api/posts/tester", { username: "tester", posts: [] });16 yield bootstrap().login().nav("dashboard").launch(driver);17 yield driver.elementById('Dashboard');18 yield driver.elementById('No items');19 done();20 });21 it("should my friends's posts", function* (driver, done) {22 server.get("/api/posts/friend", fixtures.friend());23 yield bootstrap().login().nav("dashboard/follows/friend").launch(driver);24 yield driver.elementById('friend');25 yield driver.elementById('post3');26 done();27 });28 it("should create a new post", function* (driver, done) {29 var list = fixtures.home();30 server.get("/api/posts/tester", list);31 server.post("/api/posts",32 {id: 100, content: 'new post here', username: 'tester'}, // return this content33 {content: 'new post here'} // expect this content34 );35 yield bootstrap().login().launch(driver);36 yield driver.elementById('+').click(); // new post!37 yield driver.elementById('New Post');38 yield driver.execute("target.frontMostApp().keyboard().typeString('new post here')");39 yield driver.elementById('Submit').click();40 yield driver.elementById('Dashboard');41 yield driver.elementById('new post here'); // it's there!42 done();43 });...
login.test.js
Source:login.test.js
...3 */4import it from '../helpers/appium';5describe("Authentication", () => {6 it("should sign up the user, show dashboard, logout", function* (driver, done) {7 yield driver.elementById("indexRegister");8 yield driver.elementById("indexLogin").click();9 yield driver.elementById('userName').sendKeys("15088655203");10 yield driver.elementById('password').sendKeys("wxy1313");11 yield driver.elementById('smsCaptcha').sendKeys("1111");12 yield driver.elementById('getToken').click();13 //yield driver.elementById('getToken').click();14 yield driver.elementById('doLogin').click();15 yield driver.elementById('shopPhoto').click();16 yield driver.elementById('logout').click();17 yield driver.elementById("indexLogin");18 yield driver.elementById("indexRegister");19 done();20 });21 it("register new user", function* (driver, done) {22 yield driver.elementById("indexRegister").click();23 yield driver.elementById('enter_phone').sendKeys("15088651200");24 yield driver.elementById('next').click();25 yield driver.elementById('next').click();26 yield driver.elementById('enterMSCode').sendKeys("1111");27 yield driver.elementById('next').click();28 yield driver.elementById('enterName').sendKeys("test name");29 yield driver.elementById('setSex').click();30 yield driver.elementById('确认').click();31 yield driver.elementById('enterPassword').sendKeys("wxy1111");32 yield driver.elementById('repeatPassword').sendKeys("wxy1111");33 yield driver.elementById('submit').click();34 yield driver.resetApp();35 done();36 });...
authentication.test.js
Source:authentication.test.js
...7 });8 it("should sign up the user and show dashboard", function* (driver, done) {9 server.post("api/signup", fixtures.signup());10 11 var username = yield driver.elementById('Username');12 var password = yield driver.elementById('Password');13 var button = yield driver.elementById('Sign up');14 yield username.setImmediateValue("tester");15 yield password.setImmediateValue("sample");16 yield button.click();17 // make sure logged in18 yield driver.elementById('Dashboard');19 yield driver.elementById('post1');20 done();21 });22 it("should log in and out", function* (driver, done) {23 server.post("api/login", fixtures.signup());24 yield driver.elementById('Already a user? Login here.').click();25 26 var username = yield driver.elementById('Username');27 var password = yield driver.elementById('Password');28 var button = yield driver.elementById('Log in');29 yield username.setImmediateValue("tester");30 yield password.setImmediateValue("sample");31 yield button.click();32 // make sure logged in33 yield driver.elementById('Dashboard');34 yield driver.elementById('post1');35 // show settings, log out36 yield driver.elementByXPath('//UIAApplication[1]/UIAWindow[1]/UIAElement[4]').click(); // "Me"37 yield driver.elementById('Settings');38 yield driver.elementById('Log out').click();39 // back on signup40 yield driver.elementById('Already a user? Login here.');41 done();42 });...
main.test.js
Source:main.test.js
...3 */4import it from '../helpers/appium';5describe("Main page", () => {6 it("show webView of material page", function* (driver, done) {7 yield driver.elementById("indexLogin").click();8 yield driver.elementById('userName').sendKeys("15088655203");9 yield driver.elementById('password').sendKeys("wxy1313");10 yield driver.elementById('smsCaptcha').sendKeys("1111");11 yield driver.elementById('getToken').click();12 yield driver.elementById('doLogin').click();13 yield driver.elementById('è´ä¹°ç©æ').click();14 yield driver.elementById('ç©æå表');15 yield driver.elementById('å
³é').click();16 yield driver.elementById('è´ä¹°ç©æ');17 done();18 });19 it("show setting page", function* (driver, done) {20 yield driver.elementById('设置').click();21 yield driver.elementById('设置');22 done();23 });...
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .elementById('someID')9 .then(function(el) {10 console.log(el);11 })12 .end();13var webdriverio = require('webdriverio');14var options = {15 desiredCapabilities: {16 }17};18var client = webdriverio.remote(options);19 .init()20 .elementByAccessibilityId('someAccessibilityID')21 .then(function(el) {22 console.log(el);23 })24 .end();25var webdriverio = require('webdriverio');26var options = {27 desiredCapabilities: {28 }29};30var client = webdriverio.remote(options);31 .init()
Using AI Code Generation
1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6var client = webdriverio.remote(options);7 .init()8 .waitForExist('#lst-ib', 10000)9 .elementById('lst-ib')10 .setValue('Hello World')11 .elementById('lst-ib')12 .getValue().then(function(value) {13 console.log(value);14 })15 .end();
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const assert = chai.assert;5const expect = chai.expect;6const should = chai.should();7chai.use(chaiAsPromised);8const desiredCaps = {9};10describe('My First Test', () => {11 before(async () => {12 await driver.init(desiredCaps);13 });14 it('should find an element', async () => {15 await driver.elementById('myButton').click();16 });17 after(async () => {18 await driver.quit();19 });20});21{22 "scripts": {23 },24 "dependencies": {25 }26}27{28 "dependencies": {29 "appium-base-driver": {
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5 .init(desiredCaps)6 .elementById('XXXXX')7 .then(function(el) {8 console.log('element found');9 })10 .fin(function() {11 return driver.quit();12 })13 .done();14 .init(desiredCaps)15 .source()16 .then(function(source) {17 console.log(source);18 })19 .fin(function() {20 return driver.quit();21 })22 .done();23 .init(desiredCaps)24 .then(function(el) {25 console.log('element found');26 })27 .fin(function() {28 return driver.quit();29 })30 .done();31[debug] [JSONWP Proxy] Got response with status 200: {"value":{"ELEMENT":"0.0.0"},"sessionId":"0F5C6B8F-7A1D-4B6A-8A00-AB2E3D3A3C8F","status":0}32[debug] [MJSONWP] Responding to client with driver.execute() result: {"ELEMENT":"0.0.0"}
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.elementById('button').click();7driver.quit();8 at Object.wrappedLogger.errorAndThrow (lib/logger.js:60:13)9 at IOS.start$ (lib/driver.js:261:9)10 at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)11 at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)12 at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)13 at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regen
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var desired = {4};5var browser = wd.promiseChainRemote('localhost', 4723);6 .init(desired)7 .elementById('lst-ib')8 .type('Appium')9 .elementById('lst-ib')10 .getAttribute('value')11 .then(function(text) {12 assert.equal(text, 'Appium');13 })14 .fin(function() { return browser.quit(); })15 .done();16var wd = require('wd');17var assert = require('assert');18var desired = {19};20var browser = wd.promiseChainRemote('localhost', 4723);21 .init(desired)22 .elementByAccessibilityId('Search')23 .type('Appium')24 .elementByAccessibilityId('Search')25 .getAttribute('value')26 .then(function(text) {27 assert.equal(text, 'Appium');28 })29 .fin(function() { return browser.quit(); })30 .done();31var wd = require('wd');32var assert = require('assert');33var desired = {34};35var browser = wd.promiseChainRemote('localhost', 4723);36 .init(desired)37 .type('Appium')
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var path = require('path');4driver.init({5 app: path.resolve(__dirname, 'UICatalog.app.zip'),6}).then(function () {7 return driver.elementById('Buttons');8}).then(function (el) {9 return el.click();10}).then(function () {11 return driver.quit();12}).done();
Using AI Code Generation
1var webdriverio = require('webdriverio');2var client = webdriverio.remote({3 desiredCapabilities: {4 }5});6client.init();7client.elementById('Buttons').then(function (elem) {8 console.log(elem);9});10client.end();11var webdriverio = require('webdriverio');12var client = webdriverio.remote({13 desiredCapabilities: {14 }15});16client.init();17client.elementByAccessibilityId('Buttons').then(function (elem) {18 console.log(elem);19});20client.end();
Using AI Code Generation
1var wd = require('wd');2var desired = {3};4var driver = wd.promiseChainRemote('localhost', 4723);5 .init(desired)6 .elementById('Done')7 .then(function(el) {8 console.log('Element found!');9 })10 .catch(function(err) {11 console.log(err);12 })13 .finally(function() {14 driver.quit();15 });16var wd = require('wd');17var desired = {18};19var driver = wd.promiseChainRemote('localhost', 4723);20 .init(desired)21 .elementByAccessibilityId('Done')22 .then(function(el) {23 console.log('Element found!');24 })25 .catch(function(err) {26 console.log(err);27 })28 .finally(function() {29 driver.quit();30 });
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!!