From 1daf23357eae805f934da1d969d06b47c18c341e Mon Sep 17 00:00:00 2001 From: Nick Chursin Date: Tue, 24 Sep 2024 18:26:24 +0300 Subject: [PATCH 1/6] Build WDA script - parameters --- docs/reference/scripts.md | 2 +- scripts/build-wda.js | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/docs/reference/scripts.md b/docs/reference/scripts.md index ff26dfeaa..6d73f0ff1 100644 --- a/docs/reference/scripts.md +++ b/docs/reference/scripts.md @@ -15,4 +15,4 @@ 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. Use `--sdk` and `--name` to customize iOS version and the device| diff --git a/scripts/build-wda.js b/scripts/build-wda.js index d6edad306..c1e3199cf 100644 --- a/scripts/build-wda.js +++ b/scripts/build-wda.js @@ -4,24 +4,36 @@ const B = require('bluebird'); const {Simctl} = require('node-simctl'); const {getSimulator} = require('appium-ios-simulator'); const {logger} = require('appium/support'); +const yargs = require('yargs/yargs'); +const {hideBin} = require('yargs/helpers'); const log = logger.getLogger('WDA'); -// TODO: allow passing in all the various build params as CLI args +const argv = yargs(hideBin(process.argv)).options({ + sdk: {type: 'string', alias: 'v', demandOption: false, describe: 'iOS SDK version to use'}, + name: { + type: 'string', + alias: 'd', + demandOption: false, + describe: 'Name of the iOS simulator to use', + }, +}).argv; + async function build() { - const [xcodeVersion, platformVersion] = await B.all([ - xcode.getVersion(true), - xcode.getMaxIOSSDK(), - ]); + let [xcodeVersion, platformVersion] = await B.all([xcode.getVersion(true), xcode.getMaxIOSSDK()]); + platformVersion = argv.sdk || platformVersion; + 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} ${argv.name || ''} Simulator on your system`, + ); } return info; }; const deviceInfo = verifyDevicePresence( (await new Simctl().getDevices(platformVersion, 'iOS')).find(({name}) => - name.includes('iPhone'), + name.includes(argv.name || 'iPhone'), ), ); const device = await getSimulator(deviceInfo.udid, { @@ -34,7 +46,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); } From 84e48f886f0b13df4bc0e67c2c9dc626b276edbd Mon Sep 17 00:00:00 2001 From: Nick Chursin Date: Tue, 24 Sep 2024 19:05:45 +0300 Subject: [PATCH 2/6] Resolve suggestions --- docs/reference/scripts.md | 7 ++++++- scripts/build-wda.js | 31 +++++++++++++++---------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/docs/reference/scripts.md b/docs/reference/scripts.md index 6d73f0ff1..cff604c6f 100644 --- a/docs/reference/scripts.md +++ b/docs/reference/scripts.md @@ -15,4 +15,9 @@ 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. Use `--sdk` and `--name` to customize iOS version and the device| +|`build-wda`|Builds the WebDriverAgent project using the first available iPhone simulator and the latest iOS supported by the current Xcode version by default. Params `--sdk` and `--name` to customize iOS version and the device - if not specified latest iOS and first available iPhone simulator| + + +```bash +appium driver run xcuitest build-wda --sdk=17.5 --name="iPhone 15" +``` diff --git a/scripts/build-wda.js b/scripts/build-wda.js index c1e3199cf..41c893d44 100644 --- a/scripts/build-wda.js +++ b/scripts/build-wda.js @@ -1,39 +1,38 @@ 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 yargs = require('yargs/yargs'); -const {hideBin} = require('yargs/helpers'); const log = logger.getLogger('WDA'); -const argv = yargs(hideBin(process.argv)).options({ - sdk: {type: 'string', alias: 'v', demandOption: false, describe: 'iOS SDK version to use'}, - name: { - type: 'string', - alias: 'd', - demandOption: false, - describe: 'Name of the iOS simulator to use', - }, -}).argv; +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() { - let [xcodeVersion, platformVersion] = await B.all([xcode.getVersion(true), xcode.getMaxIOSSDK()]); - platformVersion = argv.sdk || platformVersion; + const customDevice = parseArgValue('name'); + const xcodeVersion = await xcode.getVersion(true); + const platformVersion = parseArgValue('sdk') || (await xcode.getMaxIOSSDK()); const verifyDevicePresence = (info) => { if (!info) { throw new Error( - `Cannot find any available iOS ${platformVersion} ${argv.name || ''} Simulator on your system`, + `Cannot find any available iOS ${platformVersion} ${customDevice || ''} Simulator on your system`, ); } return info; }; const deviceInfo = verifyDevicePresence( (await new Simctl().getDevices(platformVersion, 'iOS')).find(({name}) => - name.includes(argv.name || 'iPhone'), + name.includes(customDevice || 'iPhone'), ), ); const device = await getSimulator(deviceInfo.udid, { From 78e834f8b5e97b995e85c31fba1e5753bd0ea1a8 Mon Sep 17 00:00:00 2001 From: Nick Chursin Date: Tue, 24 Sep 2024 20:19:43 +0300 Subject: [PATCH 3/6] rm extra whitespace --- scripts/build-wda.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-wda.js b/scripts/build-wda.js index 41c893d44..787c0cab8 100644 --- a/scripts/build-wda.js +++ b/scripts/build-wda.js @@ -25,7 +25,7 @@ async function build() { const verifyDevicePresence = (info) => { if (!info) { throw new Error( - `Cannot find any available iOS ${platformVersion} ${customDevice || ''} Simulator on your system`, + `Cannot find any available iOS ${platformVersion} ${customDevice ? `${customDevice} ` : ''}Simulator on your system`, ); } return info; From 4e00279042b9cc700c1a9d80be56680c59f546ac Mon Sep 17 00:00:00 2001 From: Nick Chursin Date: Tue, 24 Sep 2024 20:33:48 +0300 Subject: [PATCH 4/6] formatting --- scripts/build-wda.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/build-wda.js b/scripts/build-wda.js index 787c0cab8..44d0899a5 100644 --- a/scripts/build-wda.js +++ b/scripts/build-wda.js @@ -21,19 +21,17 @@ async function build() { 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} ${customDevice ? `${customDevice} ` : ''}Simulator on your system`, + `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(customDevice || 'iPhone'), - ), + iosDevices.find(({name}) => name.includes(customDevice || 'iPhone')), ); const device = await getSimulator(deviceInfo.udid, { platform: deviceInfo.platform, From a6f492afef34f2e684997c0bfe7123d0c98e8e78 Mon Sep 17 00:00:00 2001 From: Nick Chursin Date: Tue, 24 Sep 2024 20:35:36 +0300 Subject: [PATCH 5/6] rm extra ) --- scripts/build-wda.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/build-wda.js b/scripts/build-wda.js index 44d0899a5..ec5e24f07 100644 --- a/scripts/build-wda.js +++ b/scripts/build-wda.js @@ -25,7 +25,7 @@ async function build() { const verifyDevicePresence = (info) => { if (!info) { 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')})`, + `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; From 53c0bd1b9dcdb6c03d218bbabf5cec1423089920 Mon Sep 17 00:00:00 2001 From: Nick Chursin Date: Tue, 24 Sep 2024 22:24:35 +0300 Subject: [PATCH 6/6] docs --- docs/reference/scripts.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/docs/reference/scripts.md b/docs/reference/scripts.md index cff604c6f..f50f559a8 100644 --- a/docs/reference/scripts.md +++ b/docs/reference/scripts.md @@ -15,9 +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 by default. Params `--sdk` and `--name` to customize iOS version and the device - if not specified latest iOS and first available iPhone simulator| - - -```bash -appium driver run xcuitest build-wda --sdk=17.5 --name="iPhone 15" -``` +|`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|