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: Support prebuiltWDAPath for iOS 17 #868

Merged
merged 6 commits into from
Mar 23, 2024
Merged
Changes from 1 commit
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
76 changes: 74 additions & 2 deletions lib/webdriveragent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { retryInterval } from 'asyncbox';
import _ from 'lodash';
import path from 'path';
import url from 'url';
Expand Down Expand Up @@ -287,6 +288,73 @@ class WebDriverAgent {
}
}


/**
* @typedef {Object} LaunchingEnvironmentOptions
* @property {number} USE_PORT
* @property {string} WDA_PRODUCT_BUNDLE_IDENTIFIER
*/

/**
* Launch WDA with preinstalled package with 'xcrun devicectl device process launch'.
* The WDA package must be prepared properly like published via
* https://github.com/appium/WebDriverAgent/releases
* with proper sign for this case.
*
* When we implement launching XCTest service via appium-ios-device,
* this implementation can be replaced with it.
*
* @param {LaunchingEnvironmentOptions} launchingEnv launching environment for WebDriverAgent.
* @return {Promise<void>}
*/

mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
async _launchWdaViaDeviceCtl(launchingEnv) {
KazuCocoa marked this conversation as resolved.
Show resolved Hide resolved
// FIXME: use appium-xcuitest-driver's Devicectl. Maybe it needs to be included in the `this.device`?
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved

const envVar = {
// the port number must be string for the devicectl command.
USE_PORT: `${launchingEnv.USE_PORT}`,
KazuCocoa marked this conversation as resolved.
Show resolved Hide resolved
WDA_PRODUCT_BUNDLE_IDENTIFIER: launchingEnv.WDA_PRODUCT_BUNDLE_IDENTIFIER
};

let xcrunBinnaryPath;
try {
xcrunBinnaryPath = await fs.which('xcrun');
} catch (e) {
throw new Error(
`xcrun has not been found in PATH. ` +
`Please make sure XCode development tools are installed`,
);
}

const {stdout} = await exec(xcrunBinnaryPath, [
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
'devicectl',
'device',
'process',
'launch',
`--device`, this.device.udid,
'--environment-variables', JSON.stringify(envVar),
'--terminate-existing',
this.bundleIdForXctest
]);
this.log.debug(`The output of devicectl command: ${stdout}`);

// Launching app via decictl does not wait for the app start.
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
// We should wait for the app start by ourselves.
try {
await retryInterval(30, 1000, async () => {
if (_.isNull(await this.getStatus())) {
throw new Error();
}
});
} catch (err) {
throw new Error(
`Failed to start the preinstalled WebDriverAgent in ${30 * 1000} ms.` +
`The WebDriverAgent might not be properly built or the device might be locked.`
);
}
}

/**
* Launch WDA with preinstalled package without xcodebuild.
* @param {string} sessionId Launch WDA and establish the session with this sessionId
Expand All @@ -302,8 +370,12 @@ class WebDriverAgent {
}
this.log.info('Launching WebDriverAgent on the device without xcodebuild');
if (this.isRealDevice) {
this.xctestApiClient = new Xctest(this.device.udid, this.bundleIdForXctest, null, {env: xctestEnv});
await this.xctestApiClient.start();
if (util.compareVersions(this.platformVersion, '>=', '17.0')) {
KazuCocoa marked this conversation as resolved.
Show resolved Hide resolved
await this._launchWdaViaDeviceCtl(xctestEnv);
} else {
this.xctestApiClient = new Xctest(this.device.udid, this.bundleIdForXctest, null, {env: xctestEnv});
await this.xctestApiClient.start();
}
} else {
await this.device.simctl.exec('launch', {
args: [
Expand Down
Loading