Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build-wda script parameters #2475

Merged
merged 6 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion docs/reference/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ 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. Params `--sdk` and `--name` to customize iOS version and the device - if not specified latest iOS and first available iPhone simulator|


```bash
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
appium driver run xcuitest build-wda --sdk=17.5 --name="iPhone 15"
```
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
Loading