Merge pull request #1079 from twalpole/double_click

Add double_click and right_click to element - support in selenium
This commit is contained in:
Jonas Nicklas 2013-11-25 17:05:15 -08:00
commit 081aba7e23
6 changed files with 58 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -70,6 +70,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

View File

@ -60,4 +60,11 @@ $(function() {
$('title').text('changed title')
}, 250)
});
$('#click-test').dblclick(function() {
$(this).after('<a id="has-been-double-clicked" href="#">Has been double clicked</a>');
});
$('#click-test').bind('contextmenu', function(e) {
e.preventDefault();
$(this).after('<a id="has-been-right-clicked" href="#">Has been right clicked</a>');
});
});

View File

@ -220,6 +220,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

View File

@ -69,6 +69,8 @@
<p>
<a href="#" id="change-title">Change title</a>
</p>
<p id="click-test">Click me</p>
<script type="text/javascript">
// a javascript comment