Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Add command to retrieve URL modified by Javascript
Browse files Browse the repository at this point in the history
If I use pushState to change the URL Browser#current_url still returns
the URL as it was after the original request. This commit adds a command
for RequestedUrl, which is the QtWebkit method for retrieving a URL
modified by Javascript or a redirect.
  • Loading branch information
joefiorini committed Nov 16, 2011
1 parent 6ba9dcb commit 89f2cf0
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/capybara/driver/webkit.rb
Expand Up @@ -30,6 +30,10 @@ def current_url
browser.url
end

def requested_url
browser.requested_url
end

def visit(path)
browser.visit(url(path))
end
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/driver/webkit/browser.rb
Expand Up @@ -53,6 +53,10 @@ def url
command("Url")
end

def requested_url
command("RequestedUrl")
end

def frame_focus(frame_id_or_index=nil)
if frame_id_or_index.is_a? Fixnum
command("FrameFocus", "", frame_id_or_index.to_s)
Expand Down
5 changes: 5 additions & 0 deletions spec/browser_spec.rb
Expand Up @@ -168,6 +168,11 @@
browser.url.should == @url
end

it 'uses URLs changed by javascript' do
browser.execute_script "window.history.pushState('', '', '/blah')"
browser.requested_url.should == 'http://example.org/blah'
end

it 'is possible to disable proxy again' do
@proxy_requests.clear
browser.clear_proxy
Expand Down
1 change: 1 addition & 0 deletions src/CommandFactory.cpp
Expand Up @@ -18,6 +18,7 @@
#include "ClearCookies.h"
#include "GetCookies.h"
#include "SetProxy.h"
#include "RequestedUrl.h"

CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent) {
m_page = page;
Expand Down
15 changes: 15 additions & 0 deletions src/RequestedUrl.cpp
@@ -0,0 +1,15 @@
#include "RequestedUrl.h"
#include "WebPage.h"

RequestedUrl::RequestedUrl(WebPage *page, QObject *parent) : Command(page, parent) {
}

void RequestedUrl::start(QStringList &arguments) {
Q_UNUSED(arguments);

QUrl humanUrl = page()->currentFrame()->requestedUrl();
QByteArray encodedBytes = humanUrl.toEncoded();
QString urlString = QString(encodedBytes);
emit finished(new Response(true, urlString));
}

12 changes: 12 additions & 0 deletions src/RequestedUrl.h
@@ -0,0 +1,12 @@
#include "Command.h"

class WebPage;

class RequestedUrl : public Command {
Q_OBJECT

public:
RequestedUrl(WebPage *page, QObject *parent = 0);
virtual void start(QStringList &arguments);
};

1 change: 1 addition & 0 deletions src/find_command.h
Expand Up @@ -22,3 +22,4 @@ CHECK_COMMAND(ClearCookies)
CHECK_COMMAND(GetCookies)
CHECK_COMMAND(Headers)
CHECK_COMMAND(SetProxy)
CHECK_COMMAND(RequestedUrl)
6 changes: 6 additions & 0 deletions src/webkit_server.pro
Expand Up @@ -2,6 +2,7 @@ TEMPLATE = app
TARGET = webkit_server
DESTDIR = .
HEADERS = \
RequestedUrl.h \
WebPage.h \
Server.h \
Connection.h \
Expand Down Expand Up @@ -33,6 +34,11 @@ HEADERS = \
SetProxy.h \

SOURCES = \
<<<<<<< HEAD
=======
RequestedUrl.cpp \
ConsoleMessages.cpp \
>>>>>>> 3d0768c... Add command to retrieve URL modified by Javascript
main.cpp \
WebPage.cpp \
Server.cpp \
Expand Down

0 comments on commit 89f2cf0

Please sign in to comment.