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
|
end
|
||||||
|
|
||||||
def body
|
def body
|
||||||
source
|
browser.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def header(key, value)
|
def header(key, value)
|
||||||
|
@ -45,7 +45,8 @@ class Capybara::Driver::Webkit
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_script(script)
|
def execute_script(script)
|
||||||
browser.execute_script script
|
value = browser.execute_script script
|
||||||
|
value.empty? ? nil : value
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate_script(script)
|
def evaluate_script(script)
|
||||||
|
@ -98,7 +99,7 @@ class Capybara::Driver::Webkit
|
||||||
def server_port
|
def server_port
|
||||||
@rack_server.port
|
@rack_server.port
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def url(path)
|
def url(path)
|
||||||
|
|
|
@ -28,6 +28,10 @@ class Capybara::Driver::Webkit
|
||||||
command("Reset")
|
command("Reset")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def body
|
||||||
|
command("Body")
|
||||||
|
end
|
||||||
|
|
||||||
def source
|
def source
|
||||||
command("Source")
|
command("Source")
|
||||||
end
|
end
|
||||||
|
|
|
@ -177,10 +177,6 @@ describe Capybara::Driver::Webkit do
|
||||||
subject.source.should =~ %r{<html>.*greeting.*}m
|
subject.source.should =~ %r{<html>.*greeting.*}m
|
||||||
end
|
end
|
||||||
|
|
||||||
it "aliases body as source" do
|
|
||||||
subject.body.should == subject.source
|
|
||||||
end
|
|
||||||
|
|
||||||
it "evaluates Javascript and returns a string" do
|
it "evaluates Javascript and returns a string" do
|
||||||
result = subject.evaluate_script(%<document.getElementById('greeting').innerText>)
|
result = subject.evaluate_script(%<document.getElementById('greeting').innerText>)
|
||||||
result.should == "hello"
|
result.should == "hello"
|
||||||
|
|
|
@ -87,5 +87,5 @@ describe Capybara::Session, "with TestApp" do
|
||||||
end
|
end
|
||||||
|
|
||||||
it_should_behave_like "session"
|
it_should_behave_like "session"
|
||||||
# it_should_behave_like "session with javascript support"
|
it_should_behave_like "session with javascript support"
|
||||||
end
|
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 "FrameFocus.h"
|
||||||
#include "Header.h"
|
#include "Header.h"
|
||||||
#include "Render.h"
|
#include "Render.h"
|
||||||
|
#include "Body.h"
|
||||||
|
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
|
@ -7,7 +7,14 @@ Source::Source(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||||
void Source::start(QStringList &arguments) {
|
void Source::start(QStringList &arguments) {
|
||||||
Q_UNUSED(arguments)
|
Q_UNUSED(arguments)
|
||||||
|
|
||||||
QString result = page()->currentFrame()->toHtml();
|
QNetworkAccessManager* accessManager = page()->networkAccessManager();
|
||||||
emit finished(new Response(true, result));
|
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"
|
#include "Command.h"
|
||||||
|
|
||||||
class WebPage;
|
class WebPage;
|
||||||
|
class QNetworkReply;
|
||||||
|
|
||||||
class Source : public Command {
|
class Source : public Command {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -8,5 +9,11 @@ class Source : public Command {
|
||||||
public:
|
public:
|
||||||
Source(WebPage *page, QObject *parent = 0);
|
Source(WebPage *page, QObject *parent = 0);
|
||||||
virtual void start(QStringList &arguments);
|
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(FrameFocus)
|
||||||
CHECK_COMMAND(Header)
|
CHECK_COMMAND(Header)
|
||||||
CHECK_COMMAND(Render)
|
CHECK_COMMAND(Render)
|
||||||
|
CHECK_COMMAND(Body)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
TARGET = webkit_server
|
TARGET = webkit_server
|
||||||
DESTDIR = .
|
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
|
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
|
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
|
RESOURCES = webkit_server.qrc
|
||||||
QT += network webkit
|
QT += network webkit
|
||||||
CONFIG += console
|
CONFIG += console
|
||||||
|
|
Loading…
Reference in New Issue