1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Support multi-line prompt messages

This commit is contained in:
Matthew Horan 2012-12-30 15:04:44 -05:00
parent 2f9d76bfbb
commit 8a8d12af5c
5 changed files with 15 additions and 6 deletions

View file

@ -59,7 +59,7 @@ module Capybara::Webkit
end end
def prompt_messages def prompt_messages
command("JavascriptPromptMessages").split("\n") JSON.parse(command("JavascriptPromptMessages"))
end end
def response_headers def response_headers

View file

@ -700,6 +700,12 @@ describe Capybara::Webkit::Driver do
driver.find("//input").first.click driver.find("//input").first.click
driver.console_messages.first[:message].should == "goodbye" driver.console_messages.first[:message].should == "goodbye"
end end
it "supports multi-line prompt messages" do
driver.execute_script("prompt('Hello\\nnewline')")
driver.prompt_messages.first.should == "Hello\nnewline"
end
end end
end end

View file

@ -1,10 +1,13 @@
#include "JavascriptPromptMessages.h" #include "JavascriptPromptMessages.h"
#include "WebPage.h" #include "WebPage.h"
#include "WebPageManager.h" #include "WebPageManager.h"
#include "JsonSerializer.h"
JavascriptPromptMessages::JavascriptPromptMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {} JavascriptPromptMessages::JavascriptPromptMessages(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {}
void JavascriptPromptMessages::start() void JavascriptPromptMessages::start()
{ {
emitFinished(true, page()->promptMessages()); JsonSerializer serializer;
QByteArray json = serializer.serialize(page()->promptMessages());
emitFinished(true, json);
} }

View file

@ -95,8 +95,8 @@ QVariantList WebPage::confirmMessages() {
return m_confirmMessages; return m_confirmMessages;
} }
QString WebPage::promptMessages() { QVariantList WebPage::promptMessages() {
return m_promptMessages.join("\n"); return m_promptMessages;
} }
void WebPage::setUserAgent(QString userAgent) { void WebPage::setUserAgent(QString userAgent) {

View file

@ -26,7 +26,7 @@ class WebPage : public QWebPage {
QVariantList consoleMessages(); QVariantList consoleMessages();
QVariantList alertMessages(); QVariantList alertMessages();
QVariantList confirmMessages(); QVariantList confirmMessages();
QString promptMessages(); QVariantList promptMessages();
void resetWindowSize(); void resetWindowSize();
QWebPage *createWindow(WebWindowType type); QWebPage *createWindow(WebWindowType type);
QString uuid(); QString uuid();
@ -75,7 +75,7 @@ class WebPage : public QWebPage {
QVariantList m_alertMessages; QVariantList m_alertMessages;
QVariantList m_confirmMessages; QVariantList m_confirmMessages;
QString m_prompt_text; QString m_prompt_text;
QStringList m_promptMessages; QVariantList m_promptMessages;
QString m_uuid; QString m_uuid;
WebPageManager *m_manager; WebPageManager *m_manager;
QString m_errorPageMessage; QString m_errorPageMessage;