Using Cucumber testing for uploadify on rails 3

2019-05-02 11:59发布

I want cucumber test for uploadify on ruby on rails 3. I had tried to click on the upload button from capybara but as it is neither button nor link. Furthermore, it is hiding the text_field so I cannot write "When I fill in "upload" with "text.txt"". If any one has solved this problem, please help is needed here.

2条回答
够拽才男人
2楼-- · 2019-05-02 12:04

You would need to write a custom step for uploading a file

When /^I upload a file$/ do
    attach_file(:image, <path-to-file>)
end 

Where image is the name of the html element for getting the file to be uploaded.

查看更多
祖国的老花朵
3楼-- · 2019-05-02 12:06

Write custom step for uploading a file

When /^(?:|I)attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
  type = path.split(".")[1]
  case type
  when "jpg"
    type = "image/jpg"
  when "png"
    type = "image/png"
  when "gif"
    type = "image/gif"
  end
  attach_file(field, path, type)
end

When /^I attach the "(.*)" file at "(.*)" to "(.*)"$/ do |type, path, field|
 attach_file(field,path,type)
end

Cucumber Step like

When I attach the file "/images/back.gif" to "data_input"

查看更多
登录 后发表回答