有谁知道如何使用cucumber测试文件下载?
发布于 2011-03-17 23:32:06
当我使用像这样的send_data(data, :filename => "inventory_#{Date.today.to_s}.csv", :disposition => 'attachment')
这样的send_data时,这对我很有效
可能不是编写步骤的最好方法,但它起作用了!
Then /^I should receive a file(?: "([^"]*)")?/ do |file|
result = page.response_headers['Content-Type'].should == "application/octet-stream"
if result
result = page.response_headers['Content-Disposition'].should =~ /#{file}/
end
result
end
发布于 2011-06-30 19:12:00
我发现this是一种方便的下载测试方法,它只是一种简单的测试方法,在大多数情况下它是合理的。
如果您正在使用capbybara,那么将以下内容放入您的step_definitions.rb中
Then /^I should get a download with the filename "([^\"]*)"$/ do |filename|
page.response_headers['Content-Disposition'].should include("filename=\"#{filename}\"")
end
在功能中,您现在可以执行以下操作:
When I follow "Export as ZIP"
Then I should get a download with the filename "contacts_20110203.zip"
干杯
发布于 2015-07-20 22:26:47
我通过chrome运行selenium,当我测试csv已经下载时,我在Ruby中使用以下代码:
Then /^I should get a downloaded file for fleet: "(.*?)"$/ do |export|
puts Dir["C:/Users/**/Downloads/fleet_#{export}_export_all_*.csv"].last
end
它只是在缺省的下载目录中查找,并确认文件在那里,并输出cmd中的文件名。
https://stackoverflow.com/questions/5255250
复制相似问题