我正在尝试使用Capybara和Cucumber测试下载。
测试步骤如下:
When(/^I export to CSV$/) do
export_button = find("div.results-table input[type=\"submit\"]")
export_button.click
end
Then(/^I should be prompted to download the CSV$/) do
Capybara.current_driver = :webkit #switch driver so we can see the response_headers
page.response_headers['Content-Disposition'].should include("filename=\"transactions\"")
end
我必须在测试过程中添加capybara webkit驱动程序,以便我可以使用response_headers,但response_headers似乎返回一个空对象。我之前使用的是默认驱动程序,因为我需要单击按钮,但我想知道切换这样的驱动程序是为什么我在response_header中没有得到任何内容?
答案 0 :(得分:1)
我在最近的项目中完成了这项工作,如下所示
<link rel="stylesheet" href="../Includes/Assets/style.css" />
这个黄瓜的水豚就像
Given Download folder for export is empty
And Joe clicks "Download Csv" button
Then The contents of the downloaded csv should be:
|TEAM_ID | TEAM_EXTERNAL_ID | TYPE | REG_OPTION | TEAM_REG_BRACKET | RACE_NAME | WAVE | BIB | BRACKET | STATUS | TEAM_NAME | TEAM_TYPE | ATHLETE_COUNT | MIN_MEMBERS | MAX_MEMBERS | TEAM_MEMBERS |
| 8 | | TEAM | 10k Aggregate | N/A | 10k | Universal | 208 | Overall | DNF | Team 08 | Aggregate |0 | | | |
希望这可以解决您下载CSV并验证其内容的问题:)