Best JavaScript code snippet using appium-xcuitest-driver
driver.js
Source:driver.js
...527 this.opts.udid = await detectUdid();528 } catch (err) {529 // Trying to find matching UDID for Simulator530 log.warn(`Cannot detect any connected real devices. Falling back to Simulator. Original error: ${err.message}`);531 const device = await getExistingSim(this.opts);532 if (!device) {533 // No matching Simulator is found. Throw an error534 log.errorAndThrow(`Cannot detect udid for ${this.opts.deviceName} Simulator running iOS ${this.opts.platformVersion}`);535 }536 // Matching Simulator exists and is found. Use it537 this.opts.udid = device.udid;538 return {device, realDevice: false, udid: device.udid};539 }540 } else {541 // make sure it is a connected device. If not, the udid passed in is invalid542 const devices = await getConnectedDevices();543 log.debug(`Available devices: ${devices.join(', ')}`);544 if (devices.indexOf(this.opts.udid) === -1) {545 throw new Error(`Unknown device or simulator UDID: '${this.opts.udid}'`);546 }547 }548 const device = await getRealDeviceObj(this.opts.udid);549 return {device, realDevice: true, udid: this.opts.udid};550 }551 // figure out the correct simulator to use, given the desired capabilities552 let device = await getExistingSim(this.opts);553 // check for an existing simulator554 if (device) {555 return {device, realDevice: false, udid: device.udid};556 }557 // no device of this type exists, so create one558 log.info('Simulator udid not provided, using desired caps to create a new simulator');559 if (!this.opts.platformVersion) {560 log.info(`No platformVersion specified. Using latest version Xcode supports: '${this.iosSdkVersion}' ` +561 `This may cause problems if a simulator does not exist for this platform version.`);562 this.opts.platformVersion = this.iosSdkVersion;563 }564 if (this.opts.noReset) {565 // Check for existing simulator just with correct capabilities566 let device = await getExistingSim(this.opts);567 if (device) {568 return {device, realDevice: false, udid: device.udid};569 }570 }571 device = await this.createSim();572 return {device, realDevice: false, udid: device.udid};573 }574 async startSim () {575 const runOpts = {576 scaleFactor: this.opts.scaleFactor,577 connectHardwareKeyboard: !!this.opts.connectHardwareKeyboard,578 isHeadless: !!this.opts.isHeadless,579 devicePreferences: {},580 };...
safari-e2e-specs.js
Source:safari-e2e-specs.js
...34 let sim;35 let simCreated = false;36 let address;37 before(async function () {38 sim = await getExistingSim(DEVICE_NAME, PLATFORM_VERSION);39 if (!sim) {40 const udid = await new Simctl().createDevice(SIM_NAME, DEVICE_NAME, PLATFORM_VERSION);41 sim = await getSimulator(udid);42 simCreated = true;43 }44 // on certain system, particularly Xcode 11 on Travis, starting the sim fails45 await retry(4, async function () {46 try {47 await sim.run({48 startupTimeout: 60000,49 });50 } catch (err) {51 await sim.shutdown();52 throw err;...
simulator-management-specs.js
Source:simulator-management-specs.js
...34 });35 it('should call default device name', async function () {36 createDeviceStub.returns([{name: 'iPhone 6', udid: 'dummy-udid'}]);37 getSimulatorStub.returns('dummy-udid');38 await getExistingSim(caps);39 createDeviceStub.calledOnce.should.be.true;40 createDeviceStub.firstCall.args[0].should.eql('10.1');41 getSimulatorStub.calledOnce.should.be.true;42 getSimulatorStub.firstCall.args[0].should.eql('dummy-udid');43 });44 it('should call non-appiumTest prefix name if device has appiumTest prefix and no prefix device name', async function () {45 createDeviceStub.returns([{name: 'appiumTest-iPhone 6', udid: 'appiumTest-dummy-udid'}, {name: 'iPhone 6', udid: 'dummy-udid'}]);46 getSimulatorStub.returns('dummy-udid');47 await getExistingSim(caps);48 createDeviceStub.calledOnce.should.be.true;49 createDeviceStub.firstCall.args[0].should.eql('10.1');50 getSimulatorStub.calledOnce.should.be.true;51 getSimulatorStub.firstCall.args[0].should.eql('dummy-udid');52 });53 it('should call appiumTest prefix device name', async function () {54 createDeviceStub.returns([{name: 'appiumTest-iPhone 6', udid: 'dummy-udid'}]);55 getSimulatorStub.returns('dummy-udid');56 await getExistingSim(caps);57 createDeviceStub.calledOnce.should.be.true;58 createDeviceStub.firstCall.args[0].should.eql('10.1');59 getSimulatorStub.calledOnce.should.be.true;60 getSimulatorStub.firstCall.args[0].should.eql('dummy-udid');61 });62 it('should not exist sim', async function () {63 createDeviceStub.returns();64 getSimulatorStub.returns();65 await getExistingSim(caps);66 createDeviceStub.calledOnce.should.be.true;67 createDeviceStub.firstCall.args[0].should.eql('10.1');68 getSimulatorStub.notCalled.should.be.true;69 });70 });...
simulator-management.js
Source:simulator-management.js
1import path from 'path';2import { getSimulator } from 'appium-ios-simulator';3import { createDevice, getDevices, terminate } from 'node-simctl';4import { resetXCTestProcesses } from './utils';5import _ from 'lodash';6import log from './logger';7// returns sim for desired caps8async function createSim (caps, sessionId) {9 let name = `appiumTest-${sessionId}`;10 let udid = await createDevice(name, caps.deviceName, caps.platformVersion);11 return await getSimulator(udid);12}13async function getExistingSim (opts) {14 let devices = await getDevices(opts.platformVersion);15 for (let device of _.values(devices)) {16 if (device.name === opts.deviceName) {17 return await getSimulator(device.udid);18 }19 }20 return null;21}22async function runSimulatorReset (device, opts) {23 if (opts.noReset && !opts.fullReset) {24 // noReset === true && fullReset === false25 log.debug('Reset: noReset is on. Leaving simulator as is');26 return;27 }28 if (!device) {29 log.debug('Reset: no device available. Skipping');30 return;31 }32 if (opts.fullReset) {33 log.debug('Reset: fullReset is on. Cleaning simulator');34 // stop XCTest processes if running to avoid unexpected side effects35 await resetXCTestProcesses(device.udid, true);36 // The simulator process must be ended before we delete applications.37 await device.shutdown();38 await device.clean();39 } else if (opts.bundleId) {40 // Terminate the app under test if it is still running on Simulator41 // Termination is not needed if Simulator is not running42 if (await device.isRunning()) {43 if (device.xcodeVersion.major >= 8) {44 try {45 await terminate(device.udid, opts.bundleId);46 } catch (err) {47 log.warn(`Reset: failed to terminate Simulator application with id "${opts.bundleId}"`);48 }49 } else {50 await device.shutdown();51 }52 }53 if (opts.app) {54 log.info('Not scrubbing third party app in anticipation of uninstall');55 return;56 }57 const isSafari = (opts.browserName || '').toLowerCase() === 'safari';58 try {59 if (isSafari) {60 await device.cleanSafari();61 } else {62 await device.scrubCustomApp(path.basename(opts.app), opts.bundleId);63 }64 } catch (err) {65 log.warn(err.message);66 log.warn(`Reset: could not scrub ${isSafari ? 'Safari browser' : 'application with id "' + opts.bundleId + '"'}. Leaving as is.`);67 }68 }69}70async function installToSimulator (device, app, bundleId, noReset = true) {71 if (!app) {72 log.debug('No app path is given. Nothing to install.');73 return;74 }75 if (bundleId) {76 if (await device.isAppInstalled(bundleId)) {77 if (noReset) {78 log.debug(`App '${bundleId}' is already installed. No need to reinstall.`);79 return;80 }81 log.debug(`Reset requested. Removing app with id '${bundleId}' from the device`);82 await device.removeApp(bundleId);83 }84 }85 log.debug(`Installing '${app}' on Simulator with UUID '${device.udid}'...`);86 await device.installApp(app);87 log.debug('The app has been installed successfully.');88}...
build-wda.js
Source:build-wda.js
...7async function build () {8 const xcodeVersion = await getAndCheckXcodeVersion();9 const iosVersion = await getAndCheckIosSdkVersion();10 const deviceName = translateDeviceName(iosVersion, DEFAULT_SIM_NAME);11 const device = await getExistingSim({12 platformVersion: iosVersion,13 deviceName14 });15 const wda = new WebDriverAgent(xcodeVersion, {16 iosSdkVersion: iosVersion,17 platformVersion: iosVersion,18 showXcodeLog: true,19 device,20 });21 await wda.xcodebuild.start(true);22}23if (require.main === module) {24 asyncify(build);25}...
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const expect = chai.expect;6const should = chai.should;7const _ = require('lodash');8const { exec } = require('teen_process');9const { retryInterval } = require('asyncbox');10const { XCUITestDriver, commands } = require('appium-xcuitest-driver');11const { server, port } = require('appium-uiautomator2-driver');12const { getExistingSim } = commands;13const SIM_NAME = 'iPhone 6';14const opts = {15};16async function getExistingSimulator (udid, xcodeVersion) {17 return await getExistingSim.call(this, udid, xcodeVersion);18}19async function main () {20 const driver = new XCUITestDriver();21 await driver.createSession(opts);22 const udid = await driver.opts.device.udid;23 const xcodeVersion = await driver.opts.device.xcodeVersion;24 const sim = await getExistingSimulator.call(driver, udid, xcodeVersion);25 console.log(sim);26 await driver.deleteSession();27}28main();29{30 "scripts": {31 },32 "dependencies": {33 }34}
Using AI Code Generation
1var wd = require('wd');2var assert = require('assert');3var serverConfig = {4};5var driver = wd.promiseChainRemote(serverConfig);6var desired = {7};8 .init(desired)9 .getExistingSim()10 .then(function (res) {11 console.log(res);12 })13 .quit();
Using AI Code Generation
1const { XCUITestDriver } = require('appium-xcuitest-driver');2const { XCUITestSimulator } = require('appium-ios-simulator');3const { getExistingSim } = require('appium-ios-simulator');4const { getExistingDevice } = require('appium-ios-device');5const { XCUITestSimulatorDriver } = require('appium-xcuitest-driver');6const { XCUITestDriver } = require('appium-xcuitest-driver');7const { XCUITestSimulator } = require('appium-ios-simulator');8const { getExistingSim } = require('appium-ios-simulator');9const { getExistingDevice } = require('appium-ios-device');10const { XCUITestSimulatorDriver } = require('appium-xcuitest-driver');11const { XCUITestDriver } = require('appium-xcuitest-driver');12const { XCUITestSimulator } = require('appium-ios-simulator');13const { getExistingSim } = require('appium-ios-simulator');14const { getExistingDevice } = require('appium-ios-device');15const { XCUITestSimulatorDriver } = require('appium-xcuitest-driver');16const { XCUITestDriver } = require('appium-xcuitest-driver');17const { XCUITestSimulator } = require('appium-ios-simulator');18const { getExistingSim } = require('appium-ios-simulator');19const { getExistingDevice } = require('appium-ios-device');20const { XCUITestSimulatorDriver } = require('appium-xcuitest-driver');21const { XCUITestDriver } = require('appium-xcuitest-driver');22const { XCUITestSimulator } = require('appium-ios-simulator');23const { getExistingSim } = require('appium-ios-simulator');24const { getExistingDevice } = require('appium-ios-device');25const { XCUITestSimulatorDriver } = require('appium-xcuitest-driver');26const { XCUITestDriver } = require('appium-xcuitest-driver');27const { XCUITestSimulator } = require('appium-ios-simulator');28const { getExistingSim } = require('
Using AI Code Generation
1const { getExistingSim } = require('appium-xcuitest-driver/lib/simulator-management.js');2async function getSim() {3 const sim = await getExistingSim('iPhone 11');4 console.log(sim);5}6getSim();7{8 "dependencies": {9 },10 "devDependencies": {},11 "scripts": {12 },13}
Using AI Code Generation
1const { getExistingSim } = require('appium-xcuitest-driver');2async function getSim() {3 const sim = await getExistingSim('iPhone 6');4 console.log(sim);5}6getSim();7{8 availability: '(available)',9}
Using AI Code Generation
1const {getExistingSim} = require('appium-xcuitest-driver');2const getSim = async () => {3 const simList = await getExistingSim();4 console.log('Simulator List: ', simList);5}6getSim();7Simulator List: [ 'iPhone 5s', 'iPhone 6', 'iPhone 6 Plus', 'iPhone 6s', 'iPhone 6s Plus', 'iPhone 7', 'iPhone 7 Plus', 'iPhone 8', 'iPhone 8 Plus', 'iPhone SE', 'iPhone X', 'iPad Air', 'iPad Air 2', 'iPad Pro (9.7-inch)', 'iPad Pro (12.9-inch) (1st generation)', 'iPad Pro (12.9-inch) (2nd generation)', 'iPad Pro (10.5-inch)', 'iPad (5th generation)', 'iPad (6th generation)', 'iPad (7th generation)', 'iPad Pro (11-inch)', 'iPad Pro (12.9-inch) (3rd generation)' ]
Using AI Code Generation
1let getExistingSim = require('./lib/getExistingSim');2let sim = getExistingSim('iPhone 6s', '11.4');3console.log(sim);4let simctl = require('node-simctl');5module.exports = function (deviceName, platformVersion) {6 let simulators = simctl.list('devices');7 let sim = null;8 for (let i = 0; i < simulators.length; i++) {9 if (simulators[i].name === deviceName && simulators[i].runtime === `iOS ${platformVersion}`) {10 sim = simulators[i];11 break;12 }13 }14 return sim;15};
Using AI Code Generation
1const wd = require('wd');2const {assert} = require('chai');3const port = 4723;4const udid = '00008020-000E6A0E1C1A002E';5const app = '/Users/username/Library/Developer/Xcode/DerivedData/WebDriverAgent-brdadhpuduowllgivnnvuygpwhzy/Build/Products/Debug-iphonesimulator/IntegrationApp.app';6const host = 'localhost';7const desiredCaps = {
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!!