Skip to content

Commit

Permalink
feat: Enable usePreinstalledWDA feature for simulators (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Mar 21, 2024
1 parent 8c868dc commit 7c684e2
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions lib/webdriveragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,19 @@ class WebDriverAgent {
xctestEnv.MJPEG_SERVER_PORT = this.mjpegServerPort;
}
this.log.info('Launching WebDriverAgent on the device without xcodebuild');
this.xctestApiClient = new Xctest(this.device.udid, this.bundleIdForXctest, null, {env: xctestEnv});

await this.xctestApiClient.start();
if (this.isRealDevice) {
this.xctestApiClient = new Xctest(this.device.udid, this.bundleIdForXctest, null, {env: xctestEnv});
await this.xctestApiClient.start();
} else {
await this.device.simctl.exec('launch', {
args: [
'--terminate-running-process',
this.device.udid,
this.bundleIdForXctest,
],
env: xctestEnv,
});
}

this.setupProxies(sessionId);
const status = await this.getStatus();
Expand Down Expand Up @@ -343,10 +353,7 @@ class WebDriverAgent {
}

if (this.usePreinstalledWDA) {
if (this.isRealDevice) {
return await this.launchWithPreinstalledWDA(sessionId);
}
throw new Error('usePreinstalledWDA is available only for a real device.');
return await this.launchWithPreinstalledWDA(sessionId);
}

this.log.info('Launching WebDriverAgent on the device');
Expand Down Expand Up @@ -460,10 +467,16 @@ class WebDriverAgent {

async quit () {
if (this.usePreinstalledWDA) {
this.log.info('Stopping the XCTest session');
if (this.xctestApiClient) {
this.log.info('Stopping the XCTest session');
this.xctestApiClient.stop();
this.xctestApiClient = null;
} else {
try {
await this.device.simctl.terminateApp(this.bundleIdForXctest);
} catch (e) {
this.log.warn(e.message);
}
}
} else if (!this.args.webDriverAgentUrl) {
this.log.info('Shutting down sub-processes');
Expand Down

0 comments on commit 7c684e2

Please sign in to comment.