How to use driver2.init method in Appium

Best JavaScript code snippet using appium

test.js

Source:test.js Github

copy

Full Screen

1var expect = chai.expect;2var should = chai.should();3var webdriverjs = require('webdriverjs');4describe('E2E selenium tests', function() {5 this.timeout(90000);6 var options = {7 desiredCapabilities: {8 browserName: 'firefox'9 }10 };11 var browserA,browserB;12 13 function startCheckpoint(numbersOfBrowsers, doneCallback){14 return {15 finish: function(){ if(--numbersOfBrowsers <= 0){ doneCallback() } }16 }17 }18 19 function drag(browser, element, x, y, offsetX, offsetY, times, callback){20 var val = browser.moveTo(element,x,y).buttonDown(0)21 var xstep = Math.floor(offsetX/times)22 var ystep = Math.floor(offsetY/times)23 24 for(var i = 0; i < times; i++) {25 val = val.moveTo(null,xstep,ystep)26 }27 val.moveTo(null,offsetX - xstep * times,offsetY - ystep * times).buttonUp(callback)28 }29 30 var dragElBy = function(element,offsetX,offsetY, cb){31 this.element(element,function(err,result){32 var times = 5;33 var val = this.moveTo(result.value.ELEMENT,5,5).buttonDown()34 var xstep = Math.floor(offsetX/times)35 var ystep = Math.floor(offsetY/times)36 for(var i = 0; i < times; i++) {37 val = val.moveTo(null,xstep,ystep)38 }39 val.buttonUp(cb)40 })41 }42 43 before(function(done){ 44 var checkpoint = startCheckpoint(2,done)45 var driver1 = webdriverjs.remote(options);46 driver1.addCommand("dragBy", dragElBy)47 browserA = driver148 .init()49 .url('http://localhost:1337/')50 .windowHandleMaximize(function(){checkpoint.finish()});51 52 var driver2 = webdriverjs.remote(options);53 driver2.addCommand("dragBy", dragElBy)54 browserB = driver255 .init()56 .url('http://localhost:1337/')57 .windowHandleMaximize(function(){checkpoint.finish()});58 })59 it('should register and fail', function(done) {60 var checkpoint = startCheckpoint(1,done)61 62 browserA63 .setValue("input.signup-name", "Mieister Hendrich")64 .setValue("input.signup-email", "invalidEmail")65 .setValue("input.signup-password", "nininini")66 .setValue("input.signup-confirmation", "nininini")67 .click('input.signup-submit')68 .getText('.alert li', function(err,text){69 text.should.equal("invalid email, bro")70 })71 .setValue("input.signup-name", "Mieister Hendrich")72 .setValue("input.signup-email", "mieister@hendrich.com")73 .setValue("input.signup-password", "nininini")74 .setValue("input.signup-confirmation", "nininini")75 .click('input.signup-submit')76 .url(function(err, url){77 expect(url.value).to.contain("/user/show/");78 })79 .click('.logout-button',function(){checkpoint.finish()});80 81 //browserB82 // .url('http://localhost:1337/')83 // .setValue("input.login-user","user@user.fe.up.pt")84 // .setValue("input.login-password","teste123")85 // .click('button.login-submit')86 // .click('//td[text() = "project miel picante"]/following-sibling::td/a[text() = "Join"]')87 // .waitFor('.file-component.component', function(err){checkpoint.finish(err)})88 });89 90 91 it('should login two users and join the same project', function(done) {92 var checkpoint = startCheckpoint(2,done)93 94 browserA95 .setValue("input.login-user","admin@admin.pt")96 .setValue("input.login-password","admin123")97 .click('button.login-submit')98 .click('//td[text() = "project miel picante"]/following-sibling::td/a[text() = "Join"]')99 .waitFor('.command-component.component', function(){checkpoint.finish()})100 101 browserB102 .setValue("input.login-user","user@user.fe.up.pt")103 .setValue("input.login-password","teste123")104 .click('button.login-submit')105 .click('//td[text() = "project miel picante"]/following-sibling::td/a[text() = "Join"]')106 .waitFor('.command-component.component', function(err){checkpoint.finish(err)})107 });108 109 110 it('should collaboratively move a component', function(done) {111 var checkpoint = startCheckpoint(2,done)112 browserA113 .pause(2000)114 .waitFor('.component')115 .dragBy('.component',0,50)116 .pause(1000,function(){117 browserB118 .waitFor('.component')119 .dragBy('.component',0,-50)120 .pause(1000, function(){checkpoint.finish()})121 122 })123 124 //.element('.file-component',function(err,result) {125 // drag(browserA,result.value.ELEMENT,20,20,0,50,15, function(){126 // //browserA.wait()127 // drag(browserA,result.value.ELEMENT,20,20,0,-50,15, function(){checkpoint.finish()})128 // }) 129 //})130 131 setTimeout(function(){checkpoint.finish()},1000);132 });133 134 after(function(){135 browserA.end();136 browserB.end();137 })138 139 140 141 142/* browser.getAllWindowHandles().then(function (handles) {143 // handle of first window144 var originalHandle = handles[0];145 // open new window146 browser.executeScript('window.open("https://angularjs.org/", "second-window")');147 // switch to new window148 browser.switchTo().window('second-window');149 // do something within context of new window150 // switch to original window151 browser.switchTo().window(originalHandle);152 // do something within context of original window153 // closes the current window154 browser.executeScript('window.close()');155});*/...

Full Screen

Full Screen

driver-e2e-specs.js

Source:driver-e2e-specs.js Github

copy

Full Screen

...40 let [sessionId1] = await driver1.init(caps);41 should.exist(sessionId1);42 sessionId1.should.be.a('string');43 let driver2 = wd.promiseChainRemote(TEST_HOST, TEST_PORT);44 let [sessionId2] = await driver2.init(caps);45 should.exist(sessionId2);46 sessionId2.should.be.a('string');47 sessionId1.should.not.equal(sessionId2);48 await driver1.quit();49 await driver2.quit();50 });51 it('should not be able to run two FakeDriver sessions simultaneously when one is unique', async () => {52 let uniqueCaps = _.clone(caps);53 uniqueCaps.uniqueApp = true;54 let driver1 = wd.promiseChainRemote(TEST_HOST, TEST_PORT);55 let [sessionId1] = await driver1.init(uniqueCaps);56 should.exist(sessionId1);57 sessionId1.should.be.a('string');58 let driver2 = wd.promiseChainRemote(TEST_HOST, TEST_PORT);59 await driver2.init(caps).should.eventually.be.rejected;60 await driver1.quit();61 });62 it('should use the newCommandTimeout of the inner Driver on session creation', async () => {63 let driver = wd.promiseChainRemote(TEST_HOST, TEST_PORT);64 caps.newCommandTimeout = 0.25;65 let [sessionId] = await driver.init(caps);66 should.exist(sessionId);67 await B.delay(250);68 await driver.source().should.eventually.be.rejectedWith(/terminated/);69 });70 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver2 = new AppiumDriver2();2driver2.init();3var driver2 = new AppiumDriver2();4driver2.init();5var driver2 = new AppiumDriver2();6driver2.init();7var driver2 = new AppiumDriver2();8driver2.init();9var driver2 = new AppiumDriver2();10driver2.init();11var driver2 = new AppiumDriver2();12driver2.init();13var driver2 = new AppiumDriver2();14driver2.init();15var driver2 = new AppiumDriver2();16driver2.init();17var driver2 = new AppiumDriver2();18driver2.init();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var driver2 = wd.promiseChainRemote("localhost", 4723);3driver2.init({4}).then(function() {5 console.log("Appium Driver2 initialized");6});7var wd = require('wd');8var driver = wd.remote("localhost", 4723);9driver.init({10}, function() {11 console.log("Appium Driver initialized");12});

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver2 = new AppiumDriver();2driver2.init({3});4var driver2 = new AppiumDriver();5driver2.init({6});7driver2.quit();8driver2.init({9});10Is there a way to keep the driver2.init method defined after calling driver2.quit()?11var AppiumDriver = require('appium').AppiumDriver;12var driver = new AppiumDriver();13module.exports = driver;14var driver = require('./helper');15driver.init({16});17var driver = require('./helper');18driver.init({19});20driver.quit();21driver.init({

Full Screen

Using AI Code Generation

copy

Full Screen

1const driver2 = require('driver2');2driver2.init();3driver2.click();4driver2.sendKeys();5const driver2 = require('driver2');6driver2.init();7driver2.click();8driver2.sendKeys();9const driver2 = require('driver2');10driver2.init();11driver2.click();12driver2.sendKeys();13const driver2 = require('driver2');14driver2.init();15driver2.click();16driver2.sendKeys();17const driver2 = require('driver2');18driver2.init();19driver2.click();20driver2.sendKeys();21const driver2 = require('driver2');22driver2.init();23driver2.click();24driver2.sendKeys();25const driver2 = require('driver2');26driver2.init();27driver2.click();28driver2.sendKeys();29const driver2 = require('driver2');30driver2.init();31driver2.click();32driver2.sendKeys();33const driver2 = require('driver2');34driver2.init();35driver2.click();36driver2.sendKeys();37const driver2 = require('driver2');38driver2.init();39driver2.click();40driver2.sendKeys();41const driver2 = require('driver2');42driver2.init();43driver2.click();44driver2.sendKeys();45const driver2 = require('driver2');46driver2.init();47driver2.click();48driver2.sendKeys();

Full Screen

Using AI Code Generation

copy

Full Screen

1driver2.execute("mobile: swipe", {direction: "down"});2driver2.execute("mobile: swipe", {direction: "down"});3driver2.execute("mobile: swipe", {direction: "down"});4driver2.execute("mobile: swipe", {direction: "down"});5driver2.execute("mobile: swipe", {direction: "down"});6driver2.execute("mobile: swipe", {direction: "down"});7driver2.execute("mobile: swipe

Full Screen

Using AI Code Generation

copy

Full Screen

1driver2.init(caps);2driver2.findElement(By.id("com.android.calculator2:id/digit_2")).click();3driver2.findElement(By.id("com.android.calculator2:id/digit_5")).click();4driver2.findElement(By.id("com.android.calculator2:id/plus")).click();5driver2.findElement(By.id("com.android.calculator2:id/digit_6")).click();6driver2.findElement(By.id("com.android.calculator2:id/equal")).click();7driver2.findElement(By.id("com.android.calculator2:id/result")).getText();8driver2.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1driver2.init(desiredCaps, function(err, sessionID) { 2 if (err) {3 console.log(err);4 } else {5 console.log("Appium session ID is " + sessionID);6 }7});8driver2.setImplicitWaitTimeout(30000, function(err) { 9 if (err) {10 console.log(err);11 } else {12 console.log("Implicit wait timeout set");13 }14});15driver2.findElOrEls("name", "Add Contact", false, function(err, el) { 16 if (err) {17 console.log(err);18 } else {19 console.log("Found element " + el);20 }21});22 if (err) {23 console.log(err);24 } else {25 console.log("Clicked element");26 }27});28driver2.quit(function(err) { 29 if (err) {30 console.log(err);31 } else {32 console.log("Appium session ended");33 }34});35driver3.init(desiredCaps, function(err, sessionID) { 36 if (err) {37 console.log(err);38 } else {39 console.log("Appium session ID is " + sessionID);40 }41});42driver3.setImplicitWaitTimeout(30000, function(err) { 43 if (err) {44 console.log(err);45 } else {46 console.log("Implicit wait timeout set");47 }48});49driver3.findElOrEls("name", "Add Contact", false, function(err, el) { 50 if (err) {51 console.log(err);52 } else {53 console.log("Found element " + el);54 }55});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful