我正在尝试使用 Capybara 测试简单的文件上传。这是我的 Gemfile.锁
capybara (1.1.2)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
我的 selenium-webdriver 版本是 2.18。这是我的 web_steps 文件(已生成):
When /^(?:|I )attach the file "([^\"]*)" to "([^\"]*)"(?: within "([^\"]*)")?$/ do |path, field, selector|
with_scope(selector) do
attach_file(field, path)
end
end
这是我上传文件的功能:
Then I attach the file "features/resources/empty.file" to "file" within "#uploadForm"
实际上它运行良好并且在线上显示为绿色,但是输入没有获取任何文件,因此之后测试失败,因为没有选择文件。
这是我的表格:
%form#uploadForm{:action => "/upload", :method => "POST", :enctype => "multipart/form-data"}
%input{:type => "file", :name => "file", :id => "file"}
这是非常基本的,但我不确定为什么它不起作用。
最佳答案
玩具, 我建议:
attach_file(field, File.expand_path(path))
而不是使用绝对路径,尤其是在协作时。
编辑:File.expand_path 不是 File.extend_path
关于ruby - cucumber + capybara 文件上传对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9153290/