Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test file download with rspec 1.3.0/capybara 0.3.9/selenium?

Hi friends I want to test file download in capybara.

I have tried

page.response_headers['Content-Type']

But it raises Capybara::NotSupportedByDriverError exception.

I have also tried

page.driver.browser.switch_to.alert.text

It fails with the message 'No alert is present'

Any help appreciated.

Thank you.

like image 440
Soundar Rathinasamy Avatar asked Mar 13 '12 07:03

Soundar Rathinasamy


People also ask

What are some examples of RSpec and capybara testing?

Here is an example of testing with RSpec and Capybara for a 'login' page: DatabaseCleaner: As the name says, it is a tool used to clean the database after tests.

What is feature testing in capybara?

Capybara tests are often called “feature tests” because, unlike unit tests, they test complex program behaviors that rely on multiple systems within your code. Go ahead and create a spec/features directory to store these tests in later. Database_cleaner takes some more love to get working.

How do I test uploading files through a UI in capybara?

Capybara is a great tool for testing your Rails app. Recently I had cause to test uploading files through a particular UI. Here is how you go about in Capybara. What this tells Capybara is look for a file upload input with the label “Upload Your File” and then inserts the file specified.

How do I clean the database in RSpec?

I use the database_cleaner gem to scrub my test database before each test runs, ensuring a clean slate and stable baseline every time. By default, RSpec will actually do this for you, running every test with a database transaction and then rolling back that transaction after it finishes.


1 Answers

I tested that when I click on a link I should receive *.pdf file.

click_on "link_to_pdf"
page.response_headers['Content-Type'].should eq "application/pdf"

It doesn't work with selenium, so better to specify not javascript driver. I am sure that it works with RackTest.

feature "Download pdf", :js => false do
end
like image 77
Kamil Jopek Avatar answered Sep 20 '22 16:09

Kamil Jopek