1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Implement Browser#title

This commit is contained in:
Matthew Horan 2013-02-18 11:08:40 -05:00
parent 09e19e305f
commit fda0894f76
8 changed files with 46 additions and 2 deletions

View file

@ -22,6 +22,10 @@ module Capybara::Webkit
command("Header", key, value) command("Header", key, value)
end end
def title
command("Title")
end
def find(query) def find(query)
command("Find", query).split(",") command("Find", query).split(",")
end end

View file

@ -41,6 +41,10 @@ module Capybara::Webkit
browser.header(key, value) browser.header(key, value)
end end
def title
browser.title
end
def execute_script(script) def execute_script(script)
value = browser.execute_script script value = browser.execute_script script
value.empty? ? nil : value value.empty? ? nil : value

View file

@ -41,6 +41,7 @@ describe Capybara::Webkit::Driver do
<<-HTML <<-HTML
<html> <html>
<head> <head>
<title>Title</title>
<style type="text/css"> <style type="text/css">
#display_none { display: none } #display_none { display: none }
</style> </style>
@ -150,6 +151,12 @@ describe Capybara::Webkit::Driver do
driver.status_code.should == 200 driver.status_code.should == 200
end end
end end
it "returns the document title" do
driver.within_frame("f") do
driver.title.should == "Title"
end
end
end end
context "error iframe app" do context "error iframe app" do
@ -299,6 +306,7 @@ describe Capybara::Webkit::Driver do
driver_for_html(<<-HTML) driver_for_html(<<-HTML)
<html> <html>
<head> <head>
<title>Title</title>
<style type="text/css"> <style type="text/css">
#display_none { display: none } #display_none { display: none }
#visibility_hidden { visibility: hidden } #visibility_hidden { visibility: hidden }
@ -490,6 +498,10 @@ describe Capybara::Webkit::Driver do
driver.find("//*[@id='invisible']").first.should_not be_visible driver.find("//*[@id='invisible']").first.should_not be_visible
driver.find("//*[@id='invisible_with_visibility']").first.should_not be_visible driver.find("//*[@id='invisible_with_visibility']").first.should_not be_visible
end end
it "returns the document title" do
driver.title.should == "Title"
end
end end
context "svg app" do context "svg app" do

View file

@ -39,6 +39,7 @@
#include "JavascriptPromptMessages.h" #include "JavascriptPromptMessages.h"
#include "SetUrlBlacklist.h" #include "SetUrlBlacklist.h"
#include "Version.h" #include "Version.h"
#include "Title.h"
CommandFactory::CommandFactory(WebPageManager *manager, QObject *parent) : QObject(parent) { CommandFactory::CommandFactory(WebPageManager *manager, QObject *parent) : QObject(parent) {
m_manager = manager; m_manager = manager;

11
src/Title.cpp Normal file
View file

@ -0,0 +1,11 @@
#include "Title.h"
#include "WebPage.h"
#include "WebPageManager.h"
#include "NetworkAccessManager.h"
Title::Title(WebPageManager *manager, QStringList &arguments, QObject *parent) : SocketCommand(manager, arguments, parent) {
}
void Title::start() {
finish(true, page()->currentFrame()->title());
}

9
src/Title.h Normal file
View file

@ -0,0 +1,9 @@
#include "SocketCommand.h"
class Title : public SocketCommand {
Q_OBJECT
public:
Title(WebPageManager *, QStringList &arguments, QObject *parent = 0);
virtual void start();
};

View file

@ -39,5 +39,6 @@ CHECK_COMMAND(JavascriptPromptMessages)
CHECK_COMMAND(GetTimeout) CHECK_COMMAND(GetTimeout)
CHECK_COMMAND(SetTimeout) CHECK_COMMAND(SetTimeout)
CHECK_COMMAND(SetUrlBlacklist) CHECK_COMMAND(SetUrlBlacklist)
CHECK_COMMAND(Title)
CHECK_COMMAND(Version) CHECK_COMMAND(Version)

View file

@ -58,7 +58,8 @@ HEADERS = \
NoOpReply.h \ NoOpReply.h \
JsonSerializer.h \ JsonSerializer.h \
InvocationResult.h \ InvocationResult.h \
ErrorMessage.h ErrorMessage.h \
Title.h
SOURCES = \ SOURCES = \
Version.cpp \ Version.cpp \
@ -118,7 +119,8 @@ SOURCES = \
NoOpReply.cpp \ NoOpReply.cpp \
JsonSerializer.cpp \ JsonSerializer.cpp \
InvocationResult.cpp \ InvocationResult.cpp \
ErrorMessage.cpp ErrorMessage.cpp \
Title.cpp
RESOURCES = webkit_server.qrc RESOURCES = webkit_server.qrc
QT += network webkit QT += network webkit