diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index c705b5e..636b747 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -2341,6 +2341,63 @@ describe Capybara::Webkit::Driver do end end + context 'Qt debug error app' do + let(:app) do + Class.new(Sinatra::Base) do + get '/' do + <<-HTML + + +
Loading
+ + + + HTML + end + + post '/ajax' do + 'Complete' + end + end + end + + it 'silences Qt debug messages' do + visit '/' + wait_for_ajax_request + log.should eq('') + end + + def wait_for_ajax_request + driver.find_css('#target').first.text.should eq('Complete') + end + + let(:driver) do + run_application app + connection = Capybara::Webkit::Connection.new(:stderr => output) + browser = Capybara::Webkit::Browser.new(connection) + Capybara::Webkit::Driver.new(AppRunner.app, :browser => browser) + end + + let(:output) { StringIO.new } + + def log + output.rewind + output.read + end + end + def driver_url(driver, path) URI.parse(driver.current_url).merge(path).to_s end diff --git a/src/WebPageManager.cpp b/src/WebPageManager.cpp index 1c32d00..3ba9aac 100644 --- a/src/WebPageManager.cpp +++ b/src/WebPageManager.cpp @@ -130,10 +130,11 @@ bool WebPageManager::isLoading() const { } QDebug WebPageManager::logger() const { - if (m_loggingEnabled) - return qDebug(); - else + if (m_loggingEnabled) { + return qCritical(); + } else { return QDebug(m_ignoredOutput); + } } void WebPageManager::enableLogging() { diff --git a/src/main.cpp b/src/main.cpp index 0d923d9..9cefa67 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,12 @@ #include #endif +void ignoreDebugOutput(QtMsgType type, const char *msg); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + void ignoreDebugOutputQt5(QtMsgType type, const QMessageLogContext &context, const QString &message); +#endif + int main(int argc, char **argv) { #ifdef Q_OS_UNIX if (setpgid(0, 0) < 0) { @@ -18,6 +24,12 @@ int main(int argc, char **argv) { app.setOrganizationName("thoughtbot, inc"); app.setOrganizationDomain("thoughtbot.com"); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + qInstallMessageHandler(ignoreDebugOutputQt5); +#else + qInstallMsgHandler(ignoreDebugOutput); +#endif + Server server(0); if (server.start()) { @@ -29,3 +41,20 @@ int main(int argc, char **argv) { } } +void ignoreDebugOutput(QtMsgType type, const char *msg) { + switch (type) { + case QtDebugMsg: + case QtWarningMsg: + break; + default: + fprintf(stderr, "%s\n", msg); + break; + } +} + +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + void ignoreDebugOutputQt5(QtMsgType type, const QMessageLogContext &context, const QString &message) { + Q_UNUSED(context); + ignoreDebugOutput(type, message.toLocal8Bit().data()); + } +#endif