From 3a4830120bb23dbacb1a9481be99ae7c228daa22 Mon Sep 17 00:00:00 2001 From: Nick Chursin Date: Tue, 24 Sep 2024 19:05:45 +0300 Subject: [PATCH] Resolve suggestions --- docs/reference/scripts.md | 7 ++++++- scripts/build-wda.js | 33 +++++++++++++++++---------------- 2 files changed, 23 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..7a4772b9b 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, { @@ -49,6 +48,8 @@ async function build() { log.info( `Building WDA for ${deviceInfo.name} ${platformVersion} with udid '${deviceInfo.udid}' Simulator...`, ); + console.log(deviceInfo); + throw new Error('Not implemented'); await wda.xcodebuild.start(true); }