0
我想多次調用一個dropzone水豚測試。但是,當我第二次打電話時,該ID已被使用。我試圖隨機化ID,以便它可以運行多次。重構水豚javascript dropzone測試
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"