9

I could test upload of one file

attach_file 'photo', File.join(Rails.root, 'public', 'uploads', 'test.png')

But what if I have a file field with multiple atribute? How can I test multiple files upload using Cucumber/Capybara?

0

2 Answers 2

25

HTML:

<input id="fileupload" class="photo-uploader" type="file" multiple="" name="images">

Capybara:

page.attach_file "images", ['path to file1.jpg', 'path to file2.jpg', 'path to file3.jpg']
  1. Look for the name attribute of the <input> with type="file" and add it as the first parameter.
  2. Add the path to the files as the second parameter. Refer to the statement given above. Do not use relative paths for uploading the file.
Sign up to request clarification or add additional context in comments.

1 Comment

This should be the accepted answer. Simple and it works.
0

It seems it is currently not possible with Capybara:

https://github.com/jnicklas/capybara/issues/37

1 Comment

This answer was correct at the time, but I think @user2391218 has the new correct answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.