Implement source and body. Evaluate javascript should return nil when empty
This commit is contained in:
parent
4642d338cc
commit
81ad8fd130
|
@ -37,7 +37,7 @@ class Capybara::Driver::Webkit
|
|||
end
|
||||
|
||||
def body
|
||||
source
|
||||
browser.body
|
||||
end
|
||||
|
||||
def header(key, value)
|
||||
|
@ -45,7 +45,8 @@ class Capybara::Driver::Webkit
|
|||
end
|
||||
|
||||
def execute_script(script)
|
||||
browser.execute_script script
|
||||
value = browser.execute_script script
|
||||
value.empty? ? nil : value
|
||||
end
|
||||
|
||||
def evaluate_script(script)
|
||||
|
|
|
@ -28,6 +28,10 @@ class Capybara::Driver::Webkit
|
|||
command("Reset")
|
||||
end
|
||||
|
||||
def body
|
||||
command("Body")
|
||||
end
|
||||
|
||||
def source
|
||||
command("Source")
|
||||
end
|
||||
|
|
|
@ -177,10 +177,6 @@ describe Capybara::Driver::Webkit do
|
|||
subject.source.should =~ %r{<html>.*greeting.*}m
|
||||
end
|
||||
|
||||
it "aliases body as source" do
|
||||
subject.body.should == subject.source
|
||||
end
|
||||
|
||||
it "evaluates Javascript and returns a string" do
|
||||
result = subject.evaluate_script(%<document.getElementById('greeting').innerText>)
|
||||
result.should == "hello"
|
||||
|
|
|
@ -87,5 +87,5 @@ describe Capybara::Session, "with TestApp" do
|
|||
end
|
||||
|
||||
it_should_behave_like "session"
|
||||
# it_should_behave_like "session with javascript support"
|
||||
it_should_behave_like "session with javascript support"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#include "Command.h"
|
||||
|
||||
class WebPage;
|
||||
|
||||
class Body : public Command {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Body(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
};
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
#include "FrameFocus.h"
|
||||
#include "Header.h"
|
||||
#include "Render.h"
|
||||
#include "Body.h"
|
||||
|
||||
#include <QTcpSocket>
|
||||
#include <iostream>
|
||||
|
|
|
@ -7,7 +7,14 @@ Source::Source(WebPage *page, QObject *parent) : Command(page, parent) {
|
|||
void Source::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments)
|
||||
|
||||
QString result = page()->currentFrame()->toHtml();
|
||||
emit finished(new Response(true, result));
|
||||
QNetworkAccessManager* accessManager = page()->networkAccessManager();
|
||||
QNetworkRequest request(page()->currentFrame()->url());
|
||||
reply = accessManager->get(request);
|
||||
|
||||
connect(reply, SIGNAL(finished()), this, SLOT(sourceLoaded()));
|
||||
}
|
||||
|
||||
void Source::sourceLoaded() {
|
||||
emit finished(new Response(true, reply->readAll()));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Command.h"
|
||||
|
||||
class WebPage;
|
||||
class QNetworkReply;
|
||||
|
||||
class Source : public Command {
|
||||
Q_OBJECT
|
||||
|
@ -8,5 +9,11 @@ class Source : public Command {
|
|||
public:
|
||||
Source(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
|
||||
public slots:
|
||||
void sourceLoaded();
|
||||
|
||||
private:
|
||||
QNetworkReply *reply;
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#include "Body.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Body::Body(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
}
|
||||
|
||||
void Body::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments);
|
||||
QString result = page()->currentFrame()->toHtml();
|
||||
emit finished(new Response(true, result));
|
||||
}
|
|
@ -14,3 +14,4 @@ CHECK_COMMAND(Execute)
|
|||
CHECK_COMMAND(FrameFocus)
|
||||
CHECK_COMMAND(Header)
|
||||
CHECK_COMMAND(Render)
|
||||
CHECK_COMMAND(Body)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
TEMPLATE = app
|
||||
TARGET = webkit_server
|
||||
DESTDIR = .
|
||||
HEADERS = WebPage.h Server.h Connection.h Command.h Visit.h Find.h Reset.h Node.h JavascriptInvocation.h Url.h Source.h Evaluate.h Execute.h FrameFocus.h Response.h NetworkAccessManager.h Header.h Render.h
|
||||
SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Node.cpp JavascriptInvocation.cpp Url.cpp Source.cpp Evaluate.cpp Execute.cpp FrameFocus.cpp Response.cpp NetworkAccessManager.cpp Header.cpp Render.cpp
|
||||
HEADERS = WebPage.h Server.h Connection.h Command.h Visit.h Find.h Reset.h Node.h JavascriptInvocation.h Url.h Source.h Evaluate.h Execute.h FrameFocus.h Response.h NetworkAccessManager.h Header.h Render.h body.h
|
||||
SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Node.cpp JavascriptInvocation.cpp Url.cpp Source.cpp Evaluate.cpp Execute.cpp FrameFocus.cpp Response.cpp NetworkAccessManager.cpp Header.cpp Render.cpp body.cpp
|
||||
RESOURCES = webkit_server.qrc
|
||||
QT += network webkit
|
||||
CONFIG += console
|
||||
|
|
Loading…
Reference in New Issue