Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement source and body. Evaluate javascript should return nil when…

… empty
  • Loading branch information...
commit 81ad8fd130437149d843191893550160cd6ec6c3 1 parent 4642d33
@halogenandtoast halogenandtoast authored
View
7 lib/capybara/driver/webkit.rb
@@ -37,7 +37,7 @@ def source
end
def body
- source
+ browser.body
end
def header(key, value)
@@ -45,7 +45,8 @@ def header(key, value)
end
def execute_script(script)
- browser.execute_script script
+ value = browser.execute_script script
+ value.empty? ? nil : value
end
def evaluate_script(script)
@@ -98,7 +99,7 @@ def render(path, options={})
def server_port
@rack_server.port
end
-
+
private
def url(path)
View
4 lib/capybara/driver/webkit/browser.rb
@@ -28,6 +28,10 @@ def reset!
command("Reset")
end
+ def body
+ command("Body")
+ end
+
def source
command("Source")
end
View
4 spec/driver_spec.rb
@@ -177,10 +177,6 @@
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"
View
2  spec/integration/session_spec.rb
@@ -87,5 +87,5 @@
end
it_should_behave_like "session"
- # it_should_behave_like "session with javascript support"
+ it_should_behave_like "session with javascript support"
end
View
12 src/Body.h
@@ -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);
+};
+
View
1  src/Connection.cpp
@@ -12,6 +12,7 @@
#include "FrameFocus.h"
#include "Header.h"
#include "Render.h"
+#include "Body.h"
#include <QTcpSocket>
#include <iostream>
View
11 src/Source.cpp
@@ -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()));
}
View
7 src/Source.h
@@ -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;
};
View
11 src/body.cpp
@@ -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));
+}
View
1  src/find_command.h
@@ -14,3 +14,4 @@ CHECK_COMMAND(Execute)
CHECK_COMMAND(FrameFocus)
CHECK_COMMAND(Header)
CHECK_COMMAND(Render)
+CHECK_COMMAND(Body)
View
4 src/webkit_server.pro
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.