Skip to content

Commit

Permalink
feat: build-wda script parameters (#2475)
Browse files Browse the repository at this point in the history
  • Loading branch information
unickq authored Sep 25, 2024
1 parent 7419f29 commit b8bdfad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
3 changes: 2 additions & 1 deletion docs/reference/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ appium driver run xcuitest <script-name>
|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|
33 changes: 22 additions & 11 deletions scripts/build-wda.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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);
}

Expand Down

0 comments on commit b8bdfad

Please sign in to comment.