How to use wd.promiseChainRemote method in Appium

Best JavaScript code snippet using appium

index.test.js

Source:index.test.js Github

copy

Full Screen

1import wd from 'wd';2import sauceConnect from 'sauce-connect-launcher';3import SauceConnector from '../lib';4jest.mock('wd');5jest.mock('sauce-connect-launcher');6class BrowserMock {7 constructor (args) {8 this.args = args;9 this.opts = null;10 this.url = '';11 this.subscribedEvents = [];12 }13 once (event) {14 this.subscribedEvents.push(event);15 }16 init (opts) {17 this.opts = opts;18 return this;19 }20 get (url) {21 this.url = url;22 return Promise.resolve();23 }24}25test('Should handle custom options', async () => {26 let connectorOptions = null;27 jest.spyOn(Date, 'now').mockImplementationOnce(() => Date.UTC(2007, 1, 1));28 wd.promiseChainRemote.mockImplementationOnce((...args) => new BrowserMock(args));29 sauceConnect.mockImplementationOnce((opts, cb) => {30 connectorOptions = opts;31 cb(null , {});32 });33 const sauceConnector = new SauceConnector('user', 'pass', {34 verbose: false,35 verboseDebugging: false,36 vv: false37 });38 expect(sauceConnector.options.connectorLogging).toEqual(true);39 expect(sauceConnector.options.createTunnel).toEqual(true);40 await sauceConnector.connect();41 expect(connectorOptions.username).toEqual('user');42 expect(connectorOptions.accessKey).toEqual('pass');43 expect(connectorOptions.tunnelIdentifier).toEqual(Date.UTC(2007, 1, 1));44 expect(connectorOptions.logfile).toEqual(null);45 expect(connectorOptions.directDomains).toEqual('*.google.com,*.gstatic.com,*.googleapis.com');46 expect(connectorOptions.verbose).toEqual(false);47 expect(connectorOptions.verboseDebugging).toEqual(false);48 expect(connectorOptions.vv).toEqual(false);49 const browser = await sauceConnector.startBrowser(50 { browserName: 'chrome' },51 'http://example.com',52 { jobName: 'job-name' },53 424254 );55 expect(browser).toBeInstanceOf(BrowserMock);56 expect(browser.args).toEqual(['ondemand.saucelabs.com', 80, 'user', 'pass']);57 expect(browser.subscribedEvents).toEqual(['status']);58 expect(browser.url).toEqual('http://example.com');59 expect(browser.opts.browserName).toEqual('chrome');60 expect(browser.opts.name).toEqual('job-name');61 expect(browser.opts.tunnelIdentifier).toEqual(Date.UTC(2007, 1, 1));62 expect(browser.opts.idleTimeout).toEqual(1000);63 expect(browser.opts.maxDuration).toEqual(4242);64});65test('Should not create a tunnel if createTunnel is false', async () => {66 let connectorOptions = null;67 jest.spyOn(Date, 'now').mockImplementationOnce(() => Date.UTC(2007, 1, 1));68 sauceConnect.mockImplementationOnce((opts, cb) => {69 connectorOptions = opts;70 cb(null, {});71 });72 wd.promiseChainRemote.mockImplementationOnce((...args) => new BrowserMock(args));73 const sauceConnector = new SauceConnector('user', 'pass', {74 createTunnel: false75 });76 expect(sauceConnector.options.createTunnel).toEqual(false);77 expect(sauceConnector.sauceConnectOptions).toEqual(null);78 await sauceConnector.connect();79 expect(sauceConnector.sauceConnectProcess).toEqual(null);80 expect(connectorOptions).toEqual(null);81 const browser = await sauceConnector.startBrowser(82 { browserName: 'chrome' },83 'http://example.com',84 { jobName: 'job-name' },85 424286 );87 expect(browser.opts).not.toHaveProperty('tunnelIdentifier');88 await sauceConnector.disconnect();89});90test('Should allow using external tunnel', async () => {91 let connectorOptions = null;92 jest.spyOn(Date, 'now').mockImplementationOnce(() => Date.UTC(2007, 1, 1));93 sauceConnect.mockImplementationOnce((opts, cb) => {94 connectorOptions = opts;95 cb(null, {});96 });97 wd.promiseChainRemote.mockImplementationOnce((...args) => new BrowserMock(args));98 const sauceConnector = new SauceConnector('user', 'pass', {99 createTunnel: false,100 tunnelIdentifier: 'ABRACADABRA'101 });102 expect(sauceConnector.options.createTunnel).toEqual(false);103 expect(sauceConnector.sauceConnectOptions).toEqual(null);104 await sauceConnector.connect();105 expect(sauceConnector.sauceConnectProcess).toEqual(null);106 expect(connectorOptions).toEqual(null);107 const browser = await sauceConnector.startBrowser(108 { browserName: 'chrome' },109 'http://example.com',110 { jobName: 'job-name' },111 4242112 );113 expect(browser.opts.tunnelIdentifier).toEqual('ABRACADABRA');114 await sauceConnector.disconnect();...

Full Screen

Full Screen

worker.js

Source:worker.js Github

copy

Full Screen

...39// ---------------------------------------------------------------------------40global.config = config;41switch (service) {42 case 'browserstack':43 global.browser = wd.promiseChainRemote(44 config[service].selenium.host,45 config[service].selenium.port46 );47 break;48 case 'saucelabs':49 global.browser = wd.promiseChainRemote(50 config[service].selenium.host,51 config[service].selenium.port,52 config[service].user,53 config[service].key54 );55 break;56 case 'testingbot':57 global.browser = wd.promiseChainRemote(58 config[service].selenium.host,59 config[service].selenium.port,60 config[service].key,61 config[service].secret62 );63 break;64 default:65 throw new Error('Invalid service: ' + service);66}67// ---------------------------------------------------------------------------68// Get on with the testing.69// ---------------------------------------------------------------------------70var mocha = new Mocha(config.mocha);71// Expand the glob path specifications into paths and add them to Mocha....

Full Screen

Full Screen

driver-e2e-specs.js

Source:driver-e2e-specs.js Github

copy

Full Screen

...24 }25 });26 describe('session handling', () => {27 it('should start and stop a session', async () => {28 let driver = wd.promiseChainRemote(TEST_HOST, TEST_PORT);29 let [sessionId] = await driver.init(caps);30 should.exist(sessionId);31 sessionId.should.be.a('string');32 await driver.quit();33 await driver.title().should.eventually.be.rejectedWith(/terminated/);34 });35 it('should be able to run two FakeDriver sessions simultaneously', async () => {36 let driver1 = wd.promiseChainRemote(TEST_HOST, TEST_PORT);37 let [sessionId1] = await driver1.init(caps);38 should.exist(sessionId1);39 sessionId1.should.be.a('string');40 let driver2 = wd.promiseChainRemote(TEST_HOST, TEST_PORT);41 let [sessionId2] = await driver2.init(caps);42 should.exist(sessionId2);43 sessionId2.should.be.a('string');44 sessionId1.should.not.equal(sessionId2);45 await driver1.quit();46 await driver2.quit();47 });48 it('should not be able to run two FakeDriver sessions simultaneously when one is unique', async () => {49 let uniqueCaps = _.clone(caps);50 uniqueCaps.uniqueApp = true;51 let driver1 = wd.promiseChainRemote(TEST_HOST, TEST_PORT);52 let [sessionId1] = await driver1.init(uniqueCaps);53 should.exist(sessionId1);54 sessionId1.should.be.a('string');55 let driver2 = wd.promiseChainRemote(TEST_HOST, TEST_PORT);56 await driver2.init(caps).should.eventually.be.rejected;57 await driver1.quit();58 });59 it('should use the newCommandTimeout of the inner Driver on session creation', async () => {60 let driver = wd.promiseChainRemote(TEST_HOST, TEST_PORT);61 caps.newCommandTimeout = 0.25;62 let [sessionId] = await driver.init(caps);63 should.exist(sessionId);64 await B.delay(250);65 await driver.source().should.eventually.be.rejectedWith(/terminated/);66 });67 });68});69describe('Logsink', () => {70 let server = null;71 let logs = [];72 let logHandler = (level, message) => {73 logs.push([level, message]);74 };...

Full Screen

Full Screen

test-init.js

Source:test-init.js Github

copy

Full Screen

...41 function startSelenium (callback) {42 request(SELENIUM_HUB, function (error, resp) {43 if (error) throw error44 if (resp && resp.statusCode === 200) {45 self.browser = wd.promiseChainRemote()46 callback()47 } else {48 console.log('.')49 setTimeout(started, 1000)50 }51 })52 }53 function startSauceConnect (callback) {54 console.log('connecting to saucelabs')55 var options = {56 username: username,57 accessKey: accessKey,58 tunnelIdentifier: tunnelId59 }60 sauceConnectLauncher(options, function (err, process) {61 if (err) {62 console.error('Failed to connect to saucelabs')63 console.error(err)64 return process.exit(1)65 }66 self.browser = wd.promiseChainRemote('localhost', 4445, username, accessKey)67 callback()68 })69 }70 function startTest () {71 // optional extra logging72 self.browser.on('status', function (info) {73 console.log(info.cyan)74 })75 self.browser.on('command', function (eventType, command, response) {76 if (eventType === 'RESPONSE') {77 return console.log(' <', (response || 'ok').grey)78 }79 console.log(' > ' + eventType.cyan, command)80 })...

Full Screen

Full Screen

tutorial-specs.js

Source:tutorial-specs.js Github

copy

Full Screen

...29 var allPassed = true;30 before(function (done) {31 var username = process.env.SAUCE_USERNAME;32 var accessKey = process.env.SAUCE_ACCESS_KEY;33 browser = wd.promiseChainRemote("ondemand.saucelabs.com", 80, username, accessKey);34 /* webdriver-manager start */35 //browser = wd.promiseChainRemote("localhost", 4444, username, accessKey);36 if (process.env.VERBOSE) {37 // optional logging38 browser.on('status', function (info) {39 console.log(info.cyan);40 });41 browser.on('command', function (meth, path, data) {42 console.log(' > ' + meth.yellow, path.grey, data || '');43 });44 }45 browser46 .init(desired)47 .nodeify(done);48 });49 afterEach(function (done) {...

Full Screen

Full Screen

myTests.test.js

Source:myTests.test.js Github

copy

Full Screen

...11 platformVersion: "8.1",12 //app: '/Users/vetal04075/job/react-native/AppiumDemo/android/app/build/outputs/apk/debug/app-debug.apk'13 app: 'storage:filename=demoAppiumRelease.apk'14};15const driver = wd.promiseChainRemote('https://vetal04075:0053aaad15cf42849a26663483054553@ondemand.eu-central-1.saucelabs.com:443/wd/hub', PORT);*/16//const driver = wd.promiseChainRemote('localhost', PORT);17/*beforeAll(async () => {18 await driver.init(config);19 await driver.sleep(10000);20}) // Sometime for the app to load*/21/*test('appium renders', async () => {22 expect(await driver.hasElementByAccessibilityId('alertButton')).toBe(true);23 const element = await driver.elementByAccessibilityId('alertButton')24 await element.click()25 expect(await driver.hasElementByAccessibilityId('notHere')).toBe(false);26 await driver.quit();27});*/28describe('Setup screen', () => {29 it('Move to login screen', () => {30 $("~alertButton").click();...

Full Screen

Full Screen

init.js

Source:init.js Github

copy

Full Screen

...8require("../function/promise-chain") //添加自定义方法9require('../function/setenv') //配置环境变量10require('./setup') //加载依赖环境11function Driver() {12 driver = wd.promiseChainRemote(require("../server/appium-servers").local)13 require("../server/logging").configure(driver) //打印日志14 return driver15}16global.driver = new Driver //实例化一个对象17global.driver_clone = wd.promiseChainRemote(require("../server/appium-servers").remote)18var APP_LOCALATION = process.env['app_install_location']19if (!fs.existsSync(APP_LOCALATION)){20 console.log('临时变量存在问题,请检查'.yellow)21 process.exit(0)22}...

Full Screen

Full Screen

run.appium.spec.js

Source:run.appium.spec.js Github

copy

Full Screen

...5jasmine.DEFAULT_TIMEOUT_INTERVAL = 600000;6let config = process.env.TESTING_OS === 'ios' ? e2eiOSConfig : e2eAndroidConfig;7let platform = process.env.TESTING_OS || 'android';8const driver = process.env.BROWSERSTACK_APP_URL9 ? wd.promiseChainRemote('http://hub-cloud.browserstack.com/wd/hub')10 : wd.promiseChainRemote('localhost', PORT);11beforeAll(async () => {12 await driver.init(config());13});14afterAll(async () => {15 await driver.sleep(5000);16 await driver.quit();17});18describe('Logged user context', () => {19 CheckElement(driver, platform);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var asserters = wd.asserters;3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var should = chai.should();7var expect = chai.expect;8var driver = wd.promiseChainRemote({9});10var wd = require('wd');11var asserters = wd.asserters;12var chai = require('chai');13var chaiAsPromised = require('chai-as-promised');14chai.use(chaiAsPromised);15var should = chai.should();16var expect = chai.expect;17var driver = wd.promiseChainRemote({18});19var wd = require('wd');20var asserters = wd.asserters;21var chai = require('chai');22var chaiAsPromised = require('chai-as-promised');23chai.use(chaiAsPromised);24var should = chai.should();25var expect = chai.expect;26var driver = wd.promiseChainRemote({27});28var wd = require('wd');29var asserters = wd.asserters;30var chai = require('chai');31var chaiAsPromised = require('chai-as-promised');32chai.use(chaiAsPromised);33var should = chai.should();34var expect = chai.expect;35var driver = wd.promiseChainRemote({36});37var wd = require('wd');38var asserters = wd.asserters;39var chai = require('chai');40var chaiAsPromised = require('chai-as-promised');41chai.use(chaiAsPromised);42var should = chai.should();43var expect = chai.expect;44var driver = wd.promiseChainRemote({45});46var wd = require('wd');47var asserters = wd.asserters;48var chai = require('chai');49var chaiAsPromised = require('chai-as-promised');50chai.use(chaiAsPromised);51var should = chai.should();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var expect = chai.expect;7chai.should();8var desired = {9};10var driver = wd.promiseChainRemote("localhost", 4723);11driver.init(desired);12 .click()13 .elementById("id of an element")14 .click()15 .elementById("id of another element")16 .click()17 .click()18 .elementById("id of an element")19 .click()20 .elementById("id of another element")21 .click()22 .quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require("wd");2var assert = require("assert");3var desired = {4};5var browser = wd.promiseChainRemote("ondemand.saucelabs.com", 80, "sauceUserName", "sauceAccessKey");6 .init(desired)7 .then(function () {8 })9 .then(function (el) {10 return el.text();11 })12 .then(function (text) {13 assert.ok(text === "Hello, World!");14 })15 .fin(function () {16 return browser.quit();17 })18 .done();19var wd = require("wd");20var assert = require("assert");21var desired = {22};23var browser = wd.promiseChainRemote("ondemand.saucelabs.com", 80, "sauceUserName", "sauceAccessKey");24 .init(desired)25 .then(function () {26 })27 .then(function (el) {28 return el.text();29 })30 .then(function (text) {31 assert.ok(text === "Hello, World!");32 })33 .fin(function () {34 return browser.quit();35 })36 .done();37var wd = require("wd");38var assert = require("assert");39var desired = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desiredCaps = {4};5 .init(desiredCaps)6 .then(function() {7 return driver.elementByAccessibilityId('buttonTest');8 })9 .then(function(el) {10 return el.click();11 })12 .then(function() {13 return driver.elementByAccessibilityId('showToast');14 })15 .then(function(el) {16 return el.click();17 })18 .then(function() {19 return driver.waitForElementByAccessibilityId('showToast', 5000);20 })21 .then(function(el) {22 return el.text();23 })24 .then(function(text) {25 assert.equal(text, 'Show toast');26 })27 .fin(function() { return driver.quit(); })28 .done();29 throw err;30at Object.exports.loadDriver (C:\Users\Public\Documents\test31at Appium.start (C:\Users\Public\Documents\test32at Appium.main (C:\Users\Public\Documents\test33at Object. (C:\Users\Public\Documents\test

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = {4};5browser.init(desired).then(function(){6}).then(function(){7 return browser.elementById('lst-ib');8}).then(function(el){9 return el.sendKeys("Appium");10}).then(function(){11 return browser.elementByCss('#tsf > div.tsf-p > div.jsb > center > input[type="submit"]:nth-child(1)');12}).then(function(el){13 return el.click();14}).then(function(){15 return browser.title();16}).then(function(title){17 assert.ok(title.indexOf('Appium') !== -1);18}).fin(function() { return browser.quit(); })19.done();20var wd = require('wd');21var assert = require('assert');22var desired = {23};24browser.init(desired, function(){25 browser.elementById('lst-ib', function(err, el){26 el.sendKeys("Appium", function(){27 browser.elementByCss('#tsf > div.tsf-p > div.jsb > center > input[type="submit"]:nth-child(1)', function(err, el){28 el.click(function(){29 browser.title(function(err, title){30 assert.ok(title.indexOf('Appium') !== -1);31 browser.quit();32 });33 });34 });35 });36 });37 });38});39var wd = require('wd');40var assert = require('assert');41var desired = {42};43browser.init(desired, function(){44 browser.elementById('lst-ib', function(err, el){45 el.sendKeys("Appium", function(){46 browser.elementByCss('#tsf > div.tsf-p > div.jsb > center > input[type="submit"]:nth-child(1)', function(err, el){47 el.click(function(){

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var asserters = wd.asserters;3var browser = wd.promiseChainRemote();4var desired = {5};6 .init(desired)7 .setImplicitWaitTimeout(5000)8 .elementByCss('input[name="q"]')9 .sendKeys('Hello World')10 .elementByCss('button[name="btnG"]').click()11 .waitForElementByCss('div.srg div.g', asserters.isDisplayed, 10000)12 .text().should.become('Hello World - Google Search')13 .quit();14var wd = require('node_modules/wd');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var asserters = wd.asserters;3var browser = wd.promiseChainRemote('localhost', 4723);4var desired = {5 chromeOptions: {6 }7};8 .init(desired)9 .title()10 .then(function(title) {11 console.log(title);12 })13 .quit();14[HTTP] {"desiredCapabilities":{"browserName":"chrome","chromeOptions":{"androidPackage":"com.android.chrome"}}}15[MJSONWP] Calling AppiumDriver.createSession() with args: [{"browserName":"chrome","chromeOptions":{"androidPackage":"com.android.chrome"}},null,null]16[BaseDriver] Event 'newSessionRequested' logged at 1499424704999 (14:18:24 GMT+0530 (IST))17[Appium] Creating new AndroidDriver (v1.23.0) session18[Appium] chromeOptions: { androidPackage: 'com.android.chrome' }19[AndroidDriver] Connected devices: [{"udid":"emulator-5554","state":"device"}]

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