我正在尝试使用Capybara测试一个简单的文件上传。这是我的 Gemfile.lock的
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"}
这是非常基本的,但我不确定它为什么不起作用。
答案 0 :(得分:12)
玩具, 我建议:
attach_file(field, File.expand_path(path))
而不是使用绝对路径,尤其是在合作时。
编辑:File.expand_path而不是File.extend_path
答案 1 :(得分:5)
我只是想回答我的问题,问题是我没有使用完整路径。不知何故,水豚不承认相对路径。