Add error message detail for page load failure.
This makes it easier to debug "Unable to load URL" errors.
This commit is contained in:
parent
3b09429b44
commit
18655cb4e0
|
@ -104,6 +104,35 @@ describe Capybara::Driver::Webkit do
|
|||
end
|
||||
end
|
||||
|
||||
context "error iframe app" do
|
||||
before(:all) do
|
||||
@app = lambda do |env|
|
||||
case env["PATH_INFO"]
|
||||
when "/inner-not-found"
|
||||
[404, {}, []]
|
||||
when "/outer"
|
||||
body = <<-HTML
|
||||
<html>
|
||||
<body>
|
||||
<iframe src=\"/inner-not-found\"></iframe>
|
||||
</body>
|
||||
</html>
|
||||
HTML
|
||||
[200,
|
||||
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
||||
[body]]
|
||||
else
|
||||
body = "<html><body></body></html>"
|
||||
return [200, {'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s}, [body]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "raises error whose message references the actual missing url" do
|
||||
expect { subject.visit("/outer") }.to raise_error(Capybara::Driver::Webkit::WebkitInvalidResponseError, /inner-not-found/)
|
||||
end
|
||||
end
|
||||
|
||||
context "redirect app" do
|
||||
before(:all) do
|
||||
@app = lambda do |env|
|
||||
|
|
|
@ -141,6 +141,7 @@ bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString &message, const Q
|
|||
|
||||
void WebPage::loadStarted() {
|
||||
m_loading = true;
|
||||
m_errorPageMessage = QString();
|
||||
}
|
||||
|
||||
void WebPage::loadFinished(bool success) {
|
||||
|
@ -153,7 +154,11 @@ bool WebPage::isLoading() const {
|
|||
}
|
||||
|
||||
QString WebPage::failureString() {
|
||||
return QString("Unable to load URL: ") + currentFrame()->requestedUrl().toString();
|
||||
QString message = QString("Unable to load URL: ") + currentFrame()->requestedUrl().toString();
|
||||
if(m_errorPageMessage.isEmpty())
|
||||
return message;
|
||||
else
|
||||
return message + ": " + m_errorPageMessage;
|
||||
}
|
||||
|
||||
bool WebPage::render(const QString &fileName) {
|
||||
|
@ -191,12 +196,16 @@ QString WebPage::chooseFile(QWebFrame *parentFrame, const QString &suggestedFile
|
|||
}
|
||||
|
||||
bool WebPage::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) {
|
||||
Q_UNUSED(option);
|
||||
if (extension == ChooseMultipleFilesExtension) {
|
||||
QStringList names = QStringList() << getLastAttachedFileName();
|
||||
static_cast<ChooseMultipleFilesExtensionReturn*>(output)->fileNames = names;
|
||||
return true;
|
||||
}
|
||||
else if (extension == QWebPage::ErrorPageExtension) {
|
||||
ErrorPageExtensionOption *errorOption = (ErrorPageExtensionOption*) option;
|
||||
m_errorPageMessage = "Because of error loading " + errorOption->url.toString() + ": " + errorOption->errorString;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -269,3 +278,9 @@ bool WebPage::matchesWindowSelector(QString selector) {
|
|||
void WebPage::setFocus() {
|
||||
m_manager->setCurrentPage(this);
|
||||
}
|
||||
|
||||
bool WebPage::supportsExtension(Extension extension) const {
|
||||
if(extension == ErrorPageExtension) { return true; }
|
||||
else if(extension == ChooseMultipleFilesExtension) { return true; }
|
||||
else return false;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ class WebPage : public QWebPage {
|
|||
virtual bool javaScriptConfirm(QWebFrame *frame, const QString &message);
|
||||
virtual bool javaScriptPrompt(QWebFrame *frame, const QString &message, const QString &defaultValue, QString *result);
|
||||
virtual QString chooseFile(QWebFrame * parentFrame, const QString &suggestedFile);
|
||||
virtual bool supportsExtension(Extension extension) const;
|
||||
|
||||
private:
|
||||
QString m_capybaraJavascript;
|
||||
|
@ -61,6 +62,7 @@ class WebPage : public QWebPage {
|
|||
QStringList m_consoleMessages;
|
||||
QString m_uuid;
|
||||
WebPageManager *m_manager;
|
||||
QString m_errorPageMessage;
|
||||
};
|
||||
|
||||
#endif //_WEBPAGE_H
|
||||
|
|
Loading…
Reference in New Issue