diff --git a/lib/webdriveragent.js b/lib/webdriveragent.js index fdae2bff6..a80909954 100644 --- a/lib/webdriveragent.js +++ b/lib/webdriveragent.js @@ -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(); @@ -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'); @@ -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');