Skip to content

Instantly share code, notes, and snippets.

@vumanhcuongit
Last active January 29, 2021 02:10
Show Gist options
  • Save vumanhcuongit/4df16452d88fda4c05bf to your computer and use it in GitHub Desktop.
Save vumanhcuongit/4df16452d88fda4c05bf to your computer and use it in GitHub Desktop.
Drag & Drop Cucumber
When /^I drag the file "([^\"]*)" to "([^\"]*)"$/ do |file, field|
# make an input field be visible
page.execute_script("document.getElementsByName('#{field}')[0].className = '';") # remove class .hidden
page.execute_script("document.getElementsByName('#{field}')[0].setAttribute('style', 'display:block;')") # remove style="display: none;"
patiently do
attach_file(field, File.expand_path(file)) # attach file to input
end
draggable = page.find(".topMenu") # whatever
droppable = page.find("##{field}") # an input where we'll drag file into
draggable.drag_to(droppable) # f*cking awesome
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment