mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge pull request #953 from molfar/master
Add #title method to Capybara::Node::Document
This commit is contained in:
commit
02d12899a0
7 changed files with 42 additions and 1 deletions
|
@ -20,6 +20,10 @@ module Capybara
|
|||
def text
|
||||
find(:xpath, '/html').text
|
||||
end
|
||||
|
||||
def title
|
||||
session.driver.title
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -89,6 +89,10 @@ class Capybara::RackTest::Browser
|
|||
rescue Rack::Test::Error
|
||||
""
|
||||
end
|
||||
|
||||
def title
|
||||
dom.xpath("//title").text
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
##
|
||||
#
|
||||
|
|
16
lib/capybara/spec/session/title_spec.rb
Normal file
16
lib/capybara/spec/session/title_spec.rb
Normal 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
|
1
lib/capybara/spec/views/with_title.erb
Normal file
1
lib/capybara/spec/views/with_title.erb
Normal file
|
@ -0,0 +1 @@
|
|||
<title>Test Title</title>
|
Loading…
Add table
Reference in a new issue