How to use getAndCheckXcodeVersion method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

driver.js

Source:driver.js Github

copy

Full Screen

...107 async createSession (...args) {108 let [sessionId, caps] = await super.createSession(...args);109 // appium-ios-driver uses Instruments to automate the device110 // but Xcode 8 does not have Instruments, so short circuit111 this.xcodeVersion = await utils.getAndCheckXcodeVersion(this.opts);112 logger.debug(`Xcode version set to ${this.xcodeVersion.versionString}`);113 if (this.xcodeVersion.major >= 8) {114 let msg = `Appium's IosDriver does not support Xcode version ${this.xcodeVersion.versionString}. ` +115 'Apple has deprecated UIAutomation. Use the "XCUITest" automationName capability instead.';116 logger.errorAndThrow(new errors.SessionNotCreatedError(msg));117 }118 // merge server capabilities + desired capabilities119 this.caps = Object.assign({}, defaultServerCaps, this.caps);120 this.caps.desired = caps;121 await utils.detectUdid(this.opts);122 await utils.prepareIosOpts(this.opts);123 this.realDevice = null;124 this.useRobot = this.opts.useRobot;125 this.safari = this.opts.safari;126 this.opts.curOrientation = this.opts.initialOrientation;127 this.sock = path.resolve(this.opts.tmpDir || '/tmp', 'instruments_sock');128 try {129 await this.configureApp();130 } catch (err) {131 logger.error(`Bad app: '${this.opts.app}'. App paths need to ` +132 `be absolute, or relative to the appium server ` +133 `install dir, or a URL to compressed file, or a ` +134 `special app name.`);135 throw err;136 }137 await this.start();138 // TODO: this should be in BaseDriver.postCreateSession139 this.startNewCommandTimeout('createSession');140 return [sessionId, this.caps];141 }142 async stop () {143 this.ready = false;144 if (this.uiAutoClient) {145 await this.uiAutoClient.shutdown();146 }147 if (this.instruments) {148 try {149 await this.instruments.shutdown();150 } catch (err) {151 logger.error(`Instruments didn't shut down. ${err}`);152 }153 }154 if (this.caps && this.caps.customSSLCert && !this.isRealDevice()) {155 logger.debug(`Uninstalling ssl certificate for udid '${this.sim.udid}'`);156 await uninstallSSLCert(this.caps.customSSLCert, this.sim.udid);157 }158 if (this.opts.enableAsyncExecuteFromHttps && !this.isRealDevice()) {159 await this.stopHttpsAsyncServer();160 }161 this.uiAutoClient = null;162 this.instruments = null;163 this.realDevice = null;164 // postcleanup165 this.curCoords = null;166 this.opts.curOrientation = null;167 if (!_.isEmpty(this.logs)) {168 await this.logs.syslog.stopCapture();169 this.logs = {};170 }171 if (this.remote) {172 await this.stopRemote();173 }174 await this.stopIWDP();175 }176 async deleteSession () {177 logger.debug('Deleting ios session');178 await this.stop();179 if (this.opts.clearSystemFiles) {180 await utils.clearLogs(LOG_LOCATIONS);181 } else {182 logger.debug('Not clearing log files. Use `clearSystemFiles` capability to turn on.');183 }184 if (this.isRealDevice()) {185 await runRealDeviceReset(this.realDevice, this.opts);186 } else {187 await runSimulatorReset(this.sim, this.opts, this.keepAppToRetainPrefs);188 }189 await super.deleteSession();190 }191 async getSession () {192 let caps = await super.getSession();193 const viewportRect = await this.getViewportRect();194 const pixelRatio = await this.getDevicePixelRatio();195 const statBarHeight = await this.getStatusBarHeight();196 caps.viewportRect = viewportRect;197 caps.pixelRatio = pixelRatio;198 caps.statBarHeight = statBarHeight;199 return caps;200 }201 async executeCommand (cmd, ...args) {202 logger.debug(`Executing iOS command '${cmd}'`);203 if (cmd === 'receiveAsyncResponse') {204 return await this.receiveAsyncResponse(...args);205 } else if (this.ready || _.includes(['launchApp'], cmd)) {206 return await super.executeCommand(cmd, ...args);207 }208 throw new errors.NoSuchDriverError(`Driver is not ready, cannot execute ${cmd}.`);209 }210 // TODO: reformat this.helpers + configureApp211 async configureApp () {212 try {213 // if the app name is a bundleId assign it to the bundleId property214 if (!this.opts.bundleId && utils.appIsPackageOrBundle(this.opts.app)) {215 this.opts.bundleId = this.opts.app;216 }217 if (this.opts.app && this.opts.app.toLowerCase() === 'settings') {218 if (parseFloat(this.opts.platformVersion) >= 8) {219 logger.debug('We are on iOS8+ so not copying preferences app');220 this.opts.bundleId = 'com.apple.Preferences';221 this.opts.app = null;222 }223 } else if (this.opts.app && this.opts.app.toLowerCase() === 'calendar') {224 if (parseFloat(this.opts.platformVersion) >= 8) {225 logger.debug('We are on iOS8+ so not copying calendar app');226 this.opts.bundleId = 'com.apple.mobilecal';227 this.opts.app = null;228 }229 } else if (this.isSafari()) {230 if (!this.isRealDevice()) {231 if (parseFloat(this.opts.platformVersion) >= 8) {232 logger.debug('We are on iOS8+ so not copying Safari app');233 this.opts.bundleId = SAFARI_BUNDLE;234 this.opts.app = null;235 }236 } else {237 // on real device, need to check if safari launcher exists238 // first check if it is already on the device239 if (!await this.realDevice.isInstalled(this.opts.bundleId)) {240 // it's not on the device, so check if we need to build241 if (await needsInstall()) {242 logger.debug('SafariLauncher not found, building...');243 await install();244 }245 this.opts.bundleId = SAFARI_LAUNCHER_BUNDLE;246 }247 }248 } else if (this.opts.bundleId &&249 utils.appIsPackageOrBundle(this.opts.bundleId) &&250 (this.opts.app === '' || utils.appIsPackageOrBundle(this.opts.app))) {251 // we have a bundle ID, but no app, or app is also a bundle252 logger.debug('App is an iOS bundle, will attempt to run as pre-existing');253 } else {254 this.opts.app = await this.helpers.configureApp(this.opts.app, '.app');255 }256 } catch (err) {257 logger.error(err);258 throw new Error(259 `Bad app: ${this.opts.app}. App paths need to be absolute, or relative to the appium ` +260 'server install dir, or a URL to compressed file, or a special app name.');261 }262 }263 async startSimulator () {264 await utils.removeInstrumentsSocket(this.sock);265 if (!this.xcodeVersion) {266 logger.debug('Setting Xcode version');267 this.xcodeVersion = await utils.getAndCheckXcodeVersion(this.opts);268 logger.debug(`Xcode version set to ${this.xcodeVersion.versionString}`);269 }270 logger.debug('Setting iOS SDK Version');271 this.iosSdkVersion = await utils.getAndCheckIosSdkVersion();272 logger.debug(`iOS SDK Version set to ${this.iosSdkVersion}`);273 let timeout = _.isObject(this.opts.launchTimeout) ? this.opts.launchTimeout.global : this.opts.launchTimeout;274 let availableDevices = await retry(3, instrumentsUtils.getAvailableDevices, timeout);275 let iosSimUdid = await checkSimulatorAvailable(this.opts, this.iosSdkVersion, availableDevices);276 this.sim = await getSimulator(iosSimUdid, this.xcodeVersion.versionString);277 await moveBuiltInApp(this.sim);278 this.opts.localizableStrings = await utils.parseLocalizableStrings(this.opts);279 await utils.setBundleIdFromApp(this.opts);280 await this.createInstruments();281 {...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1import { fs, tempDir } from 'appium-support';2import path from 'path';3import { exec } from 'teen_process';4import xcode from 'appium-xcode';5import log from './logger';6const WDA_DERIVED_DATA_SEARCH_SUFFIX = 'Library/Developer/Xcode/DerivedData/WebDriverAgent-*';7const WDA_ATTACHMENTS_FOLDER_RELATIVE_PATH = 'Logs/Test/Attachments';8async function detectUdid () {9 log.debug('Auto-detecting real device udid...');10 let cmd, args = [];11 try {12 cmd = await fs.which('idevice_id');13 args.push('-l');14 log.debug('Using idevice_id');15 } catch (err) {16 log.debug('Using udidetect');17 cmd = require.resolve('udidetect');18 }19 let udid;20 try {21 let {stdout} = await exec(cmd, args, {timeout: 3000});22 udid = stdout.split('\n')[0];23 } catch (err) {24 log.errorAndThrow(`Error detecting udid: ${err.message}`);25 }26 if (!udid || udid.length <= 2) {27 throw new Error('Could not detect udid.');28 }29 log.debug(`Detected real device udid: '${udid}'`);30 return udid;31}32async function getAndCheckXcodeVersion () {33 let version;34 try {35 version = await xcode.getVersion(true);36 } catch (err) {37 log.debug(err);38 log.errorAndThrow(`Could not determine Xcode version: ${err.message}`);39 }40 // we do not support Xcodes < 7.3,41 if (version.versionFloat < 7.3) {42 log.warn(`Xcode version '${version.versionString}'. Support for Xcode ` +43 `${version.versionString} has been deprecated and will be removed ` +44 `in a future version. Please upgrade to version 7 or higher`);45 }46 return version;47}48async function getAndCheckIosSdkVersion () {49 let versionNumber;50 try {51 versionNumber = await xcode.getMaxIOSSDK();52 } catch (err) {53 log.errorAndThrow(`Could not determine iOS SDK version: ${err.message}`);54 }55 return versionNumber;56}57async function killAppUsingAppName (udid, appName) {58 let psArgs = [`-c`, `ps -ax|grep -i "${appName}"|grep -i "${udid}"|grep -v grep|awk '{print "kill -9 " $1}'|sh`];59 try {60 await exec(`bash`, psArgs);61 } catch (err) {62 log.debug(`Error : ${err.message}`);63 }64}65async function adjustWDAAttachmentsPermissions (perms) {66 if (!process.env.HOME) {67 throw new Error('Need HOME env var to be set in order to adjust WDA attachments permission');68 }69 let derivedDataSearchMask = path.join(process.env.HOME, WDA_DERIVED_DATA_SEARCH_SUFFIX);70 let folders = await fs.glob(derivedDataSearchMask);71 let processedFolders = [];72 for (let folder of folders) {73 log.debug(`Found WDA derived data folder: ${folder}`);74 let attachmentsFolder = path.join(folder, WDA_ATTACHMENTS_FOLDER_RELATIVE_PATH);75 if (await fs.exists(attachmentsFolder)) {76 log.info(`Setting '${perms}' permissions to ${attachmentsFolder} folder`);77 await fs.chmod(attachmentsFolder, perms);78 processedFolders.push(attachmentsFolder);79 }80 }81 if (!processedFolders.length) {82 log.info('No WDA derived data folders have been found.');83 }84}85async function generateXcodeConfigFile (orgId, signingId) {86 log.debug(`Generating xcode config file for orgId '${orgId}' and signingId ` +87 `'${signingId}'`);88 let contents = `DEVELOPMENT_TEAM = ${orgId}89CODE_SIGN_IDENTITY = ${signingId}90`;91 let xcconfigPath = await tempDir.path('appium-temp.xcconfig');92 log.debug(`Writing xcode config file to ${xcconfigPath}`);93 await fs.writeFile(xcconfigPath, contents, "utf8");94 return xcconfigPath;95}96export { detectUdid, getAndCheckXcodeVersion, getAndCheckIosSdkVersion,97 killAppUsingAppName, adjustWDAAttachmentsPermissions,...

Full Screen

Full Screen

build-wda.js

Source:build-wda.js Github

copy

Full Screen

...4import { asyncify } from 'asyncbox';5const DEFAULT_SIM_NAME = 'iPhone 12';6// TODO: allow passing in all the various build params as CLI args7async 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}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var XCUITestDriver = require('appium-xcuitest-driver').XCUITestDriver;2var driver = new XCUITestDriver();3driver.getAndCheckXcodeVersion().then(function (version) {4 console.log(version);5});6{7}

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');2const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');3async function test () {4 const xcodeVersion = await getAndCheckXcodeVersion();5 console.log(xcodeVersion);6}7test();8{ major: 11, minor: 3, patch: 1 }9const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');10async function test () {11 const xcodeVersion = await getAndCheckXcodeVersion();12 console.log(xcodeVersion);13}14test();15{ major: 11, minor: 3, patch: 1 }16const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');17async function test () {18 const xcodeVersion = await getAndCheckXcodeVersion();19 console.log(xcodeVersion);20}21test();22{ major: 11, minor: 3, patch: 1 }23const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');24async function test () {25 const xcodeVersion = await getAndCheckXcodeVersion();26 console.log(xcodeVersion);27}28test();29{ major: 11, minor: 3, patch: 1 }30const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');31async function test () {32 const xcodeVersion = await getAndCheckXcodeVersion();33 console.log(xcodeVersion);34}35test();36{ major: 11, minor: 3, patch: 1 }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');2async function checkXcodeVersion () {3 const version = await getAndCheckXcodeVersion();4 console.log(version);5}6checkXcodeVersion();7{8}9const { getXcodeVersion } = require('appium-xcuitest-driver/lib/utils');10async function checkXcodeVersion () {11 const version = await getXcodeVersion();12 console.log(version);13}14checkXcodeVersion();15{16}17const { getXcodeVersion } = require('appium-xcuitest-driver/lib/utils');18async function checkXcodeVersion () {19 const version = await getXcodeVersion();20 console.log(version);21}22checkXcodeVersion();23{24}25const { getXcodeVersion } = require('appium-xcuitest-driver/lib/utils');

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');2async function test() {3 const version = await getAndCheckXcodeVersion();4 console.log(version);5}6test();7{ versionString: '12.2',8 buildVersion: '12B45b' }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');2const xcodeVersion = await getAndCheckXcodeVersion();3console.log(xcodeVersion);4{5}6const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');7const xcodeVersion = await getAndCheckXcodeVersion();8console.log(xcodeVersion);9const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');10const xcodeVersion = await getAndCheckXcodeVersion();11console.log(xcodeVersion);12const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');13const xcodeVersion = await getAndCheckXcodeVersion();14console.log(xcodeVersion);15const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');16const xcodeVersion = await getAndCheckXcodeVersion();17console.log(xcodeVersion);18const { getAndCheckXcodeVersion } = require('appium-xcuitest-driver/lib/utils');19const xcodeVersion = await getAndCheckXcodeVersion();20console.log(xcodeVersion);21const { getAndCheck

Full Screen

Using AI Code Generation

copy

Full Screen

1import { XCUITestDriver } from 'appium-xcuitest-driver';2import { getAndCheckXcodeVersion } from 'appium-xcuitest-driver/lib/utils';3async function main () {4 try {5 let driver = new XCUITestDriver();6 let xcodeVersion = await driver.getAndCheckXcodeVersion();7 console.log(`xcodeVersion: ${xcodeVersion}`);8 } catch (err) {9 console.log(`Error: ${err.message}`);10 }11}12main();13import { XCUITestDriver } from 'appium-xcuitest-driver';14import { getAndCheckXcodeVersion } from 'appium-xcuitest-driver/lib/utils';15async function main () {16 try {17 let driver = new XCUITestDriver();18 let xcodeVersion = await driver.getAndCheckXcodeVersion();19 console.log(`xcodeVersion: ${xcodeVersion}`);20 } catch (err) {21 console.log(`Error: ${err.message}`);22 }23}24main();

Full Screen

Using AI Code Generation

copy

Full Screen

1const XCUITestDriver = require('appium-xcuitest-driver');2const xcode = XCUITestDriver.xcode;3async function checkXcodeVersion() {4 try {5 const xcodeVersion = await xcode.getAndCheckXcodeVersion();6 console.log('Xcode version is', xcodeVersion.versionString);7 console.log('Xcode build version is', xcodeVersion.buildVersion);8 } catch (err) {9 console.error(err);10 }11}12checkXcodeVersion();13{14 "scripts": {15 },16 "dependencies": {17 }18}19{20 "dependencies": {21 "appium-xcuitest-driver": {22 "requires": {

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 Xcuitest Driver automation tests on LambdaTest cloud grid

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

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful