How to use baseDriverE2ETests method in Appium Base Driver

Best JavaScript code snippet using appium-base-driver

driver-e2e-tests.js

Source: driver-e2e-tests.js Github

copy

Full Screen

1import _ from 'lodash';2import { server, routeConfiguringFunction, DeviceSettings } from '../​..';3import request from 'request-promise';4import chai from 'chai';5import chaiAsPromised from 'chai-as-promised';6import B from 'bluebird';7const should = chai.should();8chai.use(chaiAsPromised);9function baseDriverE2ETests (DriverClass, defaultCaps = {}) {10 describe('BaseDriver (e2e)', function () {11 let baseServer, d = new DriverClass();12 before(async function () {13 baseServer = await server(routeConfiguringFunction(d), 8181);14 });15 after(async function () {16 await baseServer.close();17 });18 function startSession (caps) {19 return request({20 url: 'http:/​/​localhost:8181/​wd/​hub/​session',21 method: 'POST',22 json: {desiredCapabilities: caps, requiredCapabilities: {}},23 });24 }25 function endSession (id) {26 return request({27 url: `http:/​/​localhost:8181/​wd/​hub/​session/​${id}`,28 method: 'DELETE',29 json: true,30 simple: false31 });32 }33 function getSession (id) {34 return request({35 url: `http:/​/​localhost:8181/​wd/​hub/​session/​${id}`,36 method: 'GET',37 json: true,38 simple: false39 });40 }41 describe('session handling', function () {42 it('should create session and retrieve a session id, then delete it', async function () {43 let res = await request({44 url: 'http:/​/​localhost:8181/​wd/​hub/​session',45 method: 'POST',46 json: {desiredCapabilities: defaultCaps, requiredCapabilities: {}},47 simple: false,48 resolveWithFullResponse: true49 });50 res.statusCode.should.equal(200);51 res.body.status.should.equal(0);52 should.exist(res.body.sessionId);53 res.body.value.should.eql(defaultCaps);54 res = await request({55 url: `http:/​/​localhost:8181/​wd/​hub/​session/​${d.sessionId}`,56 method: 'DELETE',57 json: true,58 simple: false,59 resolveWithFullResponse: true60 });61 res.statusCode.should.equal(200);62 res.body.status.should.equal(0);63 should.equal(d.sessionId, null);64 });65 });66 it.skip('should throw NYI for commands not implemented', async function () {67 });68 describe('command timeouts', function () {69 function startTimeoutSession (timeout) {70 let caps = _.clone(defaultCaps);71 caps.newCommandTimeout = timeout;72 return startSession(caps);73 }74 d.findElement = function () {75 return 'foo';76 }.bind(d);77 d.findElements = async function () {78 await B.delay(200);79 return ['foo'];80 }.bind(d);81 it('should set a default commandTimeout', async function () {82 let newSession = await startTimeoutSession();83 d.newCommandTimeoutMs.should.be.above(0);84 await endSession(newSession.sessionId);85 });86 it('should timeout on commands using commandTimeout cap', async function () {87 let newSession = await startTimeoutSession(0.25);88 await request({89 url: `http:/​/​localhost:8181/​wd/​hub/​session/​${d.sessionId}/​element`,90 method: 'POST',91 json: {using: 'name', value: 'foo'},92 });93 await B.delay(400);94 let res = await request({95 url: `http:/​/​localhost:8181/​wd/​hub/​session/​${d.sessionId}`,96 method: 'GET',97 json: true,98 simple: false99 });100 res.status.should.equal(6);101 should.equal(d.sessionId, null);102 res = await endSession(newSession.sessionId);103 res.status.should.equal(6);104 });105 it('should not timeout with commandTimeout of false', async function () {106 let newSession = await startTimeoutSession(0.1);107 let start = Date.now();108 let res = await request({109 url: `http:/​/​localhost:8181/​wd/​hub/​session/​${d.sessionId}/​elements`,110 method: 'POST',111 json: {using: 'name', value: 'foo'},112 });113 (Date.now() - start).should.be.above(150);114 res.value.should.eql(['foo']);115 await endSession(newSession.sessionId);116 });117 it('should not timeout with commandTimeout of 0', async function () {118 d.newCommandTimeoutMs = 2;119 let newSession = await startTimeoutSession(0);120 await request({121 url: `http:/​/​localhost:8181/​wd/​hub/​session/​${d.sessionId}/​element`,122 method: 'POST',123 json: {using: 'name', value: 'foo'},124 });125 await B.delay(400);126 let res = await request({127 url: `http:/​/​localhost:8181/​wd/​hub/​session/​${d.sessionId}`,128 method: 'GET',129 json: true,130 simple: false131 });132 res.status.should.equal(0);133 res = await endSession(newSession.sessionId);134 res.status.should.equal(0);135 d.newCommandTimeoutMs = 60 * 1000;136 });137 it('should not timeout if its just the command taking awhile', async function () {138 let newSession = await startTimeoutSession(0.25);139 await request({140 url: `http:/​/​localhost:8181/​wd/​hub/​session/​${d.sessionId}/​element`,141 method: 'POST',142 json: {using: 'name', value: 'foo'},143 });144 await B.delay(400);145 let res = await request({146 url: `http:/​/​localhost:8181/​wd/​hub/​session/​${d.sessionId}`,147 method: 'GET',148 json: true,149 simple: false150 });151 res.status.should.equal(6);152 should.equal(d.sessionId, null);153 res = await endSession(newSession.sessionId);154 res.status.should.equal(6);155 });156 it('should not have a timer running before or after a session', async function () {157 should.not.exist(d.noCommandTimer);158 let newSession = await startTimeoutSession(0.25);159 newSession.sessionId.should.equal(d.sessionId);160 should.exist(d.noCommandTimer);161 await endSession(newSession.sessionId);162 should.not.exist(d.noCommandTimer);163 });164 });165 describe('settings api', function () {166 before(function () {167 d.settings = new DeviceSettings({ignoreUnimportantViews: false});168 });169 it('should be able to get settings object', function () {170 d.settings.getSettings().ignoreUnimportantViews.should.be.false;171 });172 it('should throw error when updateSettings method is not defined', async function () {173 await d.settings.update({ignoreUnimportantViews: true}).should.eventually174 .be.rejectedWith('onSettingsUpdate');175 });176 it('should throw error for invalid update object', async function () {177 await d.settings.update('invalid json').should.eventually178 .be.rejectedWith('JSON');179 });180 });181 describe('unexpected exits', function () {182 it('should reject a current command when the driver crashes', async function () {183 d._oldGetStatus = d.getStatus;184 d.getStatus = async function () {185 await B.delay(5000);186 }.bind(d);187 let p = request({188 url: 'http:/​/​localhost:8181/​wd/​hub/​status',189 method: 'GET',190 json: true,191 simple: false192 });193 /​/​ make sure that the request gets to the server before our shutdown194 await B.delay(100);195 d.startUnexpectedShutdown(new Error('Crashytimes'));196 let res = await p;197 res.status.should.equal(13);198 res.value.message.should.contain('Crashytimes');199 await d.onUnexpectedShutdown.should.be.rejectedWith('Crashytimes');200 });201 });202 describe('event timings', function () {203 it('should not add timings if not using opt-in cap', async function () {204 let session = await startSession(defaultCaps);205 let res = await getSession(session.sessionId);206 should.not.exist(res.events);207 await endSession(session.sessionId);208 });209 it('should add start session timings', async function () {210 let caps = Object.assign({}, defaultCaps, {eventTimings: true});211 let session = await startSession(caps);212 let res = (await getSession(session.sessionId)).value;213 should.exist(res.events);214 should.exist(res.events.newSessionRequested);215 should.exist(res.events.newSessionStarted);216 res.events.newSessionRequested[0].should.be.a('number');217 res.events.newSessionStarted[0].should.be.a('number');218 await endSession(session.sessionId);219 });220 });221 });222}...

