Best JavaScript code snippet using appium
driver-specs.js
Source:driver-specs.js
...39 it('should call inner driver\'s createSession with desired capabilities', async function () {40 mockFakeDriver.expects("createSession")41 .once().withExactArgs(BASE_CAPS, undefined, null, [])42 .returns([SESSION_ID, BASE_CAPS]);43 await appium.createSession(BASE_CAPS);44 mockFakeDriver.verify();45 });46 it('should call inner driver\'s createSession with desired and default capabilities', async function () {47 let defaultCaps = {deviceName: 'Emulator'}48 , allCaps = _.extend(_.clone(defaultCaps), BASE_CAPS);49 appium.args.defaultCapabilities = defaultCaps;50 mockFakeDriver.expects("createSession")51 .once().withArgs(allCaps)52 .returns([SESSION_ID, allCaps]);53 await appium.createSession(BASE_CAPS);54 mockFakeDriver.verify();55 });56 it('should call inner driver\'s createSession with desired and default capabilities without overriding caps', async function () {57 // a default capability with the same key as a desired capability58 // should do nothing59 let defaultCaps = {platformName: 'Ersatz'};60 appium.args.defaultCapabilities = defaultCaps;61 mockFakeDriver.expects("createSession")62 .once().withArgs(BASE_CAPS)63 .returns([SESSION_ID, BASE_CAPS]);64 await appium.createSession(BASE_CAPS);65 mockFakeDriver.verify();66 });67 it('should kill all other sessions if sessionOverride is on', async function () {68 appium.args.sessionOverride = true;69 // mock three sessions that should be removed when the new one is created70 let fakeDrivers = [new FakeDriver(),71 new FakeDriver(),72 new FakeDriver()];73 let mockFakeDrivers = _.map(fakeDrivers, (fd) => {return sinon.mock(fd);});74 mockFakeDrivers[0].expects('deleteSession')75 .once();76 mockFakeDrivers[1].expects('deleteSession')77 .once()78 .throws('Cannot shut down Android driver; it has already shut down');79 mockFakeDrivers[2].expects('deleteSession')80 .once();81 appium.sessions['abc-123-xyz'] = fakeDrivers[0];82 appium.sessions['xyz-321-abc'] = fakeDrivers[1];83 appium.sessions['123-abc-xyz'] = fakeDrivers[2];84 let sessions = await appium.getSessions();85 sessions.should.have.length(3);86 mockFakeDriver.expects("createSession")87 .once().withExactArgs(BASE_CAPS, undefined, null, [])88 .returns([SESSION_ID, BASE_CAPS]);89 await appium.createSession(BASE_CAPS);90 sessions = await appium.getSessions();91 sessions.should.have.length(1);92 for (let mfd of mockFakeDrivers) {93 mfd.verify();94 }95 mockFakeDriver.verify();96 });97 it('should call "createSession" with W3C capabilities argument, if provided', async function () {98 mockFakeDriver.expects("createSession")99 .once().withArgs(null, undefined, W3C_CAPS)100 .returns([SESSION_ID, BASE_CAPS]);101 await appium.createSession(undefined, undefined, W3C_CAPS);102 mockFakeDriver.verify();103 });104 it('should call "createSession" with W3C capabilities argument with additional provided parameters', async function () {105 let w3cCaps = {106 ...W3C_CAPS,107 alwaysMatch: {108 ...W3C_CAPS.alwaysMatch,109 'appium:someOtherParm': 'someOtherParm',110 },111 };112 mockFakeDriver.expects("createSession")113 .once().withArgs(null, undefined, {114 alwaysMatch: {115 ...w3cCaps.alwaysMatch,116 'appium:someOtherParm': 'someOtherParm',117 },118 firstMatch: [{}],119 })120 .returns([SESSION_ID, insertAppiumPrefixes(BASE_CAPS)]);121 await appium.createSession(undefined, undefined, w3cCaps);122 mockFakeDriver.verify();123 });124 it('should call "createSession" with JSONWP capabilities if W3C has incomplete capabilities', async function () {125 let w3cCaps = {126 ...W3C_CAPS,127 alwaysMatch: {128 ...W3C_CAPS.alwaysMatch,129 'appium:someOtherParm': 'someOtherParm',130 },131 };132 let jsonwpCaps = {133 ...BASE_CAPS,134 automationName: 'Fake',135 someOtherParam: 'someOtherParam',136 };137 mockFakeDriver.expects("createSession")138 .once().withArgs(jsonwpCaps, undefined, null)139 .returns([SESSION_ID, jsonwpCaps]);140 await appium.createSession(jsonwpCaps, undefined, w3cCaps);141 mockFakeDriver.verify();142 });143 });144 describe('deleteSession', function () {145 let appium;146 let mockFakeDriver;147 beforeEach(function () {148 [appium, mockFakeDriver] = getDriverAndFakeDriver();149 });150 afterEach(function () {151 mockFakeDriver.restore();152 });153 it('should remove the session if it is found', async function () {154 let [sessionId] = (await appium.createSession(BASE_CAPS)).value;155 let sessions = await appium.getSessions();156 sessions.should.have.length(1);157 await appium.deleteSession(sessionId);158 sessions = await appium.getSessions();159 sessions.should.have.length(0);160 });161 it('should call inner driver\'s deleteSession method', async function () {162 const [sessionId] = (await appium.createSession(BASE_CAPS)).value;163 mockFakeDriver.expects("deleteSession")164 .once().withExactArgs(sessionId, [])165 .returns();166 await appium.deleteSession(sessionId);167 mockFakeDriver.verify();168 // cleanup, since we faked the delete session call169 await mockFakeDriver.object.deleteSession();170 });171 });172 describe('getSessions', function () {173 let appium;174 let sessions;175 before(function () {176 appium = new AppiumDriver({});177 });178 afterEach(async function () {179 for (let session of sessions) {180 await appium.deleteSession(session.id);181 }182 });183 it('should return an empty array of sessions', async function () {184 sessions = await appium.getSessions();185 sessions.should.be.an.array;186 sessions.should.be.empty;187 });188 it('should return sessions created', async function () {189 let session1 = (await appium.createSession(_.extend(_.clone(BASE_CAPS), {cap: 'value'}))).value;190 let session2 = (await appium.createSession(_.extend(_.clone(BASE_CAPS), {cap: 'other value'}))).value;191 sessions = await appium.getSessions();192 sessions.should.be.an.array;193 sessions.should.have.length(2);194 sessions[0].id.should.equal(session1[0]);195 sessions[0].capabilities.should.eql(session1[1]);196 sessions[1].id.should.equal(session2[0]);197 sessions[1].capabilities.should.eql(session2[1]);198 });199 });200 describe('getStatus', function () {201 let appium;202 before(function () {203 appium = new AppiumDriver({});204 });205 it('should return a status', async function () {206 let status = await appium.getStatus();207 status.build.should.exist;208 status.build.version.should.exist;209 });210 });211 describe('sessionExists', function () {212 });213 describe('attachUnexpectedShutdownHandler', function () {214 let appium215 , mockFakeDriver;216 beforeEach(function () {217 [appium, mockFakeDriver] = getDriverAndFakeDriver();218 });219 afterEach(async function () {220 await mockFakeDriver.object.deleteSession();221 mockFakeDriver.restore();222 appium.args.defaultCapabilities = {};223 });224 it('should remove session if inner driver unexpectedly exits with an error', async function () {225 let [sessionId,] = (await appium.createSession(_.clone(BASE_CAPS))).value; // eslint-disable-line comma-spacing226 _.keys(appium.sessions).should.contain(sessionId);227 appium.sessions[sessionId].unexpectedShutdownDeferred.reject(new Error("Oops"));228 // let event loop spin so rejection is handled229 await sleep(1);230 _.keys(appium.sessions).should.not.contain(sessionId);231 });232 it('should remove session if inner driver unexpectedly exits with no error', async function () {233 let [sessionId,] = (await appium.createSession(_.clone(BASE_CAPS))).value; // eslint-disable-line comma-spacing234 _.keys(appium.sessions).should.contain(sessionId);235 appium.sessions[sessionId].unexpectedShutdownDeferred.resolve();236 // let event loop spin so rejection is handled237 await sleep(1);238 _.keys(appium.sessions).should.not.contain(sessionId);239 });240 it('should not remove session if inner driver cancels unexpected exit', async function () {241 let [sessionId,] = (await appium.createSession(_.clone(BASE_CAPS))).value; // eslint-disable-line comma-spacing242 _.keys(appium.sessions).should.contain(sessionId);243 appium.sessions[sessionId].onUnexpectedShutdown.cancel();244 // let event loop spin so rejection is handled245 await sleep(1);246 _.keys(appium.sessions).should.contain(sessionId);247 });248 });249 describe('getDriverForCaps', function () {250 it('should not blow up if user does not provide platformName', function () {251 let appium = new AppiumDriver({});252 (() => { appium.getDriverForCaps({}); }).should.throw(/platformName/);253 });254 it('should get XCUITestDriver driver for automationName of XCUITest', function () {255 let appium = new AppiumDriver({});...
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var caps = {4};5var driver = wd.remote('localhost', 4723);6driver.init(caps, function(err) {7 assert.equal(err, null);8 driver.quit();9});10var wd = require('wd');11var assert = require('assert');12var caps = {13};14var driver = wd.remote('localhost', 4723);15driver.init(caps, function(err) {16 assert.equal(err, null);17 driver.quit();18});19var wd = require('wd');20var assert = require('assert');21var caps = {22};23var driver = wd.remote('localhost', 4723);24driver.init(caps, function(err) {25 assert.equal(err, null);26 driver.quit();27});28var wd = require('wd');29var assert = require('assert');30var caps = {31};32var driver = wd.remote('localhost', 4723);33driver.init(caps, function(err) {34 assert.equal(err, null);35 driver.quit();36});
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var Appium = require('appium');4var appium = new Appium();5var desiredCapabilities = {6};7appium.createSession(desiredCapabilities, function(err, session) {8 if (err) {9 console.log(err);10 } else {11 console.log(session);12 var driver = wd.remote('
Using AI Code Generation
1var appium = require('appium');2var desiredCaps = {3};4appium.createSession(desiredCaps, function(err, session) {5 if (err) {6 console.log(err);7 } else {8 console.log(session);9 }10});
Using AI Code Generation
1var appium = require('appium');2var appiumServer = appium.startServer();3appiumServer.on('exit', function() {4 console.log('Appium exited unexpectedly');5});6appiumServer.on('error', function(err) {7 console.log('Appium failed to start: ' + err);8});9appiumServer.on('listening', function() {10 console.log('Appium server started');11 appium.createSession({12 }, function(err, sessionId) {13 if (err) {14 console.log('Error creating session: ' + err);15 appiumServer.stop();16 } else {17 console.log('Session ID: ' + sessionId);18 appiumServer.stop();19 }20 });21});22var appium = require('appium');23var appiumServer = appium.startServer();24appiumServer.on('exit', function() {25 console.log('Appium exited unexpectedly');26});27appiumServer.on('error', function(err) {28 console.log('Appium failed to start: ' + err);29});30appiumServer.on('listening', function() {31 console.log('Appium server started');32 appium.createSession({33 }, function(err, sessionId) {34 if (err) {35 console.log('Error creating session: ' + err);36 appiumServer.stop();37 } else {38 console.log('Session ID: ' + sessionId);39 appiumServer.stop();40 }41 });42});43var appium = require('appium');44var appiumServer = appium.startServer();45appiumServer.on('exit', function() {46 console.log('Appium exited unexpectedly');47});48appiumServer.on('error', function(err) {49 console.log('Appium failed to start
Using AI Code Generation
1var Appium = require('appium');2var capabilities = {3};4Appium.createSession(capabilities, function (err, session) {5 session.close(function (err) {6 });7});8#### Appium.createSession(capabilities, callback)9#### Appium.createSessionAsync(capabilities)10#### Appium.createSessionWithConfig(config, callback)11#### Appium.createSessionWithConfigAsync(config)12#### Session.close(callback)13#### Session.closeAsync()
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!!