首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >cucumber测试文件下载

cucumber测试文件下载
EN

Stack Overflow用户
提问于 2011-03-10 11:51:03
回答 5查看 11.4K关注 0票数 18

有谁知道如何使用cucumber测试文件下载?

EN

回答 5

Stack Overflow用户

发布于 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
票数 14
EN

Stack Overflow用户

发布于 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"

干杯

票数 11
EN

Stack Overflow用户

发布于 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中的文件名。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5255250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档