Full Screen

Full Screen

driver-e2e-specs.js

Source: driver-e2e-specs.js Github

copy

Full Screen

1/​/​ transpile:mocha2import BaseDriver from '../​..';3import baseDriverE2ETests from './​driver-e2e-tests';4baseDriverE2ETests(BaseDriver, {5 platformName: 'iOS',6 deviceName: 'Delorean'...

Full Screen

Full Screen

index.js

Source: index.js Github

copy

Full Screen

1/​/​ transpile:main2import baseDriverUnitTests from './​driver-tests';3import baseDriverE2ETests from './​driver-e2e-tests';...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { baseDriverE2ETests } from 'appium-base-driver/​build/​lib/​tester';2import { baseDriverUnitTests } from 'appium-base-driver/​build/​lib/​tester';3baseDriverE2ETests({4 driverArgs: {},5 skipTests: {6 },7 onlyTests: {8 },9 beforeSession: async (caps, driver) => {10 await driver.start();11 },12 afterSession: async (driver) => {13 await driver.stop();14 },

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

New Year Resolutions Of Every Website Tester In 2020

Were you able to work upon your resolutions for 2019? I may sound comical here but my 2019 resolution being a web developer was to take a leap into web testing in my free time. Why? So I could understand the release cycles from a tester’s perspective. I wanted to wear their shoes and see the SDLC from their eyes. I also thought that it would help me groom myself better as an all-round IT professional.

Getting Started with SpecFlow Actions [SpecFlow Automation Tutorial]

With the rise of Agile, teams have been trying to minimize the gap between the stakeholders and the development team.

How To Identify Locators In Appium [With Examples]

Nowadays, automation is becoming integral to the overall quality of the products being developed. Especially for mobile applications, it’s even more important to implement automation robustly.

How To Test React Native Apps On iOS And Android

As everyone knows, the mobile industry has taken over the world and is the fastest emerging industry in terms of technology and business. It is possible to do all the tasks using a mobile phone, for which earlier we had to use a computer. According to Statista, in 2021, smartphone vendors sold around 1.43 billion smartphones worldwide. The smartphone penetration rate has been continuously rising, reaching 78.05 percent in 2020. By 2025, it is expected that almost 87 percent of all mobile users in the United States will own a smartphone.

Automation Testing Tutorial: A Starter’s Guide With Example

Software testing is an integral part of any IT project. Testing the software more and more will ensure a better quality of your software. Now, how do you achieve it? Either you go with Manual Testing or Automation Testing.

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 Base Driver 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