capybara-webkit 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -1
- data/Gemfile.lock +5 -4
- data/NEWS.md +11 -0
- data/README.md +42 -0
- data/lib/capybara/driver/webkit.rb +7 -2
- data/lib/capybara/driver/webkit/browser.rb +22 -96
- data/lib/capybara/driver/webkit/connection.rb +120 -0
- data/lib/capybara/driver/webkit/version.rb +1 -1
- data/lib/capybara/webkit/matchers.rb +2 -4
- data/lib/capybara_webkit_builder.rb +22 -4
- data/spec/browser_spec.rb +19 -29
- data/spec/connection_spec.rb +54 -0
- data/spec/driver_resize_window_spec.rb +59 -0
- data/spec/driver_spec.rb +175 -27
- data/spec/spec_helper.rb +9 -2
- data/src/Body.h +2 -2
- data/src/ClearCookies.cpp +2 -5
- data/src/ClearCookies.h +2 -2
- data/src/Command.cpp +7 -3
- data/src/Command.h +4 -2
- data/src/CommandFactory.cpp +7 -2
- data/src/CommandFactory.h +1 -1
- data/src/CommandParser.cpp +13 -5
- data/src/CommandParser.h +6 -2
- data/src/Connection.cpp +18 -47
- data/src/Connection.h +5 -7
- data/src/ConsoleMessages.cpp +2 -3
- data/src/ConsoleMessages.h +2 -2
- data/src/CurrentUrl.cpp +3 -6
- data/src/CurrentUrl.h +2 -2
- data/src/Evaluate.cpp +3 -3
- data/src/Evaluate.h +2 -2
- data/src/Execute.cpp +4 -4
- data/src/Execute.h +2 -2
- data/src/Find.cpp +4 -4
- data/src/Find.h +2 -2
- data/src/FrameFocus.cpp +7 -7
- data/src/FrameFocus.h +2 -2
- data/src/GetCookies.cpp +2 -4
- data/src/GetCookies.h +2 -2
- data/src/Header.cpp +4 -4
- data/src/Header.h +2 -2
- data/src/Headers.cpp +2 -3
- data/src/Headers.h +2 -2
- data/src/IgnoreSslErrors.cpp +12 -0
- data/src/IgnoreSslErrors.h +12 -0
- data/src/NetworkAccessManager.cpp +4 -0
- data/src/NetworkAccessManager.h +2 -1
- data/src/Node.cpp +3 -3
- data/src/Node.h +2 -2
- data/src/NullCommand.cpp +10 -0
- data/src/NullCommand.h +11 -0
- data/src/PageLoadingCommand.cpp +46 -0
- data/src/PageLoadingCommand.h +40 -0
- data/src/Render.cpp +5 -6
- data/src/Render.h +2 -2
- data/src/RequestedUrl.cpp +3 -6
- data/src/RequestedUrl.h +2 -2
- data/src/Reset.cpp +8 -7
- data/src/Reset.h +2 -2
- data/src/ResizeWindow.cpp +16 -0
- data/src/ResizeWindow.h +12 -0
- data/src/Response.cpp +6 -1
- data/src/Response.h +4 -2
- data/src/Server.cpp +2 -3
- data/src/Server.h +1 -1
- data/src/SetCookie.cpp +3 -5
- data/src/SetCookie.h +2 -2
- data/src/SetProxy.cpp +7 -9
- data/src/SetProxy.h +2 -2
- data/src/Source.cpp +2 -4
- data/src/Source.h +2 -2
- data/src/Status.cpp +2 -3
- data/src/Status.h +2 -2
- data/src/Url.cpp +3 -6
- data/src/Url.h +2 -2
- data/src/Visit.cpp +4 -13
- data/src/Visit.h +2 -5
- data/src/WebPage.cpp +11 -9
- data/src/WebPage.h +3 -3
- data/src/body.cpp +2 -3
- data/src/capybara.js +58 -3
- data/src/find_command.h +3 -1
- data/src/main.cpp +1 -2
- data/src/webkit_server.pro +8 -0
- metadata +29 -16
data/src/Evaluate.h
CHANGED
@@ -8,8 +8,8 @@ class Evaluate : public Command {
|
|
8
8
|
Q_OBJECT
|
9
9
|
|
10
10
|
public:
|
11
|
-
Evaluate(WebPage *page, QObject *parent = 0);
|
12
|
-
virtual void start(
|
11
|
+
Evaluate(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
12
|
+
virtual void start();
|
13
13
|
|
14
14
|
private:
|
15
15
|
void addVariant(QVariant &object);
|
data/src/Execute.cpp
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
#include "Execute.h"
|
2
2
|
#include "WebPage.h"
|
3
3
|
|
4
|
-
Execute::Execute(WebPage *page, QObject *parent) : Command(page, parent) {
|
4
|
+
Execute::Execute(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
5
5
|
}
|
6
6
|
|
7
|
-
void Execute::start(
|
8
|
-
QString script = arguments[0] + QString("; 'success'");
|
7
|
+
void Execute::start() {
|
8
|
+
QString script = arguments()[0] + QString("; 'success'");
|
9
9
|
QVariant result = page()->currentFrame()->evaluateJavaScript(script);
|
10
10
|
if (result.isValid()) {
|
11
11
|
emit finished(new Response(true));
|
12
12
|
} else {
|
13
|
-
emit finished(new Response(false, "Javascript failed to execute"));
|
13
|
+
emit finished(new Response(false, QString("Javascript failed to execute")));
|
14
14
|
}
|
15
15
|
}
|
16
16
|
|
data/src/Execute.h
CHANGED
data/src/Find.cpp
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
#include "Command.h"
|
3
3
|
#include "WebPage.h"
|
4
4
|
|
5
|
-
Find::Find(WebPage *page, QObject *parent) : Command(page, parent) {
|
5
|
+
Find::Find(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
6
6
|
}
|
7
7
|
|
8
|
-
void Find::start(
|
8
|
+
void Find::start() {
|
9
9
|
QString message;
|
10
|
-
QVariant result = page()->invokeCapybaraFunction("find", arguments);
|
10
|
+
QVariant result = page()->invokeCapybaraFunction("find", arguments());
|
11
11
|
|
12
12
|
if (result.isValid()) {
|
13
13
|
message = result.toString();
|
14
14
|
emit finished(new Response(true, message));
|
15
15
|
} else {
|
16
|
-
emit finished(new Response(false, "Invalid XPath expression"));
|
16
|
+
emit finished(new Response(false, QString("Invalid XPath expression")));
|
17
17
|
}
|
18
18
|
}
|
19
19
|
|
data/src/Find.h
CHANGED
data/src/FrameFocus.cpp
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
#include "Command.h"
|
3
3
|
#include "WebPage.h"
|
4
4
|
|
5
|
-
FrameFocus::FrameFocus(WebPage *page, QObject *parent) : Command(page, parent) {
|
5
|
+
FrameFocus::FrameFocus(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
6
6
|
}
|
7
7
|
|
8
|
-
void FrameFocus::start(
|
8
|
+
void FrameFocus::start() {
|
9
9
|
findFrames();
|
10
|
-
switch(arguments.length()) {
|
10
|
+
switch(arguments().length()) {
|
11
11
|
case 1:
|
12
|
-
focusId(arguments[0]);
|
12
|
+
focusId(arguments()[0]);
|
13
13
|
break;
|
14
14
|
case 2:
|
15
|
-
focusIndex(arguments[1].toInt());
|
15
|
+
focusIndex(arguments()[1].toInt());
|
16
16
|
break;
|
17
17
|
default:
|
18
18
|
focusParent();
|
@@ -50,7 +50,7 @@ void FrameFocus::focusId(QString name) {
|
|
50
50
|
|
51
51
|
void FrameFocus::focusParent() {
|
52
52
|
if (page()->currentFrame()->parentFrame() == 0) {
|
53
|
-
emit finished(new Response(false, "Already at parent frame."));
|
53
|
+
emit finished(new Response(false, QString("Already at parent frame.")));
|
54
54
|
} else {
|
55
55
|
page()->currentFrame()->parentFrame()->setFocus();
|
56
56
|
success();
|
@@ -58,7 +58,7 @@ void FrameFocus::focusParent() {
|
|
58
58
|
}
|
59
59
|
|
60
60
|
void FrameFocus::frameNotFound() {
|
61
|
-
emit finished(new Response(false, "Unable to locate frame. "));
|
61
|
+
emit finished(new Response(false, QString("Unable to locate frame. ")));
|
62
62
|
}
|
63
63
|
|
64
64
|
void FrameFocus::success() {
|
data/src/FrameFocus.h
CHANGED
@@ -7,8 +7,8 @@ class FrameFocus : public Command {
|
|
7
7
|
Q_OBJECT
|
8
8
|
|
9
9
|
public:
|
10
|
-
FrameFocus(WebPage *page, QObject *parent = 0);
|
11
|
-
virtual void start(
|
10
|
+
FrameFocus(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
11
|
+
virtual void start();
|
12
12
|
|
13
13
|
private:
|
14
14
|
void findFrames();
|
data/src/GetCookies.cpp
CHANGED
@@ -2,15 +2,13 @@
|
|
2
2
|
#include "WebPage.h"
|
3
3
|
#include "NetworkCookieJar.h"
|
4
4
|
|
5
|
-
GetCookies::GetCookies(WebPage *page, QObject *parent)
|
6
|
-
: Command(page, parent)
|
5
|
+
GetCookies::GetCookies(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent)
|
7
6
|
{
|
8
7
|
m_buffer = "";
|
9
8
|
}
|
10
9
|
|
11
|
-
void GetCookies::start(
|
10
|
+
void GetCookies::start()
|
12
11
|
{
|
13
|
-
Q_UNUSED(arguments);
|
14
12
|
NetworkCookieJar *jar = qobject_cast<NetworkCookieJar*>(page()
|
15
13
|
->networkAccessManager()
|
16
14
|
->cookieJar());
|
data/src/GetCookies.h
CHANGED
@@ -6,8 +6,8 @@ class GetCookies : public Command {
|
|
6
6
|
Q_OBJECT;
|
7
7
|
|
8
8
|
public:
|
9
|
-
GetCookies(WebPage *page, QObject *parent = 0);
|
10
|
-
virtual void start(
|
9
|
+
GetCookies(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
10
|
+
virtual void start();
|
11
11
|
|
12
12
|
private:
|
13
13
|
QString m_buffer;
|
data/src/Header.cpp
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
#include "WebPage.h"
|
3
3
|
#include "NetworkAccessManager.h"
|
4
4
|
|
5
|
-
Header::Header(WebPage *page, QObject *parent) : Command(page, parent) {
|
5
|
+
Header::Header(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
6
6
|
}
|
7
7
|
|
8
|
-
void Header::start(
|
9
|
-
QString key = arguments[0];
|
10
|
-
QString value = arguments[1];
|
8
|
+
void Header::start() {
|
9
|
+
QString key = arguments()[0];
|
10
|
+
QString value = arguments()[1];
|
11
11
|
NetworkAccessManager* networkAccessManager = qobject_cast<NetworkAccessManager*>(page()->networkAccessManager());
|
12
12
|
if (key.toLower().replace("-", "_") == "user_agent") {
|
13
13
|
page()->setUserAgent(value);
|
data/src/Header.h
CHANGED
data/src/Headers.cpp
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
#include "Headers.h"
|
2
2
|
#include "WebPage.h"
|
3
3
|
|
4
|
-
Headers::Headers(WebPage *page, QObject *parent) : Command(page, parent) {
|
4
|
+
Headers::Headers(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
5
5
|
}
|
6
6
|
|
7
|
-
void Headers::start(
|
8
|
-
Q_UNUSED(arguments);
|
7
|
+
void Headers::start() {
|
9
8
|
emit finished(new Response(true, page()->pageHeaders()));
|
10
9
|
}
|
11
10
|
|
data/src/Headers.h
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
#include "IgnoreSslErrors.h"
|
2
|
+
#include "WebPage.h"
|
3
|
+
|
4
|
+
IgnoreSslErrors::IgnoreSslErrors(WebPage *page, QStringList &arguments, QObject *parent) :
|
5
|
+
Command(page, arguments, parent) {
|
6
|
+
}
|
7
|
+
|
8
|
+
void IgnoreSslErrors::start() {
|
9
|
+
page()->ignoreSslErrors();
|
10
|
+
emit finished(new Response(true));
|
11
|
+
}
|
12
|
+
|
data/src/NetworkAccessManager.h
CHANGED
@@ -9,10 +9,11 @@ class NetworkAccessManager : public QNetworkAccessManager {
|
|
9
9
|
public:
|
10
10
|
NetworkAccessManager(QObject *parent = 0);
|
11
11
|
void addHeader(QString key, QString value);
|
12
|
+
void resetHeaders();
|
12
13
|
|
13
14
|
protected:
|
14
15
|
QNetworkReply* createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice * outgoingData);
|
15
16
|
|
16
17
|
private:
|
17
18
|
QHash<QString, QString> m_headers;
|
18
|
-
};
|
19
|
+
};
|
data/src/Node.cpp
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#include "Node.h"
|
2
2
|
#include "WebPage.h"
|
3
3
|
|
4
|
-
Node::Node(WebPage *page, QObject *parent) : Command(page, parent) {
|
4
|
+
Node::Node(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
5
5
|
}
|
6
6
|
|
7
|
-
void Node::start(
|
8
|
-
QStringList functionArguments(arguments);
|
7
|
+
void Node::start() {
|
8
|
+
QStringList functionArguments(arguments());
|
9
9
|
QString functionName = functionArguments.takeFirst();
|
10
10
|
QVariant result = page()->invokeCapybaraFunction(functionName, functionArguments);
|
11
11
|
QString attributeValue = result.toString();
|
data/src/Node.h
CHANGED
data/src/NullCommand.cpp
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#include "NullCommand.h"
|
2
|
+
#include "WebPage.h"
|
3
|
+
|
4
|
+
NullCommand::NullCommand(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
|
5
|
+
|
6
|
+
void NullCommand::start() {
|
7
|
+
QString failure = QString("[Capybara WebKit] Unknown command: ") + arguments()[0] + "\n";
|
8
|
+
emit finished(new Response(false, failure));
|
9
|
+
}
|
10
|
+
|
data/src/NullCommand.h
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#include "PageLoadingCommand.h"
|
2
|
+
#include "Command.h"
|
3
|
+
#include "WebPage.h"
|
4
|
+
|
5
|
+
PageLoadingCommand::PageLoadingCommand(Command *command, WebPage *page, QObject *parent) : QObject(parent) {
|
6
|
+
m_page = page;
|
7
|
+
m_command = command;
|
8
|
+
m_pageLoadingFromCommand = false;
|
9
|
+
m_pageSuccess = true;
|
10
|
+
m_pendingResponse = NULL;
|
11
|
+
connect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
12
|
+
connect(m_page, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
13
|
+
}
|
14
|
+
|
15
|
+
void PageLoadingCommand::start() {
|
16
|
+
connect(m_command, SIGNAL(finished(Response *)), this, SLOT(commandFinished(Response *)));
|
17
|
+
m_command->start();
|
18
|
+
};
|
19
|
+
|
20
|
+
void PageLoadingCommand::pendingLoadFinished(bool success) {
|
21
|
+
m_pageSuccess = success;
|
22
|
+
if (m_pageLoadingFromCommand) {
|
23
|
+
m_pageLoadingFromCommand = false;
|
24
|
+
if (m_pendingResponse) {
|
25
|
+
if (m_pageSuccess) {
|
26
|
+
emit finished(m_pendingResponse);
|
27
|
+
} else {
|
28
|
+
QString message = m_page->failureString();
|
29
|
+
emit finished(new Response(false, message));
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
void PageLoadingCommand::pageLoadingFromCommand() {
|
36
|
+
m_pageLoadingFromCommand = true;
|
37
|
+
}
|
38
|
+
|
39
|
+
void PageLoadingCommand::commandFinished(Response *response) {
|
40
|
+
disconnect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
41
|
+
m_command->deleteLater();
|
42
|
+
if (m_pageLoadingFromCommand)
|
43
|
+
m_pendingResponse = response;
|
44
|
+
else
|
45
|
+
emit finished(response);
|
46
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#include <QObject>
|
2
|
+
#include <QStringList>
|
3
|
+
|
4
|
+
class Command;
|
5
|
+
class Response;
|
6
|
+
class WebPage;
|
7
|
+
|
8
|
+
/*
|
9
|
+
* Decorates a Command by deferring the finished() signal until any pending
|
10
|
+
* page loads are complete.
|
11
|
+
*
|
12
|
+
* If a Command starts a page load, no signal will be emitted until the page
|
13
|
+
* load is finished.
|
14
|
+
*
|
15
|
+
* If a pending page load fails, the command's response will be discarded and a
|
16
|
+
* failure response will be emitted instead.
|
17
|
+
*/
|
18
|
+
class PageLoadingCommand : public QObject {
|
19
|
+
Q_OBJECT
|
20
|
+
|
21
|
+
public:
|
22
|
+
PageLoadingCommand(Command *command, WebPage *page, QObject *parent = 0);
|
23
|
+
void start();
|
24
|
+
|
25
|
+
public slots:
|
26
|
+
void pageLoadingFromCommand();
|
27
|
+
void pendingLoadFinished(bool success);
|
28
|
+
void commandFinished(Response *response);
|
29
|
+
|
30
|
+
signals:
|
31
|
+
void finished(Response *response);
|
32
|
+
|
33
|
+
private:
|
34
|
+
WebPage *m_page;
|
35
|
+
Command *m_command;
|
36
|
+
Response *m_pendingResponse;
|
37
|
+
bool m_pageSuccess;
|
38
|
+
bool m_pageLoadingFromCommand;
|
39
|
+
};
|
40
|
+
|
data/src/Render.cpp
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
#include "Render.h"
|
2
2
|
#include "WebPage.h"
|
3
3
|
|
4
|
-
Render::Render(WebPage *page, QObject *parent) : Command(page, parent) {
|
4
|
+
Render::Render(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
5
5
|
}
|
6
6
|
|
7
|
-
void Render::start(
|
8
|
-
|
9
|
-
|
10
|
-
int
|
11
|
-
int height = functionArguments.takeFirst().toInt();
|
7
|
+
void Render::start() {
|
8
|
+
QString imagePath = arguments()[0];
|
9
|
+
int width = arguments()[1].toInt();
|
10
|
+
int height = arguments()[2].toInt();
|
12
11
|
|
13
12
|
QSize size(width, height);
|
14
13
|
page()->setViewportSize(size);
|
data/src/Render.h
CHANGED
data/src/RequestedUrl.cpp
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
#include "RequestedUrl.h"
|
2
2
|
#include "WebPage.h"
|
3
3
|
|
4
|
-
RequestedUrl::RequestedUrl(WebPage *page, QObject *parent) : Command(page, parent) {
|
4
|
+
RequestedUrl::RequestedUrl(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
5
5
|
}
|
6
6
|
|
7
|
-
void RequestedUrl::start(
|
8
|
-
Q_UNUSED(arguments);
|
9
|
-
|
7
|
+
void RequestedUrl::start() {
|
10
8
|
QUrl humanUrl = page()->currentFrame()->requestedUrl();
|
11
9
|
QByteArray encodedBytes = humanUrl.toEncoded();
|
12
|
-
|
13
|
-
emit finished(new Response(true, urlString));
|
10
|
+
emit finished(new Response(true, encodedBytes));
|
14
11
|
}
|
15
12
|
|