Permalink
Browse files

Return element and position for ClickFailed error

  • Loading branch information...
1 parent 5dcbe9a commit 05b92c9bf0c16d20e4eb819eeb4bcaa5701ea88f @mhoran mhoran committed Feb 10, 2013
Showing with 10 additions and 5 deletions.
  1. +1 −1 lib/capybara/webkit/errors.rb
  2. +2 −2 spec/integration/session_spec.rb
  3. +7 −2 src/capybara.js
@@ -13,7 +13,7 @@ class NodeNotAttachedError < Capybara::ElementNotFound
class ClickFailed < StandardError
def self.json_create(o)
- new
+ new(o["message"])
end
end
@@ -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
@@ -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;

0 comments on commit 05b92c9

Please sign in to comment.