Add #title method to Capybara::Node::Document

This commit is contained in:
molfar 2013-02-06 21:36:55 +02:00
parent 8368069cfd
commit 8df6ed16ec
7 changed files with 42 additions and 1 deletions

View File

@ -20,6 +20,10 @@ module Capybara
def text
find(:xpath, '/html').text
end
def title
session.driver.title
end
end
end
end

View File

@ -89,6 +89,10 @@ class Capybara::RackTest::Browser
rescue Rack::Test::Error
""
end
def title
dom.xpath("//title").text
end
protected

View File

@ -73,6 +73,10 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
def dom
browser.dom
end
def title
browser.title
end
def reset!
@browser = nil

View File

@ -38,6 +38,10 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
browser.page_source
end
def title
browser.title
end
def current_url
browser.current_url
end

View File

@ -37,7 +37,7 @@ module Capybara
:has_no_unchecked_field?, :query, :assert_selector, :assert_no_selector
]
SESSION_METHODS = [
:body, :html, :current_url, :current_host, :evaluate_script, :source,
:body, :html, :current_url, :current_host, :evaluate_script, :source, :title,
:visit, :within, :within_fieldset, :within_table, :within_frame,
:within_window, :current_path, :save_page, :save_and_open_page,
:save_screenshot, :reset_session!, :response_headers, :status_code
@ -136,6 +136,14 @@ module Capybara
def current_url
driver.current_url
end
##
#
# @return [String] Title of the current page
#
def title
driver.title
end
##
#

View File

@ -0,0 +1,16 @@
Capybara::SpecHelper.spec '#title' do
it "should print the title of the page" do
@session.visit('/with_title')
@session.title.should == 'Test Title'
end
context "with css as default selector" do
before { Capybara.default_selector = :css }
it "should print the title of the page" do
@session.visit('/with_title')
@session.title.should == 'Test Title'
end
after { Capybara.default_selector = :xpath }
end
end

View File

@ -0,0 +1 @@
<title>Test Title</title>