Live data from Hacker News

Running feature specs with Capybara and Chrome headless

drivy.engineering

31–35 of 35 posts

Re: Running feature specs with Capybara and Chrome headless

#31

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…

Seconded, I did not try all of the other ways you had to go through, fortunately I was already using Selenium with chromedriver in my testing and I found this great set of examples for testing file downloads:

[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]

[3] https://github.com/email-spec/email-spec

Re: Running feature specs with Capybara and Chrome headless

#32
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

Any guess at how much faster the tests are running?

Re: Running feature specs with Capybara and Chrome headless

#33
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.

>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.

Re: Running feature specs with Capybara and Chrome headless

#34

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…

>One thing I learned and wanted to warn about here is that Chrome headless currently doesn't support file downloads [1]. 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;…

Yes - I could have done that on other cases, but not in the specific case I tracked, where I don't know the report URL at all, nor I can construct it (it's generated by some enterprise app / javascript code). I think the bug report I mentioned relates to that.

(otherwise you could use pretty much whatever you want to download the file, indeed).

Re: Running feature specs with Capybara and Chrome headless

#35

Earlier quoted context omitted.

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.

>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.

See the top comment in this issue for my setup: https://github.com/rails/rails/issues/29688

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).

Post reply on HN