Implemented Node#text; refactored Node commands so that they can be easily added in Javascript
This commit is contained in:
parent
3e32892e2b
commit
63366bf614
|
@ -1,11 +1,11 @@
|
|||
class Capybara::Driver::Webkit
|
||||
class Node < Capybara::Driver::Node
|
||||
def text
|
||||
raise NotImplementedError
|
||||
invoke "text"
|
||||
end
|
||||
|
||||
def [](name)
|
||||
command "Attribute", name
|
||||
invoke "attribute", name
|
||||
end
|
||||
|
||||
def value
|
||||
|
@ -48,8 +48,8 @@ class Capybara::Driver::Webkit
|
|||
raise NotSupportedByDriverError
|
||||
end
|
||||
|
||||
def command(name, *args)
|
||||
browser.command name, native, *args
|
||||
def invoke(name, *args)
|
||||
browser.command "Node", name, native, *args
|
||||
end
|
||||
|
||||
def browser
|
||||
|
|
|
@ -42,5 +42,9 @@ describe Capybara::Driver::Webkit do
|
|||
it "parses xpath with quotes" do
|
||||
subject.find('//*[contains(., "hello")]').should_not be_empty
|
||||
end
|
||||
|
||||
it "returns a node's text" do
|
||||
subject.find("//p").first.text.should == "hello"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
#include "Attribute.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Attribute::Attribute(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
}
|
||||
|
||||
void Attribute::start(QStringList &arguments) {
|
||||
QVariant result = page()->invokeCapybaraFunction("attribute", arguments);
|
||||
QString attributeValue = result.toString();
|
||||
emit finished(true, attributeValue);
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
#include "Find.h"
|
||||
#include "Command.h"
|
||||
#include "Reset.h"
|
||||
#include "Attribute.h"
|
||||
#include "Node.h"
|
||||
|
||||
#include <QTcpSocket>
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#include "Node.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Node::Node(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
}
|
||||
|
||||
void Node::start(QStringList &arguments) {
|
||||
QStringList functionArguments(arguments);
|
||||
QString functionName = functionArguments.takeFirst();
|
||||
QVariant result = page()->invokeCapybaraFunction(functionName, functionArguments);
|
||||
QString attributeValue = result.toString();
|
||||
emit finished(true, attributeValue);
|
||||
}
|
||||
|
|
@ -3,11 +3,11 @@
|
|||
|
||||
class WebPage;
|
||||
|
||||
class Attribute : public Command {
|
||||
class Node : public Command {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Attribute(WebPage *page, QObject *parent = 0);
|
||||
Node(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
};
|
||||
|
|
@ -26,3 +26,7 @@ QVariant WebPage::invokeCapybaraFunction(const char *name, QStringList &argument
|
|||
return mainFrame()->evaluateJavaScript(javascript);
|
||||
}
|
||||
|
||||
QVariant WebPage::invokeCapybaraFunction(QString &name, QStringList &arguments) {
|
||||
return invokeCapybaraFunction(name.toAscii().data(), arguments);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ class WebPage : public QWebPage {
|
|||
public:
|
||||
WebPage(QObject *parent = 0);
|
||||
QVariant invokeCapybaraFunction(const char *name, QStringList &arguments);
|
||||
QVariant invokeCapybaraFunction(QString &name, QStringList &arguments);
|
||||
|
||||
public slots:
|
||||
bool shouldInterruptJavaScript();
|
||||
|
|
|
@ -18,6 +18,10 @@ Capybara = {
|
|||
return results.join(",");
|
||||
},
|
||||
|
||||
text: function (index) {
|
||||
return this.nodes[index].innerText;
|
||||
},
|
||||
|
||||
attribute: function (index, name) {
|
||||
return this.nodes[index].getAttribute(name);
|
||||
}
|
||||
|
|
|
@ -6,4 +6,4 @@
|
|||
CHECK_COMMAND(Visit)
|
||||
CHECK_COMMAND(Find)
|
||||
CHECK_COMMAND(Reset)
|
||||
CHECK_COMMAND(Attribute)
|
||||
CHECK_COMMAND(Node)
|
||||
|
|
|
@ -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 JavascriptInvocation.h
|
||||
SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Attribute.cpp JavascriptInvocation.cpp
|
||||
HEADERS = WebPage.h Server.h Connection.h Command.h Visit.h Find.h Reset.h Node.h JavascriptInvocation.h
|
||||
SOURCES = main.cpp WebPage.cpp Server.cpp Connection.cpp Command.cpp Visit.cpp Find.cpp Reset.cpp Node.cpp JavascriptInvocation.cpp
|
||||
RESOURCES = webkit_server.qrc
|
||||
QT += network webkit
|
||||
CONFIG += console
|
||||
|
|
Loading…
Reference in New Issue