diff --git a/docs/reference/scripts.md b/docs/reference/scripts.md index ff26dfeaa..f50f559a8 100644 --- a/docs/reference/scripts.md +++ b/docs/reference/scripts.md @@ -15,4 +15,5 @@ appium driver run xcuitest |Script Name|Description| |------------|-----------| |`open-wda`|Opens the WebDriverAgent project in Xcode| -|`build-wda`|Builds the WebDriverAgent project using the first available iPhone simulator and the latest iOS supported by the current Xcode version| +|`build-wda`|Builds the WebDriverAgent project using the first available iPhone simulator and the latest iOS supported by the current Xcode version by default| +|`build-wda --sdk=17.5 --name="iPhone 15"`|Builds the WebDriverAgent project using the iPhone 15 simulator with iOS 17.5. If `--sdk` and `--name` params are not specified - the latest iOS and the first available iPhone simulator will be used| diff --git a/scripts/build-wda.js b/scripts/build-wda.js index d6edad306..ec5e24f07 100644 --- a/scripts/build-wda.js +++ b/scripts/build-wda.js @@ -1,28 +1,37 @@ const {WebDriverAgent} = require('appium-webdriveragent'); const xcode = require('appium-xcode'); -const B = require('bluebird'); const {Simctl} = require('node-simctl'); const {getSimulator} = require('appium-ios-simulator'); const {logger} = require('appium/support'); const log = logger.getLogger('WDA'); -// TODO: allow passing in all the various build params as CLI args +function parseArgValue(argName) { + const argNamePattern = new RegExp(`^--${argName}\\b`); + for (let i = 1; i < process.argv.length; ++i) { + const arg = process.argv[i]; + if (argNamePattern.test(arg)) { + return arg.includes('=') ? arg.split('=')[1] : process.argv[i + 1]; + } + } + return null; +} + async function build() { - const [xcodeVersion, platformVersion] = await B.all([ - xcode.getVersion(true), - xcode.getMaxIOSSDK(), - ]); + const customDevice = parseArgValue('name'); + const xcodeVersion = await xcode.getVersion(true); + const platformVersion = parseArgValue('sdk') || (await xcode.getMaxIOSSDK()); + const iosDevices = await new Simctl().getDevices(platformVersion, 'iOS'); const verifyDevicePresence = (info) => { if (!info) { - throw new Error(`Cannot find any available iOS ${platformVersion} Simulator on your system`); + throw new Error( + `Cannot find any available iOS ${platformVersion} ${customDevice ? `${customDevice} ` : ''}simulator on your system. Only the following simulators are available:\n${iosDevices.map((e) => e.name).join('\n')}`, + ); } return info; }; const deviceInfo = verifyDevicePresence( - (await new Simctl().getDevices(platformVersion, 'iOS')).find(({name}) => - name.includes('iPhone'), - ), + iosDevices.find(({name}) => name.includes(customDevice || 'iPhone')), ); const device = await getSimulator(deviceInfo.udid, { platform: deviceInfo.platform, @@ -34,7 +43,9 @@ async function build() { showXcodeLog: true, device, }); - log.info(`Building WDA for ${deviceInfo.name} ${platformVersion} Simulator...`); + log.info( + `Building WDA for ${deviceInfo.name} ${platformVersion} with udid '${deviceInfo.udid}' Simulator...`, + ); await wda.xcodebuild.start(true); }