Running feature specs with Capybara and Chrome headless
drivy.engineering
drivy.engineering
One thing I learned and wanted to warn about here is that Chrome headless currently doesn't support file downloads [1].
PhantomJS won't work either (unless you use a custom build) [2].
I also tried with capybara-webkit, but no luck either [3].
The only driver which ultimately allowed me to download files at this point was Selenium + Firefox (with some tweaking on profile options browser.download.dir, browser.download.folderList = 2, browser.helperApps.neverAsk.saveToDisk set to the MIME type of files to be downloaded).
[1] https://bugs.chromium.org/p/chromium/issues/detail?id=696481
[2] https://github.com/ariya/phantomjs/issues/10052
[3] https://github.com/thoughtbot/capybara-webkit/issues/691
I believe Nightmare [1] (running on Electron) handles files download, it might be worth looking at it?
[1] https://collectiveidea.com/blog/archives/2012/01/27/testing-...
[2] https://forum.shakacode.com/t/how-to-test-file-downloads-wit...
It looks like the second linked post here derives from the first, but both are very similar. My tests don't actually download the files anymore (they are PDFs, and we opted to open them in a new tab instead, which is unfortunately harder to confirm with a test)
Add this to the list of useful wrappers for things I thought would be difficult to test as a regression spec, but ultimately weren't hard at all, like email delivery with email-spec/email-spec [3]
Not true. At least with C# You can use
var client = new WebClient();
client.Headers[HttpRequestHeader.Cookie] = cookieString(driver);
client.DownloadFile(reportURL, savePath + fileName + ".xlsx");
Along with: string cookieString(IWebDriver driver)
{
var cookies = driver.Manage().Cookies.AllCookies;
return string.Join("; ", cookies.Select(c => string.Format("{0}={1}", c.Name, c.Value)));
}
Edit: Just wanted to emphasize that this ensures all the steps you did to login won't be lost since you're using the logged in cookie.
The idea is to use Selenium to get the download url and then use a regular download method using the selenium cookie.(otherwise you could use pretty much whatever you want to download the file, indeed).
The short version of what's wrong: chrome headless does not support extensions. The chromedriver used by selenium works via starting chrome with an automation extension that gives it certain needed functionality. So things like setting the window size, taking screenshots, and a few other important features just cause chromedriver to crash or hang.
There's bugs filed and some clever googlers are trying to fix it all- but it's not ready for our purposes yet. I don't want to rewrite dozens of tests that work with phantomjs to get around chrome's bugs.
https://github.com/teamcapybara/capybara/commit/12c100597093...
Certainly it is possible to pass chromeOptions: { args: %w[headless disable-gpu window-size=1920x1080] } to the capabilities object and that works.
Screenshots also work in Rails system tests.
Do you have a link or something about how to make that work? About two weeks ago, I was struggling with screenshots and pushed it back to my to-do list.
Until the fix is released for Rails(the issue is resolved, but I don't think it's published to rubygems) you'll also need the monkeypatch I added later on in the issue report(or some other code to that effect).
So I opened it headless and there's this REPL, nice I can do JS directly into the website. Now how do I automate this.
This leads me into all sorts of things that doesn't seem related at all (I is, but still). Selenium stuff, automation setups, drivers, language bindings, chrome-api-stuff and no end in sight.
All I want is something like "chrome -headless -js script-flow.file http://URL"
Am I to overwhelmed or is there no simple way without buttloads of 3rd party tools and setups required?
But, you have bunch of things that abstract that for you, so you don't have to implement things hitting that API manually. Anyways, here is a handy document from Mozilla on the protocol too: http://searchfox.org/mozilla-central/source/devtools/docs/ba...
Additionally, for many use cases, the many browser automation SaaS's out there are a good solution.
Basically auth on websites seems to require a whole bunch of stuff and I just started looking at simpler forms of automation instead. Still not sure which one I'll continue looking into.
(If anyone sees this, I am trying to log into iTunes Connect and Fabric and download metrics)
Everything a web scraper could do, without reinventing all the infrastructure for handling web content (including JS/DOM interaction) from scratch. You could obviously do it all yourself in your language of choice,but why not focus on the application specific parts?
Did you do a comparison of memory against phantomJS?
> I think people will switch to it, eventually. Chrome is faster and more stable than PhantomJS. And it doesn't eat memory like crazy.
[0] https://groups.google.com/forum/#!msg/phantomjs/9aI5d-LDuNE/...
[1]: https://robots.thoughtbot.com/headless-feature-specs-with-ch...
Does Chrome headless have an equivalent? It's the only thing preventing us from moving across. And if not where should I raise it?
Everything you get in the Network inspector in Chrome DevTools should be available in Headless Chrome.
https://chromedevtools.github.io/devtools-protocol/tot/Netwo...
Even with Poltergeist I used to debug a slow test suite with it's `--proxy-server` option.
You can fire up mitmproxy and see the requests flowing in real time. You can even modify them or replay them.
I don't understand. How would you do it when it's not overlapping?