使用Capybara下载CSV [英] Downloading a CSV using Capybara

查看:81
本文介绍了使用Capybara下载CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于rspec测试,我需要下载CSV文件格式的报告并验证给出的信息。

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.

如何使用rspec和Capybara将文件保存到计算机中?

How can I get the the file to be saved to the computer using rspec and Capybara?

推荐答案

我一直在使用 MiniTest :: Spec 并做到了webkit-driver,但应该可以毫无问题地转换为RSpec,因为它基本上只是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).

这篇关于使用Capybara下载CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