如何使用Cucumber/Capybara测试多个文件上传?

Val*_*sin 9 ruby-on-rails cucumber capybara

我可以测试上传一个文件

attach_file 'photo', File.join(Rails.root, 'public', 'uploads', 'test.png')
Run Code Online (Sandbox Code Playgroud)

但是,如果我有一个带multiple属性的文件字段呢?如何使用Cucumber/Capybara测试多个文件上传?

use*_*218 15

HTML:

<input id="fileupload" class="photo-uploader" type="file" multiple="" name="images">
Run Code Online (Sandbox Code Playgroud)

水豚:

page.attach_file "images", ['path to file1.jpg', 'path to file2.jpg', 'path to file3.jpg']
Run Code Online (Sandbox Code Playgroud)
  1. 查找with 的name属性并将其添加为第一个参数.<input>type="file"
  2. 将文件路径添加为第二个参数.请参阅上面给出的声明.不要使用相对路径来上传文件.