Antarr Byrd
Antarr Byrd

Reputation: 26169

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

Upvotes: 4

Views: 2409

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49950

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

Upvotes: 5

Related Questions