Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Return element and position for ClickFailed error
Browse files Browse the repository at this point in the history
  • Loading branch information
mhoran committed Feb 11, 2013
1 parent 5dcbe9a commit 05b92c9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/capybara/webkit/errors.rb
Expand Up @@ -13,7 +13,7 @@ class NodeNotAttachedError < Capybara::ElementNotFound


class ClickFailed < StandardError class ClickFailed < StandardError
def self.json_create(o) def self.json_create(o)
new new(o["message"])
end end
end end


Expand Down
4 changes: 2 additions & 2 deletions spec/integration/session_spec.rb
Expand Up @@ -400,7 +400,7 @@ module TestSessions


lambda { lambda {
subject.find(:css, '#one').click subject.find(:css, '#one').click
}.should raise_error(Capybara::Webkit::ClickFailed) }.should raise_error(Capybara::Webkit::ClickFailed, /\[@id='one'\] at position/)
end end


it 'raises an error if a checkbox is obscured when checked' do it 'raises an error if a checkbox is obscured when checked' do
Expand All @@ -424,7 +424,7 @@ module TestSessions
it 'raises an error if an element is not visible when clicked' do it 'raises an error if an element is not visible when clicked' do
subject.visit('/') subject.visit('/')
subject.execute_script "document.getElementById('foo').style.display = 'none'" subject.execute_script "document.getElementById('foo').style.display = 'none'"
lambda { subject.click_link "Click Me" }.should raise_error(Capybara::Webkit::ClickFailed) lambda { subject.click_link "Click Me" }.should raise_error(Capybara::Webkit::ClickFailed, /\[@id='foo'\] at unknown/)
end end


it 'raises an error if an element is not in the viewport when clicked' do it 'raises an error if an element is not in the viewport when clicked' do
Expand Down
9 changes: 7 additions & 2 deletions src/capybara.js
Expand Up @@ -136,7 +136,7 @@ Capybara = {
if (pos && this.clickTest(node, pos)) if (pos && this.clickTest(node, pos))
CapybaraInvocation.click(pos.absoluteX, pos.absoluteY); CapybaraInvocation.click(pos.absoluteX, pos.absoluteY);
else else
throw new Capybara.ClickFailed(); throw new Capybara.ClickFailed(this.path(index), pos);
}, },


trigger: function (index, eventName) { trigger: function (index, eventName) {
Expand Down Expand Up @@ -359,8 +359,13 @@ Capybara = {
} }
}; };


Capybara.ClickFailed = function() { Capybara.ClickFailed = function(path, position) {
this.name = 'Capybara.ClickFailed'; this.name = 'Capybara.ClickFailed';
this.message = 'Failed to click element ' + path;
if (position)
this.message += ' at position ' + position["absoluteX"] + ', ' + position["absoluteY"];
else
this.message += ' at unknown position';
}; };
Capybara.ClickFailed.prototype = new Error(); Capybara.ClickFailed.prototype = new Error();
Capybara.ClickFailed.prototype.constructor = Capybara.ClickFailed; Capybara.ClickFailed.prototype.constructor = Capybara.ClickFailed;

0 comments on commit 05b92c9

Please sign in to comment.