【问题标题】:How to test multiple file upload using Cucumber/Capybara?如何使用 Cucumber/Capybara 测试多个文件上传?
【发布时间】:2012-03-12 12:53:58
【问题描述】:

我可以测试一个文件的上传

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

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

【问题讨论】:

    标签: ruby-on-rails cucumber capybara


    【解决方案1】:

    HTML:

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

    水豚:

    page.attach_file "images", ['path to file1.jpg', 'path to file2.jpg', 'path to file3.jpg']
    
    1. type="file" 查找&lt;input&gt;name 属性并将其添加为第一个参数。
    2. 添加文件as the second parameter的路径。请参阅上面给出的声明。不要使用相对路径上传文件。

    【讨论】:

    • 这应该是公认的答案。简单而且有效。
    【解决方案2】:

    目前看来,Capybara 是不可能的:

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

    【讨论】:

    • 这个答案当时是正确的,但我认为@user2391218 有新的正确答案。
    猜你喜欢
    • 1970-01-01
    • 2013-05-19
    • 2017-05-14
    • 2015-12-29
    • 2013-08-26
    • 2018-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多