【发布时间】:2016-10-17 01:34:13
【问题描述】:
我正在尝试多次调用 dropzone capybara 测试。但是,当我第二次调用它时,该 ID 已被使用。我正在尝试随机化 ID,以便它可以运行多次。
def drop_in_dropzone(file_path)
page.execute_script <<-JS
fakeFileInput = window.$('<input/>').attr(
{id: 'fakeFileInput', type:'file'}
).appendTo('body');
JS
attach_file("fakeFileInput", file_path)
page.execute_script("var fileList = [fakeFileInput.get(0).files[0]]")
page.execute_script <<-JS
var e = jQuery.Event('drop', { dataTransfer : { files : [fakeFileInput.get(0).files[0]] } });
$('.dropzone')[0].dropzone.listeners[0].events.drop(e);
JS
end
第二次调用时出错。
Failure/Error: attach_file("fakeFileInput", file_path)
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching file field "fakeFileInput"
【问题讨论】:
标签: javascript ruby-on-rails rspec capybara