Raise WebkitError for invalid XPath expressions
This commit is contained in:
parent
742092713a
commit
d84f5c9a2e
|
@ -3,6 +3,9 @@ require "capybara/driver/webkit/node"
|
|||
require "capybara/driver/webkit/browser"
|
||||
|
||||
class Capybara::Driver::Webkit
|
||||
class WebkitError < StandardError
|
||||
end
|
||||
|
||||
def initialize(app, options={})
|
||||
@app = app
|
||||
@options = options
|
||||
|
|
|
@ -44,7 +44,7 @@ class Capybara::Driver::Webkit
|
|||
result = @socket.gets.strip
|
||||
puts ">> #{result}"
|
||||
unless result == 'ok'
|
||||
raise
|
||||
raise WebkitError, read_response
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -18,17 +18,21 @@ describe Capybara::Driver::Webkit do
|
|||
end
|
||||
|
||||
subject { Capybara::Driver::Webkit.new(hello_app) }
|
||||
before { subject.visit("/hello") }
|
||||
after { subject.reset! }
|
||||
|
||||
it "finds content after loading a URL" do
|
||||
subject.visit("/hello")
|
||||
subject.find("//*[contains(., 'hello')]").should_not be_empty
|
||||
end
|
||||
|
||||
it "has an empty page after reseting" do
|
||||
subject.visit("/")
|
||||
subject.reset!
|
||||
subject.find("//*[contains(., 'hello')]").should be_empty
|
||||
end
|
||||
|
||||
it "raises an error for an invalid xpath query" do
|
||||
expect { subject.find("totally invalid salad") }.
|
||||
to raise_error(Capybara::Driver::Webkit::WebkitError, /xpath/i)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -64,11 +64,11 @@ void Connection::finishCommand(bool success, QString &response) {
|
|||
m_command = NULL;
|
||||
if (success) {
|
||||
m_socket->write("ok\n");
|
||||
QString responseLength = QString::number(response.size()) + "\n";
|
||||
m_socket->write(responseLength.toAscii());
|
||||
m_socket->write(response.toAscii());
|
||||
} else {
|
||||
m_socket->write("failure\n");
|
||||
}
|
||||
QString responseLength = QString::number(response.size()) + "\n";
|
||||
m_socket->write(responseLength.toAscii());
|
||||
m_socket->write(response.toAscii());
|
||||
}
|
||||
|
||||
|
|
35
src/Find.cpp
35
src/Find.cpp
|
@ -34,24 +34,29 @@ void Find::receivedArgument(const char *xpath) {
|
|||
std::cout << "<< Javascript to execute:" << std::endl;
|
||||
std::cout << javascript.toAscii().data() << std::endl;
|
||||
|
||||
QString response;
|
||||
QVariant result = page()->mainFrame()->evaluateJavaScript(javascript);
|
||||
|
||||
QVariantList nodes = result.toList();
|
||||
QString response;
|
||||
bool addComma = false;
|
||||
if (result.isValid()) {
|
||||
QVariantList nodes = result.toList();
|
||||
bool addComma = false;
|
||||
|
||||
double node;
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
node = nodes[i].toDouble();
|
||||
if (addComma)
|
||||
response.append(",");
|
||||
response.append(QString::number(node));
|
||||
addComma = true;
|
||||
double node;
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
node = nodes[i].toDouble();
|
||||
if (addComma)
|
||||
response.append(",");
|
||||
response.append(QString::number(node));
|
||||
addComma = true;
|
||||
}
|
||||
|
||||
std::cout << "<< Got result:" << std::endl;
|
||||
std::cout << response.toAscii().data() << std::endl;
|
||||
|
||||
emit finished(true, response);
|
||||
} else {
|
||||
response = "Invalid XPath expression";
|
||||
emit finished(false, response);
|
||||
}
|
||||
|
||||
std::cout << "<< Got result:" << std::endl;
|
||||
std::cout << response.toAscii().data() << std::endl;
|
||||
|
||||
emit finished(true, response);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue