Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add double_click and right_click to element - support in selenium #1079

Merged
merged 1 commit into from
Nov 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/capybara/driver/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ def unselect_option
def click
raise NotImplementedError
end


def right_click
raise NotImplmentedError
end

def double_click
raise NotImplementedError
end

def hover
raise NotImplementedError
end
Expand Down
16 changes: 16 additions & 0 deletions lib/capybara/node/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ def click
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
Expand Down
8 changes: 8 additions & 0 deletions lib/capybara/selenium/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def unselect_option
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
Expand Down
7 changes: 7 additions & 0 deletions lib/capybara/spec/public/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>');
});
});
16 changes: 16 additions & 0 deletions lib/capybara/spec/session/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,22 @@
@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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double click or right click? 😊

@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
Expand Down
2 changes: 2 additions & 0 deletions lib/capybara/spec/views/with_js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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
Expand Down