Skip to content

Instantly share code, notes, and snippets.

@mrdanadams
Created March 30, 2013 02:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrdanadams/5275065 to your computer and use it in GitHub Desktop.
Save mrdanadams/5275065 to your computer and use it in GitHub Desktop.
Triggering custom events with capybara-webkit using jQuery $.trigger
def trigger(selector, name, options={})
# if you return the default object capybara tries to parse the jquery object
page.evaluate_script("$('#{selector}').trigger(jQuery.Event('#{name}', #{options.to_json})); undefined")
end
it 'triggers a couple events' do
# Ex: lets simulate a drag and drop
trigger '.canvas', :mousedown, {pageX:200, pageY:300}
trigger '.canvas', :mousemove, {pageX:400, pageY:400}
trigger '.canvas', :mouseup
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment