Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Return element and position for ClickFailed error

  • Loading branch information...
commit 05b92c9bf0c16d20e4eb819eeb4bcaa5701ea88f 1 parent 5dcbe9a
@mhoran mhoran authored
View
2  lib/capybara/webkit/errors.rb
@@ -13,7 +13,7 @@ class NodeNotAttachedError < Capybara::ElementNotFound
class ClickFailed < StandardError
def self.json_create(o)
- new
+ new(o["message"])
end
end
View
4 spec/integration/session_spec.rb
@@ -400,7 +400,7 @@ module TestSessions
lambda {
subject.find(:css, '#one').click
- }.should raise_error(Capybara::Webkit::ClickFailed)
+ }.should raise_error(Capybara::Webkit::ClickFailed, /\[@id='one'\] at position/)
end
it 'raises an error if a checkbox is obscured when checked' do
@@ -424,7 +424,7 @@ module TestSessions
it 'raises an error if an element is not visible when clicked' do
subject.visit('/')
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
it 'raises an error if an element is not in the viewport when clicked' do
View
9 src/capybara.js
@@ -136,7 +136,7 @@ Capybara = {
if (pos && this.clickTest(node, pos))
CapybaraInvocation.click(pos.absoluteX, pos.absoluteY);
else
- throw new Capybara.ClickFailed();
+ throw new Capybara.ClickFailed(this.path(index), pos);
},
trigger: function (index, eventName) {
@@ -359,8 +359,13 @@ Capybara = {
}
};
-Capybara.ClickFailed = function() {
+Capybara.ClickFailed = function(path, position) {
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.constructor = Capybara.ClickFailed;
Please sign in to comment.
Something went wrong with that request. Please try again.