Return element and position for ClickFailed error

This commit is contained in:
Matthew Horan 2013-02-09 21:04:51 -05:00
parent 5dcbe9a0a4
commit 05b92c9bf0
3 changed files with 10 additions and 5 deletions

View File

@ -13,7 +13,7 @@ module Capybara::Webkit
class ClickFailed < StandardError
def self.json_create(o)
new
new(o["message"])
end
end

View File

@ -400,7 +400,7 @@ describe Capybara::Session do
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 @@ describe Capybara::Session do
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 File

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