Deepak Lamichhane
Deepak Lamichhane

Reputation: 22704

Using Cucumber testing for uploadify on rails 3

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.

Upvotes: 5

Views: 613

Answers (2)

Dipak Panchal
Dipak Panchal

Reputation: 6036

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"

Upvotes: 1

jatin
jatin

Reputation: 1449

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.

Upvotes: 1

Related Questions