Skip to content

Commit

Permalink
Resolve suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
unickq committed Sep 24, 2024
1 parent 1daf233 commit 3a48301
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
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. 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"
```
33 changes: 17 additions & 16 deletions scripts/build-wda.js
Original file line number Diff line number Diff line change
@@ -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, {
Expand All @@ -49,6 +48,8 @@ async function build() {
log.info(
`Building WDA for ${deviceInfo.name} ${platformVersion} with udid '${deviceInfo.udid}' Simulator...`,
);
console.log(deviceInfo);

Check failure on line 51 in scripts/build-wda.js

View workflow job for this annotation

GitHub Actions / test (18)

Unexpected console statement

Check failure on line 51 in scripts/build-wda.js

View workflow job for this annotation

GitHub Actions / test (20)

Unexpected console statement

Check failure on line 51 in scripts/build-wda.js

View workflow job for this annotation

GitHub Actions / test (22)

Unexpected console statement
throw new Error('Not implemented');
await wda.xcodebuild.start(true);

Check failure on line 53 in scripts/build-wda.js

View workflow job for this annotation

GitHub Actions / test (18)

Unreachable code

Check failure on line 53 in scripts/build-wda.js

View workflow job for this annotation

GitHub Actions / test (20)

Unreachable code

Check failure on line 53 in scripts/build-wda.js

View workflow job for this annotation

GitHub Actions / test (22)

Unreachable code
}

Expand Down

0 comments on commit 3a48301

Please sign in to comment.