diff --git a/lib/capybara/driver/webkit.rb b/lib/capybara/driver/webkit.rb
index 785835b..e18516f 100644
--- a/lib/capybara/driver/webkit.rb
+++ b/lib/capybara/driver/webkit.rb
@@ -29,7 +29,7 @@ class Capybara::Driver::Webkit
end
def source
- raise NotImplementedError
+ browser.source
end
def body
diff --git a/lib/capybara/driver/webkit/browser.rb b/lib/capybara/driver/webkit/browser.rb
index 5eb2f0e..dae1c4f 100644
--- a/lib/capybara/driver/webkit/browser.rb
+++ b/lib/capybara/driver/webkit/browser.rb
@@ -19,6 +19,10 @@ class Capybara::Driver::Webkit
command("Reset")
end
+ def source
+ command("Source")
+ end
+
def url
command("Url")
end
diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb
index 99313fb..455ab74 100644
--- a/spec/driver_spec.rb
+++ b/spec/driver_spec.rb
@@ -43,5 +43,14 @@ describe Capybara::Driver::Webkit do
port = subject.instance_variable_get("@rack_server").port
subject.current_url.should == "http://127.0.0.1:#{port}/hello/world?success=true"
end
+
+ it "returns the source code for the page" do
+ subject.source.should == %{
+ hello
+
+}
+ end
end
diff --git a/src/Connection.cpp b/src/Connection.cpp
index 80a045b..7b28bc4 100644
--- a/src/Connection.cpp
+++ b/src/Connection.cpp
@@ -5,6 +5,7 @@
#include "Reset.h"
#include "Attribute.h"
#include "Url.h"
+#include "Source.h"
#include
#include
diff --git a/src/Source.cpp b/src/Source.cpp
new file mode 100644
index 0000000..28256f5
--- /dev/null
+++ b/src/Source.cpp
@@ -0,0 +1,12 @@
+#include "Source.h"
+#include "WebPage.h"
+
+Source::Source(WebPage *page, QObject *parent) : Command(page, parent) {
+}
+
+void Source::start() {
+ QString response = page()->mainFrame()->toHtml();
+
+ emit finished(true, response);
+}
+
diff --git a/src/Source.h b/src/Source.h
new file mode 100644
index 0000000..81b4439
--- /dev/null
+++ b/src/Source.h
@@ -0,0 +1,12 @@
+#include "Command.h"
+
+class WebPage;
+
+class Source : public Command {
+ Q_OBJECT
+
+ public:
+ Source(WebPage *page, QObject *parent = 0);
+ virtual void start();
+};
+
diff --git a/src/find_command.h b/src/find_command.h
index 472cb6a..6916da5 100644
--- a/src/find_command.h
+++ b/src/find_command.h
@@ -8,3 +8,4 @@ CHECK_COMMAND(Find)
CHECK_COMMAND(Reset)
CHECK_COMMAND(Attribute)
CHECK_COMMAND(Url)
+CHECK_COMMAND(Source)
\ No newline at end of file
diff --git a/src/webkit_server.pro b/src/webkit_server.pro
index 7dc3775..2ddcf8b 100644
--- a/src/webkit_server.pro
+++ b/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 Attribute.h Url.h
-SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Attribute.cpp Url.cpp
+HEADERS = WebPage.h Server.h Connection.h Command.h Visit.h Find.h Reset.h Attribute.h Url.h Source.h
+SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Attribute.cpp Url.cpp Source.cpp
QT += network webkit
CONFIG += console staticlib