diff --git a/lib/capybara/webkit/browser.rb b/lib/capybara/webkit/browser.rb index f282466..fff423d 100644 --- a/lib/capybara/webkit/browser.rb +++ b/lib/capybara/webkit/browser.rb @@ -59,7 +59,7 @@ module Capybara::Webkit end def prompt_messages - command("JavascriptPromptMessages").split("\n") + JSON.parse(command("JavascriptPromptMessages")) end def response_headers diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index a15cf32..473b140 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -700,6 +700,12 @@ describe Capybara::Webkit::Driver do driver.find("//input").first.click driver.console_messages.first[:message].should == "goodbye" end + + it "supports multi-line prompt messages" do + driver.execute_script("prompt('Hello\\nnewline')") + driver.prompt_messages.first.should == "Hello\nnewline" + end + end end diff --git a/src/JavascriptPromptMessages.cpp b/src/JavascriptPromptMessages.cpp index 234d743..0144f3b 100644 --- a/src/JavascriptPromptMessages.cpp +++ b/src/JavascriptPromptMessages.cpp @@ -1,10 +1,13 @@ #include "JavascriptPromptMessages.h" #include "WebPage.h" #include "WebPageManager.h" +#include "JsonSerializer.h" JavascriptPromptMessages::JavascriptPromptMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {} void JavascriptPromptMessages::start() { - emitFinished(true, page()->promptMessages()); + JsonSerializer serializer; + QByteArray json = serializer.serialize(page()->promptMessages()); + emitFinished(true, json); } diff --git a/src/WebPage.cpp b/src/WebPage.cpp index 8852269..ca6c6d7 100644 --- a/src/WebPage.cpp +++ b/src/WebPage.cpp @@ -95,8 +95,8 @@ QVariantList WebPage::confirmMessages() { return m_confirmMessages; } -QString WebPage::promptMessages() { - return m_promptMessages.join("\n"); +QVariantList WebPage::promptMessages() { + return m_promptMessages; } void WebPage::setUserAgent(QString userAgent) { diff --git a/src/WebPage.h b/src/WebPage.h index b8d23ad..d470391 100644 --- a/src/WebPage.h +++ b/src/WebPage.h @@ -26,7 +26,7 @@ class WebPage : public QWebPage { QVariantList consoleMessages(); QVariantList alertMessages(); QVariantList confirmMessages(); - QString promptMessages(); + QVariantList promptMessages(); void resetWindowSize(); QWebPage *createWindow(WebWindowType type); QString uuid(); @@ -75,7 +75,7 @@ class WebPage : public QWebPage { QVariantList m_alertMessages; QVariantList m_confirmMessages; QString m_prompt_text; - QStringList m_promptMessages; + QVariantList m_promptMessages; QString m_uuid; WebPageManager *m_manager; QString m_errorPageMessage;