Live data from Hacker News

Running feature specs with Capybara and Chrome headless

drivy.engineering

11–20 of 35 posts

Re: Running feature specs with Capybara and Chrome headless

#11

Earlier this month I wrote an ETL extractor using Capybara & headless browser (to work-around a lack of API - PS: only do that as a last resort!). 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 ultimat…

Unfortunately, headless Chrome is still missing some features and file downloads is one of them.

I believe Nightmare [1] (running on Electron) handles files download, it might be worth looking at it?

[1] https://github.com/segmentio/nightmare

Re: Running feature specs with Capybara and Chrome headless

#12
post #2

"It is also supposed to improve memory usage and stability" Did you do a comparison of memory against phantomJS?

Just this morning my team migrated from phantomJS to chrome headless for our Karma plus Jasmine tests. Did a bit of researching before the move and we found tests ran faster plus chrome used less memory than phantomJS. ~ 2000 specs compiling html and stuff

Re: Running feature specs with Capybara and Chrome headless

#14
I tried switching from poltergeist to Chrome headless last week using a very similar setup, but it was much, much slower. I assumed it was Selenium's fault, but didn't dig any deeper as it seemed to be expected from the guide I was using[1] ("I can anecdotally report that Capybara-Webkit seems significantly faster").

[1]: https://robots.thoughtbot.com/headless-feature-specs-with-ch...

Re: Running feature specs with Capybara and Chrome headless

#16
post #13

Poltergeist had a network_traffic mode which we found quite useful. (Seeing if requests were made etc) Does Chrome headless have an equivalent? It's the only thing preventing us from moving across. And if not where should I raise it?

Not that I know of, but AFAIK you can use a proxy.

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.

Re: Running feature specs with Capybara and Chrome headless

#17

Kind of off topic, but. Is running automation as complicated as this? I recently wanted to log in to a website, click some page and download a .csv file. I saw that chrome can be run headless, nice. 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 st…

I'm working on a high-level API to solve a lot of what you're describing. It's still in its infancy, but soon will be runtime agnostic: https://github.com/joelgriffith/navalia. File an issue for what's missing!

Re: Running feature specs with Capybara and Chrome headless

#18
post #6

Chrome headless migration has been my bane for the last two weeks. It's almost ready, but not yet. 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 ch…

I believe chromedriver 2.30(or maybe an earlier version) fixes these issues.

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.

Re: Running feature specs with Capybara and Chrome headless

#19

Kind of off topic, but. Is running automation as complicated as this? I recently wanted to log in to a website, click some page and download a .csv file. I saw that chrome can be run headless, nice. 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 st…

This one will be close one day for downloading at least. Ok today for scraping. https://github.com/LucianoGanga/simple-headless-chrome

Re: Running feature specs with Capybara and Chrome headless

#20
post #13

Poltergeist had a network_traffic mode which we found quite useful. (Seeing if requests were made etc) Does Chrome headless have an equivalent? It's the only thing preventing us from moving across. And if not where should I raise it?

Headless Chrome is controlled using the Chrome DevTools protocol, which has quite a few options for tracking and modifying network requests.

Everything you get in the Network inspector in Chrome DevTools should be available in Headless Chrome.

https://chromedevtools.github.io/devtools-protocol/tot/Netwo...

Post reply on HN