commit
e330e88a5e
|
@ -16,7 +16,7 @@ module Capybara
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :asset_root, :app_host, :run_server, :default_host, :always_include_port
|
attr_accessor :asset_root, :app_host, :run_server, :default_host, :always_include_port
|
||||||
attr_accessor :server_host, :server_port
|
attr_accessor :server_host, :server_port, :exact, :match
|
||||||
attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements
|
attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements
|
||||||
attr_accessor :save_and_open_page_path, :automatic_reload
|
attr_accessor :save_and_open_page_path, :automatic_reload
|
||||||
attr_writer :default_driver, :current_driver, :javascript_driver, :session_name
|
attr_writer :default_driver, :current_driver, :javascript_driver, :session_name
|
||||||
|
@ -344,6 +344,8 @@ Capybara.configure do |config|
|
||||||
config.ignore_hidden_elements = true
|
config.ignore_hidden_elements = true
|
||||||
config.default_host = "http://www.example.com"
|
config.default_host = "http://www.example.com"
|
||||||
config.automatic_reload = true
|
config.automatic_reload = true
|
||||||
|
config.match = :smart
|
||||||
|
config.exact = false
|
||||||
end
|
end
|
||||||
|
|
||||||
Capybara.register_driver :rack_test do |app|
|
Capybara.register_driver :rack_test do |app|
|
||||||
|
|
|
@ -23,7 +23,22 @@ module Capybara
|
||||||
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
|
# @raise [Capybara::ElementNotFound] If the element can't be found before time expires
|
||||||
#
|
#
|
||||||
def find(*args)
|
def find(*args)
|
||||||
synchronize { all(*args).find! }.tap(&:allow_reload!)
|
synchronize do
|
||||||
|
query = Capybara::Query.new(*args)
|
||||||
|
if query.match == :smart or query.match == :prefer_exact
|
||||||
|
result = resolve_query(query, true)
|
||||||
|
result = resolve_query(query, false) if result.size == 0 and not query.exact
|
||||||
|
else
|
||||||
|
result = resolve_query(query)
|
||||||
|
end
|
||||||
|
if query.match == :one or query.match == :smart and result.size > 1
|
||||||
|
raise Capybara::Ambiguous.new("Ambiguous match, found #{result.size} elements matching #{query.description}")
|
||||||
|
end
|
||||||
|
if result.size == 0
|
||||||
|
raise Capybara::ElementNotFound.new("Unable to find #{query.description}")
|
||||||
|
end
|
||||||
|
result.first
|
||||||
|
end.tap(&:allow_reload!)
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -108,13 +123,7 @@ module Capybara
|
||||||
# @return [Capybara::Result] A collection of found elements
|
# @return [Capybara::Result] A collection of found elements
|
||||||
#
|
#
|
||||||
def all(*args)
|
def all(*args)
|
||||||
query = Capybara::Query.new(*args)
|
resolve_query(Capybara::Query.new(*args))
|
||||||
elements = synchronize do
|
|
||||||
base.find(query.xpath).map do |node|
|
|
||||||
Capybara::Node::Element.new(session, node, self, query)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Capybara::Result.new(elements, query)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -131,6 +140,17 @@ module Capybara
|
||||||
def first(*args)
|
def first(*args)
|
||||||
all(*args).first
|
all(*args).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def resolve_query(query, exact=nil)
|
||||||
|
elements = synchronize do
|
||||||
|
base.find(query.xpath(exact)).map do |node|
|
||||||
|
Capybara::Node::Element.new(session, node, self, query)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Capybara::Result.new(elements, query)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -139,9 +139,10 @@ module Capybara
|
||||||
yield # simple nodes don't need to wait
|
yield # simple nodes don't need to wait
|
||||||
end
|
end
|
||||||
|
|
||||||
def all(*args)
|
private
|
||||||
query = Capybara::Query.new(*args)
|
|
||||||
elements = native.xpath(query.xpath).map do |node|
|
def resolve_query(query, exact=nil)
|
||||||
|
elements = native.xpath(query.xpath(exact)).map do |node|
|
||||||
self.class.new(node)
|
self.class.new(node)
|
||||||
end
|
end
|
||||||
Capybara::Result.new(elements, query)
|
Capybara::Result.new(elements, query)
|
||||||
|
|
|
@ -2,7 +2,7 @@ module Capybara
|
||||||
class Query
|
class Query
|
||||||
attr_accessor :selector, :locator, :options, :xpath, :find, :negative
|
attr_accessor :selector, :locator, :options, :xpath, :find, :negative
|
||||||
|
|
||||||
VALID_KEYS = [:text, :visible, :between, :count, :maximum, :minimum]
|
VALID_KEYS = [:text, :visible, :between, :count, :maximum, :minimum, :exact, :match]
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
@options = if args.last.is_a?(Hash) then args.pop.dup else {} end
|
@options = if args.last.is_a?(Hash) then args.pop.dup else {} end
|
||||||
|
@ -11,6 +11,14 @@ module Capybara
|
||||||
@options[:visible] = Capybara.ignore_hidden_elements
|
@options[:visible] = Capybara.ignore_hidden_elements
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless options.has_key?(:exact)
|
||||||
|
@options[:exact] = Capybara.exact
|
||||||
|
end
|
||||||
|
|
||||||
|
unless options.has_key?(:match)
|
||||||
|
@options[:match] = Capybara.match
|
||||||
|
end
|
||||||
|
|
||||||
if args[0].is_a?(Symbol)
|
if args[0].is_a?(Symbol)
|
||||||
@selector = Selector.all[args[0]]
|
@selector = Selector.all[args[0]]
|
||||||
@locator = args[1]
|
@locator = args[1]
|
||||||
|
@ -20,8 +28,7 @@ module Capybara
|
||||||
end
|
end
|
||||||
@selector ||= Selector.all[Capybara.default_selector]
|
@selector ||= Selector.all[Capybara.default_selector]
|
||||||
|
|
||||||
@xpath = @selector.call(@locator).to_s
|
@xpath = @selector.call(@locator)
|
||||||
|
|
||||||
assert_valid_keys!
|
assert_valid_keys!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,6 +70,24 @@ module Capybara
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def exact
|
||||||
|
@options[:exact]
|
||||||
|
end
|
||||||
|
|
||||||
|
def match
|
||||||
|
@options[:match]
|
||||||
|
end
|
||||||
|
|
||||||
|
def xpath(exact=nil)
|
||||||
|
exact = @options[:exact] if exact == nil
|
||||||
|
|
||||||
|
if @xpath.respond_to?(:to_xpath) and exact
|
||||||
|
@xpath.to_xpath(:exact)
|
||||||
|
else
|
||||||
|
@xpath.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def assert_valid_keys!
|
def assert_valid_keys!
|
||||||
|
|
|
@ -35,19 +35,6 @@ module Capybara
|
||||||
@query.matches_count?(@result.size)
|
@query.matches_count?(@result.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find!
|
|
||||||
raise find_error if @result.size != 1
|
|
||||||
@result.first
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_error
|
|
||||||
if @result.size == 0
|
|
||||||
Capybara::ElementNotFound.new("Unable to find #{@query.description}")
|
|
||||||
elsif @result.size > 1
|
|
||||||
Capybara::Ambiguous.new("Ambiguous match, found #{size} elements matching #{@query.description}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def failure_message
|
def failure_message
|
||||||
message = if @query.options[:count]
|
message = if @query.options[:count]
|
||||||
"expected #{@query.description} to be found #{@query.options[:count]} #{declension("time", "times", @query.options[:count])}"
|
"expected #{@query.description} to be found #{@query.options[:count]} #{declension("time", "times", @query.options[:count])}"
|
||||||
|
|
|
@ -48,22 +48,23 @@ Capybara::SpecHelper.spec "#all" do
|
||||||
@session.all('h1').first.text.should == 'This is a test'
|
@session.all('h1').first.text.should == 'This is a test'
|
||||||
@session.all("input[id='test_field']").first[:value].should == 'monkey'
|
@session.all("input[id='test_field']").first[:value].should == 'monkey'
|
||||||
end
|
end
|
||||||
after { Capybara.default_selector = :xpath }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with visible filter" do
|
context "with visible filter" do
|
||||||
after { Capybara.ignore_hidden_elements = true }
|
it "should only find visible nodes when true" do
|
||||||
it "should only find visible nodes" do
|
|
||||||
@session.all(:css, "a.simple").should have(1).elements
|
|
||||||
Capybara.ignore_hidden_elements = false
|
|
||||||
@session.all(:css, "a.simple").should have(2).elements
|
|
||||||
@session.all(:css, "a.simple", :visible => true).should have(1).elements
|
@session.all(:css, "a.simple", :visible => true).should have(1).elements
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should only find invisible nodes" do
|
it "should find nodes regardless of whether they are invisible when false" do
|
||||||
Capybara.ignore_hidden_elements = true
|
|
||||||
@session.all(:css, "a.simple", :visible => false).should have(2).elements
|
@session.all(:css, "a.simple", :visible => false).should have(2).elements
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should default to Capybara.ignore_hidden_elements" do
|
||||||
|
Capybara.ignore_hidden_elements = true
|
||||||
|
@session.all(:css, "a.simple").should have(1).elements
|
||||||
|
Capybara.ignore_hidden_elements = false
|
||||||
|
@session.all(:css, "a.simple").should have(2).elements
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "within a scope" do
|
context "within a scope" do
|
||||||
|
|
|
@ -5,7 +5,6 @@ Capybara::SpecHelper.spec '#find_by_id' do
|
||||||
|
|
||||||
it "should find any element by id" do
|
it "should find any element by id" do
|
||||||
@session.find_by_id('red').tag_name.should == 'a'
|
@session.find_by_id('red').tag_name.should == 'a'
|
||||||
@session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "casts to string" do
|
it "casts to string" do
|
||||||
|
|
|
@ -113,6 +113,179 @@ Capybara::SpecHelper.spec '#find' do
|
||||||
@session.find(@xpath).value.should == 'John'
|
@session.find(@xpath).value.should == 'John'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with :exact option" do
|
||||||
|
it "matches exactly when true" do
|
||||||
|
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :exact => true).value.should == "monkey"
|
||||||
|
expect do
|
||||||
|
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :exact => true)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "matches loosely when false" do
|
||||||
|
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("test_field")], :exact => false).value.should == "monkey"
|
||||||
|
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")], :exact => false).value.should == "monkey"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "defaults to `Capybara.exact`" do
|
||||||
|
Capybara.exact = true
|
||||||
|
expect do
|
||||||
|
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")])
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
Capybara.exact = false
|
||||||
|
@session.find(:xpath, XPath.descendant(:input)[XPath.attr(:id).is("est_fiel")])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with :match option" do
|
||||||
|
context "when set to `one`" do
|
||||||
|
it "raises an error when multiple matches exist" do
|
||||||
|
expect do
|
||||||
|
@session.find(:css, ".multiple", :match => :one)
|
||||||
|
end.to raise_error(Capybara::Ambiguous)
|
||||||
|
end
|
||||||
|
it "raises an error even if there the match is exact and the others are inexact" do
|
||||||
|
expect do
|
||||||
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :exact => false, :match => :one)
|
||||||
|
end.to raise_error(Capybara::Ambiguous)
|
||||||
|
end
|
||||||
|
it "returns the element if there is only one" do
|
||||||
|
@session.find(:css, ".singular", :match => :one).text.should == "singular"
|
||||||
|
end
|
||||||
|
it "raises an error if there is no match" do
|
||||||
|
expect do
|
||||||
|
@session.find(:css, ".does-not-exist", :match => :any)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when set to `any`" do
|
||||||
|
it "returns the first matched element" do
|
||||||
|
@session.find(:css, ".multiple", :match => :any).text.should == "multiple one"
|
||||||
|
end
|
||||||
|
it "raises an error if there is no match" do
|
||||||
|
expect do
|
||||||
|
@session.find(:css, ".does-not-exist", :match => :any)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when set to `smart`" do
|
||||||
|
context "and `exact` set to `false`" do
|
||||||
|
it "raises an error when there are multiple exact matches" do
|
||||||
|
expect do
|
||||||
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :smart, :exact => false)
|
||||||
|
end.to raise_error(Capybara::Ambiguous)
|
||||||
|
end
|
||||||
|
it "finds a single exact match when there also are inexact matches" do
|
||||||
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :smart, :exact => false)
|
||||||
|
result.text.should == "almost singular"
|
||||||
|
end
|
||||||
|
it "raises an error when there are multiple inexact matches" do
|
||||||
|
expect do
|
||||||
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :smart, :exact => false)
|
||||||
|
end.to raise_error(Capybara::Ambiguous)
|
||||||
|
end
|
||||||
|
it "finds a single inexact match" do
|
||||||
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :smart, :exact => false)
|
||||||
|
result.text.should == "almost singular but not quite"
|
||||||
|
end
|
||||||
|
it "raises an error if there is no match" do
|
||||||
|
expect do
|
||||||
|
@session.find(:css, ".does-not-exist", :match => :smart, :exact => false)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with `exact` set to `true`" do
|
||||||
|
it "raises an error when there are multiple exact matches" do
|
||||||
|
expect do
|
||||||
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :smart, :exact => true)
|
||||||
|
end.to raise_error(Capybara::Ambiguous)
|
||||||
|
end
|
||||||
|
it "finds a single exact match when there also are inexact matches" do
|
||||||
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :smart, :exact => true)
|
||||||
|
result.text.should == "almost singular"
|
||||||
|
end
|
||||||
|
it "raises an error when there are multiple inexact matches" do
|
||||||
|
expect do
|
||||||
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :smart, :exact => true)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
it "raises an error when there is a single inexact matches" do
|
||||||
|
expect do
|
||||||
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :smart, :exact => true)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
it "raises an error if there is no match" do
|
||||||
|
expect do
|
||||||
|
@session.find(:css, ".does-not-exist", :match => :smart, :exact => true)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when set to `prefer_exact`" do
|
||||||
|
context "and `exact` set to `false`" do
|
||||||
|
it "picks the first one when there are multiple exact matches" do
|
||||||
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :prefer_exact, :exact => false)
|
||||||
|
result.text.should == "multiple one"
|
||||||
|
end
|
||||||
|
it "finds a single exact match when there also are inexact matches" do
|
||||||
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :prefer_exact, :exact => false)
|
||||||
|
result.text.should == "almost singular"
|
||||||
|
end
|
||||||
|
it "picks the first one when there are multiple inexact matches" do
|
||||||
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :prefer_exact, :exact => false)
|
||||||
|
result.text.should == "almost singular but not quite"
|
||||||
|
end
|
||||||
|
it "finds a single inexact match" do
|
||||||
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :prefer_exact, :exact => false)
|
||||||
|
result.text.should == "almost singular but not quite"
|
||||||
|
end
|
||||||
|
it "raises an error if there is no match" do
|
||||||
|
expect do
|
||||||
|
@session.find(:css, ".does-not-exist", :match => :prefer_exact, :exact => false)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with `exact` set to `true`" do
|
||||||
|
it "picks the first one when there are multiple exact matches" do
|
||||||
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("multiple")], :match => :prefer_exact, :exact => true)
|
||||||
|
result.text.should == "multiple one"
|
||||||
|
end
|
||||||
|
it "finds a single exact match when there also are inexact matches" do
|
||||||
|
result = @session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular")], :match => :prefer_exact, :exact => true)
|
||||||
|
result.text.should == "almost singular"
|
||||||
|
end
|
||||||
|
it "raises an error if there are multiple inexact matches" do
|
||||||
|
expect do
|
||||||
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singul")], :match => :prefer_exact, :exact => true)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
it "raises an error if there is a single inexact match" do
|
||||||
|
expect do
|
||||||
|
@session.find(:xpath, XPath.descendant[XPath.attr(:class).is("almost_singular but")], :match => :prefer_exact, :exact => true)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
it "raises an error if there is no match" do
|
||||||
|
expect do
|
||||||
|
@session.find(:css, ".does-not-exist", :match => :prefer_exact, :exact => true)
|
||||||
|
end.to raise_error(Capybara::ElementNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "defaults to `Capybara.match`" do
|
||||||
|
Capybara.match = :one
|
||||||
|
expect do
|
||||||
|
@session.find(:css, ".multiple")
|
||||||
|
end.to raise_error(Capybara::Ambiguous)
|
||||||
|
Capybara.match = :any
|
||||||
|
@session.find(:css, ".multiple").text.should == "multiple one"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "within a scope" do
|
context "within a scope" do
|
||||||
before do
|
before do
|
||||||
@session.visit('/with_scope')
|
@session.visit('/with_scope')
|
||||||
|
|
|
@ -38,22 +38,24 @@ Capybara::SpecHelper.spec '#first' do
|
||||||
@session.first('h1').text.should == 'This is a test'
|
@session.first('h1').text.should == 'This is a test'
|
||||||
@session.first("input[id='test_field']")[:value].should == 'monkey'
|
@session.first("input[id='test_field']")[:value].should == 'monkey'
|
||||||
end
|
end
|
||||||
after { Capybara.default_selector = :xpath }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with visible filter" do
|
context "with visible filter" do
|
||||||
after { Capybara.ignore_hidden_elements = false }
|
it "should only find visible nodes when true" do
|
||||||
it "should only find visible nodes if true given" do
|
|
||||||
@session.first(:css, "a#invisible").should_not be_nil
|
|
||||||
@session.first(:css, "a#invisible", :visible => true).should be_nil
|
@session.first(:css, "a#invisible", :visible => true).should be_nil
|
||||||
Capybara.ignore_hidden_elements = true
|
|
||||||
@session.first(:css, "a#invisible").should be_nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should include invisible nodes if false given" do
|
it "should find nodes regardless of whether they are invisible when false" do
|
||||||
Capybara.ignore_hidden_elements = true
|
|
||||||
@session.first(:css, "a#invisible", :visible => false).should_not be_nil
|
@session.first(:css, "a#invisible", :visible => false).should_not be_nil
|
||||||
|
@session.first(:css, "a", :visible => false).should_not be_nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should default to Capybara.ignore_hidden_elements" do
|
||||||
|
Capybara.ignore_hidden_elements = true
|
||||||
@session.first(:css, "a#invisible").should be_nil
|
@session.first(:css, "a#invisible").should be_nil
|
||||||
|
Capybara.ignore_hidden_elements = false
|
||||||
|
@session.first(:css, "a#invisible").should_not be_nil
|
||||||
|
@session.first(:css, "a").should_not be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,7 @@ Capybara::SpecHelper.spec "node" do
|
||||||
|
|
||||||
describe "#visible?" do
|
describe "#visible?" do
|
||||||
it "should extract node visibility" do
|
it "should extract node visibility" do
|
||||||
|
Capybara.ignore_hidden_elements = false
|
||||||
@session.first('//a').should be_visible
|
@session.first('//a').should be_visible
|
||||||
|
|
||||||
@session.find('//div[@id="hidden"]').should_not be_visible
|
@session.find('//div[@id="hidden"]').should_not be_visible
|
||||||
|
|
|
@ -19,6 +19,9 @@ module Capybara
|
||||||
Capybara.app_host = nil
|
Capybara.app_host = nil
|
||||||
Capybara.default_selector = :xpath
|
Capybara.default_selector = :xpath
|
||||||
Capybara.default_wait_time = 1
|
Capybara.default_wait_time = 1
|
||||||
|
Capybara.ignore_hidden_elements = true
|
||||||
|
Capybara.exact = false
|
||||||
|
Capybara.match = :smart
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter(requires, metadata)
|
def filter(requires, metadata)
|
||||||
|
|
|
@ -81,3 +81,11 @@ banana</textarea>
|
||||||
<li id="john_monkey">Monkey John</li>
|
<li id="john_monkey">Monkey John</li>
|
||||||
<li id="paul_monkey">Monkey Paul</li>
|
<li id="paul_monkey">Monkey Paul</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="singular">singular</div>
|
||||||
|
<div class="multiple">multiple one</div>
|
||||||
|
<div class="multiple">multiple two</div>
|
||||||
|
<div class="almost_singular but_not_quite">almost singular but not quite</div>
|
||||||
|
<div class="almost_singular">almost singular</div>
|
||||||
|
</div>
|
||||||
|
|
|
@ -15,7 +15,7 @@ describe Capybara do
|
||||||
<input type="text" name="meh"/>
|
<input type="text" name="meh"/>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div id="footer" style="display: none">
|
<div id="footer">
|
||||||
<p>c2010</p>
|
<p>c2010</p>
|
||||||
<p>Jonas Nicklas</p>
|
<p>Jonas Nicklas</p>
|
||||||
<input type="text" name="foo" value="bar"/>
|
<input type="text" name="foo" value="bar"/>
|
||||||
|
@ -25,6 +25,10 @@ describe Capybara do
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="hidden" style="display: none">
|
||||||
|
<p id="secret">Secret</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<div class="subsection"></div>
|
<div class="subsection"></div>
|
||||||
</section>
|
</section>
|
||||||
|
@ -61,8 +65,8 @@ describe Capybara do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows finding only visible nodes" do
|
it "allows finding only visible nodes" do
|
||||||
string.all('//p', :text => 'c2010', :visible => true).should be_empty
|
string.all(:css, '#secret', :visible => true).should be_empty
|
||||||
string.all('//p', :text => 'c2010', :visible => false).should have(1).element
|
string.all(:css, '#secret', :visible => false).should have(1).element
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows finding elements and extracting text from them" do
|
it "allows finding elements and extracting text from them" do
|
||||||
|
@ -88,7 +92,7 @@ describe Capybara do
|
||||||
|
|
||||||
it "allows finding elements and checking if they are visible" do
|
it "allows finding elements and checking if they are visible" do
|
||||||
string.find('//h1').should be_visible
|
string.find('//h1').should be_visible
|
||||||
string.find('//div/input').should_not be_visible
|
string.find(:css, "#secret", :visible => false).should_not be_visible
|
||||||
end
|
end
|
||||||
|
|
||||||
it "allows finding elements and checking if they are disabled" do
|
it "allows finding elements and checking if they are disabled" do
|
||||||
|
|
Loading…
Reference in New Issue