Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
add error message detail for page load failure
Browse files Browse the repository at this point in the history
to easily debug "Unable to load URL" errors.
  • Loading branch information
Joshua Napoli committed Apr 4, 2012
1 parent 5831441 commit 142047c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
29 changes: 29 additions & 0 deletions spec/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,35 @@
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|
Expand Down
19 changes: 17 additions & 2 deletions src/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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) {
Expand All @@ -134,7 +135,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) {
Expand Down Expand Up @@ -172,12 +177,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;
}

Expand Down Expand Up @@ -235,3 +244,9 @@ void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
UnsupportedContentHandler *handler = new UnsupportedContentHandler(this, reply);
Q_UNUSED(handler);
}

bool WebPage::supportsExtension(Extension extension) const {
if(extension == ErrorPageExtension) { return true; }
else if(extension == ChooseMultipleFilesExtension) { return true; }
else return false;
}
2 changes: 2 additions & 0 deletions src/WebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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;
Expand All @@ -53,5 +54,6 @@ class WebPage : public QWebPage {
QString m_pageHeaders;
bool m_ignoreSslErrors;
QStringList m_consoleMessages;
QString m_errorPageMessage;
};

0 comments on commit 142047c

Please sign in to comment.