Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara fails with NotSupportedByDriverError

I'm trying to verify download csv works in my rails application. But its throwing the error Capybara::NotSupportedByDriverError: Capybara::Driver::Base#response_headers

  it 'exports as CSV' do
    visit_and_login
    agree_to_tos

    click_link 'Download to CSV'

    page.response_headers['Content-Type'].should include 'text/csv'
  end
like image 917
Antarr Byrd Avatar asked Oct 26 '25 09:10

Antarr Byrd


1 Answers

The selenium driver does not provide access to response headers (nor status codes). You have a couple of options

  1. Just verify the href and attributes (download, etc) or the link are correct
  2. Configure the driver to actually download the file and then open and verify it's correct.

Read http://ardesco.lazerycode.com/testing/webdriver/2012/07/25/how-to-download-files-with-selenium-and-why-you-shouldnt.html and then decide which of those you want to do. If #1 then it's straightforward

expect(page).to have_link('Download to CSV', href: 'http://blahblah' )

if #2 then take a look at the Capybara test suite for how to configure the selenium driver to actually download a file - https://github.com/teamcapybara/capybara/blob/master/spec/selenium_spec_chrome.rb#L14

like image 63
Thomas Walpole Avatar answered Oct 28 '25 04:10

Thomas Walpole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!