diff --git a/lib/webdriveragent.js b/lib/webdriveragent.js index 2424a95aa..ef6e8e766 100644 --- a/lib/webdriveragent.js +++ b/lib/webdriveragent.js @@ -48,6 +48,9 @@ class WebDriverAgent { this.prebuildWDA = args.prebuildWDA; + // this.args.webDriverAgentUrl guiarantees the capabilities acually + // gave 'appium:webDriverAgentUrl' but 'this.webDriverAgentUrl' + // could be used for caching WDA with xcodebuild. this.webDriverAgentUrl = args.webDriverAgentUrl; this.started = false; @@ -64,10 +67,7 @@ class WebDriverAgent { this.usePreinstalledWDA = args.usePreinstalledWDA; this.xctestApiClient = null; - // FIXME: maybe 'this.webDriverAgentUrl' also can ignore - // the xcodebuild instance itself. - - this.xcodebuild = this.usePreinstalledWDA + this.xcodebuild = this.canSkipXcodebuild ? null : new XcodeBuild(this.xcodeVersion, this.device, { platformVersion: this.platformVersion, @@ -96,12 +96,22 @@ class WebDriverAgent { }, this.log); } + /** + * Return true if the session does not need xcodebuild. + * @returns {boolean} Whether the session needs/has xcodebuild. + */ + get canSkipXcodebuild () { + // Use this.args.webDriverAgentUrl to guarantee + // the capabilities set gave the `appium:webDriverAgentUrl`. + return this.usePreinstalledWDA || this.args.webDriverAgentUrl; + } + /** * * @returns {string} Bundle ID for Xctest. */ get bundleIdForXctest () { - return `${this.updatedWDABundleId}.xctrunner` || WDA_RUNNER_BUNDLE_ID_FOR_XCTEST; + return this.updatedWDABundleId ? `${this.updatedWDABundleId}.xctrunner` : WDA_RUNNER_BUNDLE_ID_FOR_XCTEST; } setWDAPaths (bootstrapPath, agentPath) { @@ -266,7 +276,7 @@ class WebDriverAgent { return; } - if (this.usePreinstalledWDA) { + if (this.canSkipXcodebuild) { return; } try { @@ -451,10 +461,13 @@ class WebDriverAgent { this.xctestApiClient.stop(); this.xctestApiClient = null; } - } else { + } else if (!this.args.webDriverAgentUrl) { this.log.info('Shutting down sub-processes'); await this.xcodebuild.quit(); await this.xcodebuild.reset(); + } else { + this.log.debug('Do not stop xcodebuild nor XCTest session ' + + 'since the WDA session is managed by outside this driver.'); } if (this.jwproxy) { @@ -496,7 +509,7 @@ class WebDriverAgent { } async retrieveDerivedDataPath () { - if (this.usePreinstalledWDA) { + if (this.canSkipXcodebuild) { return; } return await this.xcodebuild.retrieveDerivedDataPath();