diff --git a/lib/capybara/driver/node.rb b/lib/capybara/driver/node.rb index 7ecf8739..8cc2eeff 100644 --- a/lib/capybara/driver/node.rb +++ b/lib/capybara/driver/node.rb @@ -40,7 +40,15 @@ module Capybara def click raise NotImplementedError end - + + def right_click + raise NotImplmentedError + end + + def double_click + raise NotImplementedError + end + def hover raise NotImplementedError end diff --git a/lib/capybara/node/element.rb b/lib/capybara/node/element.rb index 9b77fd53..3eb693ed 100644 --- a/lib/capybara/node/element.rb +++ b/lib/capybara/node/element.rb @@ -118,6 +118,22 @@ module Capybara synchronize { base.click } end + ## + # + # Right Click the Element + # + def right_click + synchronize { base.right_click } + end + + ## + # + # Double Click the Element + # + def double_click + synchronize { base.double_click } + end + ## # # Hover on the Element diff --git a/lib/capybara/selenium/node.rb b/lib/capybara/selenium/node.rb index 1de5bbee..33840b42 100644 --- a/lib/capybara/selenium/node.rb +++ b/lib/capybara/selenium/node.rb @@ -57,6 +57,14 @@ class Capybara::Selenium::Node < Capybara::Driver::Node def click native.click end + + def right_click + driver.browser.action.context_click(native).perform + end + + def double_click + driver.browser.action.double_click(native).perform + end def hover driver.browser.action.move_to(native).perform diff --git a/lib/capybara/spec/public/test.js b/lib/capybara/spec/public/test.js index 5980e6d7..89390ff1 100644 --- a/lib/capybara/spec/public/test.js +++ b/lib/capybara/spec/public/test.js @@ -60,4 +60,11 @@ $(function() { $('title').text('changed title') }, 250) }); + $('#click-test').dblclick(function() { + $(this).after('Has been double clicked'); + }); + $('#click-test').bind('contextmenu', function(e) { + e.preventDefault(); + $(this).after('Has been right clicked'); + }); }); diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index c015c8e7..08ace5c4 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -185,6 +185,22 @@ Capybara::SpecHelper.spec "node" do @session.find(:css, '.hidden_until_hover', :visible => false).should be_visible end end + + describe '#double_click', :requires => [:js] do + it "should double click an element" do + @session.visit('/with_js') + @session.find(:css, '#click-test').double_click + @session.find(:css, '#has-been-double-clicked').should be + end + end + + describe '#right_click', :requires => [:js] do + it "should double click an element" do + @session.visit('/with_js') + @session.find(:css, '#click-test').right_click + @session.find(:css, '#has-been-right-clicked').should be + end + end describe '#reload', :requires => [:js] do context "without automatic reload" do diff --git a/lib/capybara/spec/views/with_js.erb b/lib/capybara/spec/views/with_js.erb index 1fdb2284..82336ed4 100644 --- a/lib/capybara/spec/views/with_js.erb +++ b/lib/capybara/spec/views/with_js.erb @@ -61,6 +61,8 @@

Change title

+ +

Click me