For a rspec test I need to download a report in a CSV file format and verify the information given.
The report is generated from a web page when a button is clicked. The browsers save dialog box is open giving the options to open or save.
How can I get the the file to be saved to the computer using rspec and Capybara?
I have been using MiniTest::Spec
for this and did it with the webkit-driver, but it should translate to RSpec without a problem as it is basically just Capybara functionality:
scenario "download overview" do
within "aside#actions" do
click_link "Download overview"
end
page.status_code.must_equal 200
page.response_headers['Content-Type'].must_equal "text/csv"
page.response_headers['Content-Disposition'].must_match /attachment; filename="Übersicht.*\.csv/
page.must_have_content "Schubidu"
page.must_have_content "U13"
page.wont_have_content "5000"
end
I did not go into details about the format of the data, but the records that should have been there were there and the ones that should not have been left out (of course this was just a small dataset to keep the tests swift).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With