Save a screenshot when raising a ClickFailed exception
* Prints the path to the file * Make it easier to debug what was actually clicked
This commit is contained in:
parent
0f89db1825
commit
76a362c664
|
@ -415,12 +415,15 @@ describe Capybara::Session do
|
||||||
two.style.top = '0px';
|
two.style.top = '0px';
|
||||||
JS
|
JS
|
||||||
|
|
||||||
lambda {
|
expect {
|
||||||
subject.find(:css, '#one').click
|
subject.find(:css, '#one').click
|
||||||
}.should raise_error(
|
}.to raise_error(Capybara::Webkit::ClickFailed) { |exception|
|
||||||
Capybara::Webkit::ClickFailed,
|
exception.message.should =~ %r{Failed.*\[@id='one'\].*overlapping.*\[@id='two'\].*at position}
|
||||||
/Failed.*\[@id='one'\].*overlapping.*\[@id='two'\].*at position/
|
screenshot_pattern = %r{A screenshot of the page at the time of the failure has been written to (.*)}
|
||||||
)
|
exception.message.should =~ screenshot_pattern
|
||||||
|
file = exception.message.match(screenshot_pattern)[1]
|
||||||
|
File.exist?(file).should be_true
|
||||||
|
}
|
||||||
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
|
||||||
|
|
|
@ -139,3 +139,14 @@ void JavascriptInvocation::keypress(QChar key) {
|
||||||
event = QKeyEvent(QKeyEvent::KeyRelease, keyCode, Qt::NoModifier, key);
|
event = QKeyEvent(QKeyEvent::KeyRelease, keyCode, Qt::NoModifier, key);
|
||||||
QApplication::sendEvent(m_page, &event);
|
QApplication::sendEvent(m_page, &event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString JavascriptInvocation::render(void) {
|
||||||
|
QString pathTemplate =
|
||||||
|
QDir::temp().absoluteFilePath("./click_failed_XXXXXX.png");
|
||||||
|
QTemporaryFile file(pathTemplate);
|
||||||
|
file.open();
|
||||||
|
file.setAutoRemove(false);
|
||||||
|
QString path = file.fileName();
|
||||||
|
m_page->render(path, QSize(1024, 768));
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ class JavascriptInvocation : public QObject {
|
||||||
Q_INVOKABLE QVariantMap clickPosition(QWebElement element, int left, int top, int width, int height);
|
Q_INVOKABLE QVariantMap clickPosition(QWebElement element, int left, int top, int width, int height);
|
||||||
Q_INVOKABLE void hover(int absoluteX, int absoluteY);
|
Q_INVOKABLE void hover(int absoluteX, int absoluteY);
|
||||||
Q_INVOKABLE void keypress(QChar);
|
Q_INVOKABLE void keypress(QChar);
|
||||||
|
Q_INVOKABLE const QString render(void);
|
||||||
QVariant getError();
|
QVariant getError();
|
||||||
void setError(QVariant error);
|
void setError(QVariant error);
|
||||||
InvocationResult invoke(QWebFrame *);
|
InvocationResult invoke(QWebFrame *);
|
||||||
|
|
|
@ -376,6 +376,7 @@ Capybara.ClickFailed = function(expectedPath, actualPath, position) {
|
||||||
this.message += ' at position ' + position["absoluteX"] + ', ' + position["absoluteY"];
|
this.message += ' at position ' + position["absoluteX"] + ', ' + position["absoluteY"];
|
||||||
else
|
else
|
||||||
this.message += ' at unknown position';
|
this.message += ' at unknown position';
|
||||||
|
this.message += "; \nA screenshot of the page at the time of the failure has been written to " + CapybaraInvocation.render();
|
||||||
};
|
};
|
||||||
Capybara.ClickFailed.prototype = new Error();
|
Capybara.ClickFailed.prototype = new Error();
|
||||||
Capybara.ClickFailed.prototype.constructor = Capybara.ClickFailed;
|
Capybara.ClickFailed.prototype.constructor = Capybara.ClickFailed;
|
||||||
|
|
Loading…
Reference in New Issue