diff --git a/lib/capybara/driver/webkit.rb b/lib/capybara/driver/webkit.rb index be74c5d..785835b 100644 --- a/lib/capybara/driver/webkit.rb +++ b/lib/capybara/driver/webkit.rb @@ -17,7 +17,7 @@ class Capybara::Driver::Webkit end def current_url - raise NotImplementedError + browser.url end def visit(path) diff --git a/lib/capybara/driver/webkit/browser.rb b/lib/capybara/driver/webkit/browser.rb index 8c9f4e8..5eb2f0e 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 url + command("Url") + end + def command(name, *args) @socket.puts name args.each { |arg| @socket.puts arg } diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 136ad9c..99313fb 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -18,7 +18,7 @@ describe Capybara::Driver::Webkit do end subject { Capybara::Driver::Webkit.new(hello_app) } - before { subject.visit("/hello") } + before { subject.visit("/hello/world?success=true") } after { subject.reset! } it "finds content after loading a URL" do @@ -38,5 +38,10 @@ describe Capybara::Driver::Webkit do it "returns an attribute's value" do subject.find("//p").first["id"].should == "greeting" end + + it "returns the current URL" do + port = subject.instance_variable_get("@rack_server").port + subject.current_url.should == "http://127.0.0.1:#{port}/hello/world?success=true" + end end diff --git a/src/Connection.cpp b/src/Connection.cpp index d2cef2a..80a045b 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -4,6 +4,7 @@ #include "Command.h" #include "Reset.h" #include "Attribute.h" +#include "Url.h" #include #include diff --git a/src/Url.cpp b/src/Url.cpp new file mode 100644 index 0000000..cc0b734 --- /dev/null +++ b/src/Url.cpp @@ -0,0 +1,12 @@ +#include "Url.h" +#include "WebPage.h" + +Url::Url(WebPage *page, QObject *parent) : Command(page, parent) { +} + +void Url::start() { + QString response = page()->mainFrame()->url().toString(); + + emit finished(true, response); +} + diff --git a/src/Url.h b/src/Url.h new file mode 100644 index 0000000..cc81467 --- /dev/null +++ b/src/Url.h @@ -0,0 +1,12 @@ +#include "Command.h" + +class WebPage; + +class Url : public Command { + Q_OBJECT + + public: + Url(WebPage *page, QObject *parent = 0); + virtual void start(); +}; + diff --git a/src/find_command.h b/src/find_command.h index ade631c..472cb6a 100644 --- a/src/find_command.h +++ b/src/find_command.h @@ -6,4 +6,5 @@ CHECK_COMMAND(Visit) CHECK_COMMAND(Find) CHECK_COMMAND(Reset) -CHECK_COMMAND(Attribute) \ No newline at end of file +CHECK_COMMAND(Attribute) +CHECK_COMMAND(Url) diff --git a/src/webkit_server.pro b/src/webkit_server.pro index 58c198c..7dc3775 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 -SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Attribute.cpp +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 QT += network webkit CONFIG += console staticlib