How to use getAndCheckXcodeVersion method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

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

Sign up Free
_

utils.js

Source: utils.js Github

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

build-wda.js

Source: build-wda.js Github

copy
1import { WebDriverAgent } from 'appium-webdriveragent';
2import { translateDeviceName, getAndCheckXcodeVersion, getAndCheckIosSdkVersion } from './utils';
3import { getExistingSim } from './simulator-management';
4import { asyncify } from 'asyncbox';
5
6const DEFAULT_SIM_NAME = 'iPhone 12';
7
8// TODO: allow passing in all the various build params as CLI args
9async function build () {
10  const xcodeVersion = await getAndCheckXcodeVersion();
11  const iosVersion = await getAndCheckIosSdkVersion();
12  const deviceName = translateDeviceName(iosVersion, DEFAULT_SIM_NAME);
13  const device = await getExistingSim({
14    platformVersion: iosVersion,
15    deviceName
16  });
17  const wda = new WebDriverAgent(xcodeVersion, {
18    iosSdkVersion: iosVersion,
19    platformVersion: iosVersion,
20    showXcodeLog: true,
21    device,
22  });
23  await wda.xcodebuild.start(true);
24}
25
26if (require.main === module) {
27  asyncify(build);
28}
29
30export default build;
31
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Appium Xcuitest Driver on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)