Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test multiple file upload using Cucumber/Capybara?

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?

like image 672
ValeriiVasin Avatar asked Mar 12 '12 12:03

ValeriiVasin


1 Answers

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.
like image 93
user2391218 Avatar answered Nov 15 '22 19:11

user2391218