0

I'm trying to simulate a dropzone image upload. I tried to follow this StackOverflow article but still not working.

How do you test uploading a file with capybara and Dropzone?

def drop_in_dropzone(file_path)
  # Generate a fake input selector
  page.execute_script <<-JS
    fakeFileInput = window.$('<input/>').attr(
      {id: 'fakeFileInput', type:'file'}
    ).appendTo('.dropzone-upload-button');
  JS
  # Attach the file to the fake input selector with Capybara
  attach_file("fakeFileInput", file_path)
  # Trigger the fake drop event
  page.execute_script <<-JS
    var fileList = [fakeFileInput.get(0).files[0]];
    var e = jQuery.Event('drop', { dataTransfer : { files : fileList } });
    $('.dropzone')[0].dropzone.listeners[0].events.drop(e);
  JS
end

Error

$(...)[0].dropzone is undefined (Selenium::WebDriver::Error::JavascriptError)
Community
  • 1
  • 1
khoamle
  • 676
  • 2
  • 7
  • 21
  • You need to set the selector for the upload input. – Florent B. Apr 11 '16 at 21:16
  • That error implies the dropzone object was never created for the '.dropzone' element. Check for any JS errors that are preventing some of your initial startup JS from running. Just because it works in dev mode doesn't mean it will in test mode, since generally in test mode JS is concatenated so an error in one source file can cause code in other source files to not be executed, whereas in dev mode it would only cause the one source JS file with the error to stop execution. – Thomas Walpole Apr 11 '16 at 21:30

0 Answers0