-
-
Notifications
You must be signed in to change notification settings - Fork 454
Move to pinging WDA status for readiness #327
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
Conversation
| } | ||
| await exec('/bin/bash', ['Scripts/bootstrap.sh', '-d'], {cwd: this.bootstrapPath}); | ||
| } catch (err) { | ||
| log.warn('Carthage not found. Install using `brew install carthage`'); |
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.
👍
lib/webdriveragent.js
Outdated
| if (!agentUrl) { | ||
| log.errorAndThrow(new Error('No url detected from WebDriverAgent')); | ||
| try { | ||
| let {stdout} = await exec('curl', curlArgs); |
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.
Executing terminal commands is usually slower than using built-in instruments. How about sending HEAD http request with timeout to the WDA URL and checking the response code?
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 agree, why don't we use request-promise instead of curl?
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 couldn't get it to work when I was originally trying. It would always return a blank response, while I could use the terminal to curl to it no problem.
I'll give it another shot.
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 was thinking about something similar to this example:
http://stackoverflow.com/questions/5922842/getting-http-headers-with-node-js
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.
For reasons unknown, request-promise is working now. I must have done something wrong that I couldn't see before.
lib/webdriveragent.js
Outdated
| } | ||
| return (async () => { | ||
| try { | ||
| await this.iproxy.start(5000); |
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, we can move the timeout value to a separate constant?
lib/webdriveragent.js
Outdated
| resolve(); | ||
| } catch (err) { | ||
| log.error(`Error starting iproxy: '${err.message}'`); | ||
| reject('Unable to start iproxy. Is it installed?'); |
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.
can we show the expected iproxy path in the error message
lib/webdriveragent.js
Outdated
| this.url = url.parse(agentUrl); | ||
|
|
||
| this.url.hostname = 'localhost'; | ||
| this.url = url.parse(`http://localhost:8100`); |
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.
can the URL be moved to a constant?
jlipps
left a comment
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.
+1 to all of @mykola-mokhnach's comments, and added my own. Great approach.
lib/webdriveragent.js
Outdated
| if (!agentUrl) { | ||
| log.errorAndThrow(new Error('No url detected from WebDriverAgent')); | ||
| try { | ||
| let {stdout} = await exec('curl', curlArgs); |
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 agree, why don't we use request-promise instead of curl?
lib/webdriveragent.js
Outdated
| resolve(); | ||
| } catch (err) { | ||
| log.error(`Error starting iproxy: '${err.message}'`); | ||
| reject('Unable to start iproxy. Is it installed?'); |
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 a good practice to reject with an Error instead of a string?
lib/webdriveragent.js
Outdated
| } catch (err) { | ||
| let msg = `Unable to start WebDriverAgent: ${err}`; | ||
| log.error(msg); | ||
| reject(msg); |
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 a good idea to reject with an error instead of a string?
lib/webdriveragent.js
Outdated
| if (!await fs.hasAccess(`${this.bootstrapPath}/Carthage`)) { | ||
| log.debug('Running WebDriverAgent bootstrap script to install dependencies'); | ||
| } else { | ||
| log.debug('Running WebDriverAgent bootstrap script to update dependencies'); |
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.
do we really need to execute carthage again?
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.
This, I think, should fix the errors with certain dependencies not being there. I'm happy to not do this, and make people manually do it when problems arise.
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.
@imurchie is this only a problem when people are running appium from source and receive wda updates?
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.
@jlipps No. I think it is mostly a problem of people upgrading on top of an older version. As in, just doing an npm install without npm uninstall.
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.
Then it would be better to just ask them to do this action manually in an error message. Otherwise executing carthage for each WDA build may greatly slow down automated tests.
f5754cc to
38026f8
Compare
|
All comments addressed in code. |
| |`preventWDAAttachments`|Sets read only permissons to Attachments subfolder of WebDriverAgent root inside Xcode's DerivedData. This is necessary to prevent XCTest framework from creating tons of unnecessary screenshots and logs, which are impossible to shutdown using programming interfaces provided by Apple.|Setting the capability to `true` will set Posix permissions of the folder to `555` and `false` will reset them back to `755`| | ||
| |`webDriverAgentUrl`|If provided, Appium will connect to an existing WebDriverAgent instance at this URL instead of starting a new one.|e.g., `http://localhost:8100`| | ||
|
|
||
| |`useNewWDA`|If `true`, forces uninstall of any existing WebDriverAgent app on device. This can provide stability in some situations. Defaults to `false`.|e.g., `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.
I think it might be useful to give at least one example of such situation
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'll work on documenting an example. I don't have the details of the problem right now.
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.
Does this require manual git pull of webdriveragent source into the wedriveragent under the xcuittestdriver node module ?
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.
No. It just uninstalls the app from the device on session creation.
lib/desired-caps.js
Outdated
| }, | ||
| wdaLocalPort: { | ||
| isNumber: true | ||
| isNumber: 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.
there are no trailing commas for other parameters. Do we follow any rule on this?
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 think we have a rule, per se. And this one is not doing anything (since we won't be adding to the object).
lib/driver.js
Outdated
| try { | ||
| await this.wda.launch(sessionId, realDevice); | ||
| } catch (err) { | ||
| if (tries > 2) throw err; |
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.
this magic number might be moved to constants
| const AGENT_STARTED_REGEX = /ServerURLHere->(.*)<-ServerURLHere/; | ||
| const REAL_DEVICE_LOGGER_PATH = 'idevicesyslog'; | ||
| const WDA_BUNDLE_ID = 'com.apple.test.WebDriverAgentRunner-Runner'; | ||
| const WDA_LAUNCH_TIMEOUT = 60 * 1000; |
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.
👍
lib/webdriveragent.js
Outdated
| await this.deviceLogs.start(startDetector); | ||
| log.info(`WebDriverAgent started at url '${agentUrl}'`); | ||
| }); | ||
| let startupTime = Date.now() - startTime; |
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.
one recommends to use process.hrtime for such purpose instead of Date()
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.
Why?
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.
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.
shortly said - process.hrtime has been initially designed to measure intervals with maximum possible precision. And Date is a general class to represent calendar dates in apps.
38026f8 to
66f25a1
Compare
jlipps
left a comment
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.
one small remark then LGTM
lib/webdriveragent.js
Outdated
| let msg = `Unable to start WebDriverAgent: ${err}`; | ||
| log.error(msg); | ||
| reject(new Error(msg)); | ||
| return; |
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.
not sure what this return is doing
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.
Not a whole lot. There must have been something after the catch block at one point.
66f25a1 to
e740021
Compare
|
(I resolved conflicts using the GitHub UI. Pretty cool.) |
package.json
Outdated
| "lodash": "^4.0.0", | ||
| "node-simctl": "^3.1.0", | ||
| "request": "^2.79.0", | ||
| "request-promise": "^2.0.1", |
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.
@imurchie request-promise is at version 4.1.1
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.
Weird. That was just the result of npm -S request-promise, so it should have gotten the latest.
ffc7f99 to
c0b48dd
Compare
|
@jlipps: So, the GitHub UI conflict resolver isn't so good. Alas. |
We currently use the technique of looking at the ios logs (sim or device) and waiting for the marker that WDA writes on startup. This means we need to open and manage the logs, make sure we are looking at the right entries, etc. It is all fraught, as the issue tracker can attest.
This PR strips out all log handling, and instead pings the WDA server until it gets a valid status back, or times out. This is possible since (A) on simulators the WDA server is always on localhost, and (B) on real devices we use
iproxy, which maps the request over USB, so we also end up talking to localhost. In neither case do we need to actual server url, which is the only information that is available in the logs but not the status.Tests are faster, and locally work without issue.
Two new caps are introduced:
useNewWDA- forces uninstall of WDA before launch. This clears up some problems with hanging processes and "too many instances running" errors.wdaLaunchTimeout- ms to wait trying to connect.@mykola-mokhnach Can you try this out for your setup?