Reputation: 26169
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
Reputation: 49950
The selenium driver does not provide access to response headers (nor status codes). You have a couple of options
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