-
-
Notifications
You must be signed in to change notification settings - Fork 423
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
Change the default behaviour of useNewWDA capability #456
Changes from 3 commits
062036b
c254f43
698a79d
9cfcc16
b60f57f
0c9a16c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,14 @@ import { detectUdid, getAndCheckXcodeVersion, getAndCheckIosSdkVersion, | |
clearSystemFiles, translateDeviceName } from './utils'; | ||
import { getConnectedDevices, runRealDeviceReset, installToRealDevice, | ||
getRealDeviceObj } from './real-device-management'; | ||
import { NoSessionProxy } from "./wda/no-session-proxy"; | ||
import B from 'bluebird'; | ||
import { version } from '../../package.json'; // eslint-disable-line import/no-unresolved | ||
|
||
|
||
const SAFARI_BUNDLE_ID = 'com.apple.mobilesafari'; | ||
const WDA_STARTUP_RETRIES = 2; | ||
const WDA_SIM_STARTUP_RETRIES = 2; | ||
const WDA_REAL_DEV_STARTUP_RETRIES = 1; | ||
const DEFAULT_TIMEOUT_KEY = 'default'; | ||
const WDA_STARTUP_RETRY_INTERVAL = 10000; | ||
const DEFAULT_SETTINGS = { | ||
|
@@ -383,33 +385,58 @@ class XCUITestDriver extends BaseDriver { | |
} | ||
|
||
async startWda (sessionId, realDevice) { | ||
let startupRetries = this.opts.wdaStartupRetries || WDA_STARTUP_RETRIES; | ||
let startupRetryInterval = this.opts.wdaStartupRetryInterval || WDA_STARTUP_RETRY_INTERVAL; | ||
await retryInterval(startupRetries, startupRetryInterval, async () => { | ||
this.logEvent('wdaStartAttempted'); | ||
this.wda = new WebDriverAgent(this.xcodeVersion, this.opts); | ||
this.wda = new WebDriverAgent(this.xcodeVersion, this.opts); | ||
|
||
if (this.opts.useNewWDA) { | ||
log.debug(`Capability 'useNewWDA' set, so uninstalling WDA before proceeding`); | ||
await this.wda.uninstall(); | ||
this.logEvent('wdaUninstalled'); | ||
if (this.opts.useNewWDA) { | ||
log.debug(`Capability 'useNewWDA' set to true, so uninstalling WDA before proceeding`); | ||
await this.wda.quit(); | ||
await this.wda.uninstall(); | ||
this.logEvent('wdaUninstalled'); | ||
} else if (!util.hasValue(this.wda.webDriverAgentUrl)) { | ||
log.debug(`Capability 'useNewWDA' set to false, so trying to reuse currently running WDA instance at ${this.wda.url}...`); | ||
const noSessionProxy = new NoSessionProxy({ | ||
server: this.wda.url.hostname, | ||
port: this.wda.url.port, | ||
base: '', | ||
timeout: 3000, | ||
}); | ||
try { | ||
const status = await noSessionProxy.command('/status', 'GET'); | ||
if (!status) { | ||
throw new Error(`WDA response to /status command should be defined.`); | ||
} | ||
log.debug(`Detected WDA listening at ${this.wda.url}. Setting WDA endpoint to ${this.wda.url}`); | ||
this.wda.webDriverAgentUrl = this.wda.url; | ||
} catch (err) { | ||
log.debug(`WDA is not listening at ${this.wda.url}. Rebuilding...`); | ||
} | ||
} | ||
|
||
// local helper for the two places we need to uninstall wda and re-start it | ||
let quitAndUninstall = async (msg) => { | ||
log.debug(msg); | ||
log.debug('Quitting and uninstalling WebDriverAgent, then retrying'); | ||
await this.wda.quit(); | ||
await this.wda.uninstall(); | ||
throw new Error(msg); | ||
}; | ||
// local helper for the two places we need to uninstall wda and re-start it | ||
const quitAndUninstall = async (msg) => { | ||
log.debug(msg); | ||
log.debug('Quitting and uninstalling WebDriverAgent, then retrying'); | ||
await this.wda.quit(); | ||
await this.wda.uninstall(); | ||
throw new Error(msg); | ||
}; | ||
|
||
const startupRetries = this.opts.wdaStartupRetries || (this.isRealDevice() ? WDA_REAL_DEV_STARTUP_RETRIES : WDA_SIM_STARTUP_RETRIES); | ||
const startupRetryInterval = this.opts.wdaStartupRetryInterval || WDA_STARTUP_RETRY_INTERVAL; | ||
await retryInterval(startupRetries, startupRetryInterval, async () => { | ||
this.logEvent('wdaStartAttempted'); | ||
let wdaStatus = null; | ||
try { | ||
wdaStatus = await this.wda.launch(sessionId, realDevice); | ||
} catch (err) { | ||
this.logEvent('wdaStartFailed'); | ||
await quitAndUninstall(`Unable to launch WebDriverAgent because of xcodebuild failure: ${err.message}`); | ||
let errorMsg = `Unable to launch WebDriverAgent because of xcodebuild failure: ${err.message}`; | ||
if (this.isRealDevice()) { | ||
errorMsg = `Unable to launch WebDriverAgent because of xcodebuild failure: ${err.message}. ` + | ||
`Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. ` + | ||
`Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.`; | ||
} | ||
await quitAndUninstall(errorMsg); | ||
} | ||
|
||
this.proxyReqRes = this.wda.proxyReqRes.bind(this.wda); | ||
|
@@ -434,7 +461,13 @@ class XCUITestDriver extends BaseDriver { | |
}); | ||
this.logEvent('wdaSessionStarted'); | ||
} catch (err) { | ||
return await quitAndUninstall(`Unable to start WebDriverAgent session: ${err.message}`); | ||
let errorMsg = `Unable to start WebDriverAgent sesssion because of xcodebuild failure: ${err.message}`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactor into a function call to handle the error, so it's not repeated here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. error messages are different for both cases. I separated them intentionally for a case when it is necessary to add any other helpful message details to help user to fix his problem for the particular case. |
||
if (this.isRealDevice()) { | ||
errorMsg = `Unable to start WebDriverAgent session because of xcodebuild failure: ${err.message}. ` + | ||
`Make sure you follow the tutorial at https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md. ` + | ||
`Try to remove the WebDriverAgentRunner application from the device if it is installed and reboot the device.`; | ||
} | ||
await quitAndUninstall(errorMsg); | ||
} | ||
|
||
this.opts.preventWDAAttachments = !util.hasValue(this.opts.preventWDAAttachments) || this.opts.preventWDAAttachments; | ||
|
@@ -530,7 +563,9 @@ class XCUITestDriver extends BaseDriver { | |
log.debug(`Unable to DELETE session on WDA: '${err.message}'. Continuing shutdown.`); | ||
} | ||
} | ||
await this.wda.quit(); | ||
if (!this.wda.webDriverAgentUrl && this.opts.useNewWDA) { | ||
await this.wda.quit(); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -807,6 +842,7 @@ class XCUITestDriver extends BaseDriver { | |
|
||
// `resetOnSessionStartOnly` should be set to true by default | ||
this.opts.resetOnSessionStartOnly = !util.hasValue(this.opts.resetOnSessionStartOnly) || this.opts.resetOnSessionStartOnly; | ||
this.opts.useNewWDA = util.hasValue(this.opts.useNewWDA) ? this.opts.useNewWDA : false; | ||
|
||
// finally, return true since the superclass check passed, as did this | ||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably don't want to refer to appium versions in the xcuitest repo, maybe refer to the xcuitest version? unless the default is set in appium and not here. which might be the case, hmm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to driver version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't see a change