From d79413321fd8ea4dde0d661b82253e77429acdaf Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Sun, 10 Feb 2013 16:51:12 +0100 Subject: [PATCH 1/7] Update xpath lib --- xpath | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xpath b/xpath index df56bb35..130b0192 160000 --- a/xpath +++ b/xpath @@ -1 +1 @@ -Subproject commit df56bb355a0a79c886444a95632ff4182d559041 +Subproject commit 130b0192a8fbbff6110efc306b33697be66c631e From aa3d3e1eadecaa76e7de8c1897fd3a33aec2f8ec Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Fri, 15 Feb 2013 19:59:51 +0100 Subject: [PATCH 2/7] Add `exact` option --- lib/capybara/query.rb | 10 ++++++++-- lib/capybara/spec/session/find_spec.rb | 18 ++++++++++++++++++ xpath | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/capybara/query.rb b/lib/capybara/query.rb index 2ecb3c55..963ce357 100644 --- a/lib/capybara/query.rb +++ b/lib/capybara/query.rb @@ -2,7 +2,7 @@ module Capybara class Query 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] def initialize(*args) @options = if args.last.is_a?(Hash) then args.pop.dup else {} end @@ -20,7 +20,13 @@ module Capybara end @selector ||= Selector.all[Capybara.default_selector] - @xpath = @selector.call(@locator).to_s + @xpath = @selector.call(@locator) + if @xpath.respond_to?(:to_xpath) and @options[:exact] + @xpath = @xpath.to_xpath(:exact) + else + @xpath = @xpath.to_s + end + assert_valid_keys! end diff --git a/lib/capybara/spec/session/find_spec.rb b/lib/capybara/spec/session/find_spec.rb index 26edb008..3fc3759b 100644 --- a/lib/capybara/spec/session/find_spec.rb +++ b/lib/capybara/spec/session/find_spec.rb @@ -113,6 +113,24 @@ Capybara::SpecHelper.spec '#find' do @session.find(@xpath).value.should == 'John' 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 + + end + end + context "within a scope" do before do @session.visit('/with_scope') diff --git a/xpath b/xpath index 130b0192..4c7c3351 160000 --- a/xpath +++ b/xpath @@ -1 +1 @@ -Subproject commit 130b0192a8fbbff6110efc306b33697be66c631e +Subproject commit 4c7c3351f970f14635e670239e11f81fffb07717 From 83570f3ece6ce0426c1c8cbb4120555eb466cec0 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Fri, 15 Feb 2013 20:02:15 +0100 Subject: [PATCH 3/7] Add `exact` config option --- lib/capybara.rb | 2 +- lib/capybara/query.rb | 5 ++++- lib/capybara/spec/session/find_spec.rb | 7 ++++++- lib/capybara/spec/spec_helper.rb | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/capybara.rb b/lib/capybara.rb index 8de98188..fd547436 100644 --- a/lib/capybara.rb +++ b/lib/capybara.rb @@ -16,7 +16,7 @@ module Capybara class << self 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 attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements attr_accessor :save_and_open_page_path, :automatic_reload attr_writer :default_driver, :current_driver, :javascript_driver, :session_name diff --git a/lib/capybara/query.rb b/lib/capybara/query.rb index 963ce357..b528cca7 100644 --- a/lib/capybara/query.rb +++ b/lib/capybara/query.rb @@ -11,6 +11,10 @@ module Capybara @options[:visible] = Capybara.ignore_hidden_elements end + unless options.has_key?(:exact) + @options[:exact] = Capybara.exact + end + if args[0].is_a?(Symbol) @selector = Selector.all[args[0]] @locator = args[1] @@ -27,7 +31,6 @@ module Capybara @xpath = @xpath.to_s end - assert_valid_keys! end diff --git a/lib/capybara/spec/session/find_spec.rb b/lib/capybara/spec/session/find_spec.rb index 3fc3759b..1f463681 100644 --- a/lib/capybara/spec/session/find_spec.rb +++ b/lib/capybara/spec/session/find_spec.rb @@ -127,7 +127,12 @@ Capybara::SpecHelper.spec '#find' do 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 diff --git a/lib/capybara/spec/spec_helper.rb b/lib/capybara/spec/spec_helper.rb index 4150652f..30e6a9c7 100644 --- a/lib/capybara/spec/spec_helper.rb +++ b/lib/capybara/spec/spec_helper.rb @@ -19,6 +19,7 @@ module Capybara Capybara.app_host = nil Capybara.default_selector = :xpath Capybara.default_wait_time = 1 + Capybara.exact = false end def filter(requires, metadata) From e898cc2b8e6ce16f896793159057ef6bf714b166 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Fri, 15 Feb 2013 20:32:05 +0100 Subject: [PATCH 4/7] Add `match` option --- lib/capybara.rb | 4 +- lib/capybara/node/finders.rb | 36 ++++++-- lib/capybara/query.rb | 30 +++++-- lib/capybara/result.rb | 13 --- lib/capybara/spec/session/find_by_id_spec.rb | 1 - lib/capybara/spec/session/find_spec.rb | 88 ++++++++++++++++++++ lib/capybara/spec/spec_helper.rb | 1 + lib/capybara/spec/views/with_html.erb | 8 ++ 8 files changed, 151 insertions(+), 30 deletions(-) diff --git a/lib/capybara.rb b/lib/capybara.rb index fd547436..6c0cf4de 100644 --- a/lib/capybara.rb +++ b/lib/capybara.rb @@ -16,7 +16,7 @@ module Capybara class << self attr_accessor :asset_root, :app_host, :run_server, :default_host, :always_include_port - attr_accessor :server_host, :server_port, :exact + attr_accessor :server_host, :server_port, :exact, :match attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements attr_accessor :save_and_open_page_path, :automatic_reload attr_writer :default_driver, :current_driver, :javascript_driver, :session_name @@ -344,6 +344,8 @@ Capybara.configure do |config| config.ignore_hidden_elements = true config.default_host = "http://www.example.com" config.automatic_reload = true + config.match = :smart + config.exact = false end Capybara.register_driver :rack_test do |app| diff --git a/lib/capybara/node/finders.rb b/lib/capybara/node/finders.rb index 206744ca..4566d5e8 100644 --- a/lib/capybara/node/finders.rb +++ b/lib/capybara/node/finders.rb @@ -23,7 +23,22 @@ module Capybara # @raise [Capybara::ElementNotFound] If the element can't be found before time expires # def find(*args) - synchronize { all(*args).find! }.tap(&:allow_reload!) + synchronize do + query = Capybara::Query.new(*args) + if query.match == :smart + 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 ## @@ -108,13 +123,7 @@ module Capybara # @return [Array[Capybara::Element]] The found elements # def all(*args) - 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) + resolve_query(Capybara::Query.new(*args)) end ## @@ -131,6 +140,17 @@ module Capybara def first(*args) all(*args).first 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 diff --git a/lib/capybara/query.rb b/lib/capybara/query.rb index b528cca7..0d219d02 100644 --- a/lib/capybara/query.rb +++ b/lib/capybara/query.rb @@ -2,7 +2,7 @@ module Capybara class Query attr_accessor :selector, :locator, :options, :xpath, :find, :negative - VALID_KEYS = [:text, :visible, :between, :count, :maximum, :minimum, :exact] + VALID_KEYS = [:text, :visible, :between, :count, :maximum, :minimum, :exact, :match] def initialize(*args) @options = if args.last.is_a?(Hash) then args.pop.dup else {} end @@ -15,6 +15,10 @@ module Capybara @options[:exact] = Capybara.exact end + unless options.has_key?(:match) + @options[:match] = Capybara.match + end + if args[0].is_a?(Symbol) @selector = Selector.all[args[0]] @locator = args[1] @@ -25,12 +29,6 @@ module Capybara @selector ||= Selector.all[Capybara.default_selector] @xpath = @selector.call(@locator) - if @xpath.respond_to?(:to_xpath) and @options[:exact] - @xpath = @xpath.to_xpath(:exact) - else - @xpath = @xpath.to_s - end - assert_valid_keys! end @@ -72,6 +70,24 @@ module Capybara 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 def assert_valid_keys! diff --git a/lib/capybara/result.rb b/lib/capybara/result.rb index 711f66b8..de985dd4 100644 --- a/lib/capybara/result.rb +++ b/lib/capybara/result.rb @@ -18,19 +18,6 @@ module Capybara @query.matches_count?(@result.size) 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 message = if @query.options[:count] "expected #{@query.description} to be found #{@query.options[:count]} #{declension("time", "times", @query.options[:count])}" diff --git a/lib/capybara/spec/session/find_by_id_spec.rb b/lib/capybara/spec/session/find_by_id_spec.rb index 21407bb0..7204defb 100644 --- a/lib/capybara/spec/session/find_by_id_spec.rb +++ b/lib/capybara/spec/session/find_by_id_spec.rb @@ -5,7 +5,6 @@ Capybara::SpecHelper.spec '#find_by_id' do it "should find any element by id" do @session.find_by_id('red').tag_name.should == 'a' - @session.find_by_id('hidden_via_ancestor').tag_name.should == 'div' end it "casts to string" do diff --git a/lib/capybara/spec/session/find_spec.rb b/lib/capybara/spec/session/find_spec.rb index 1f463681..99c63d20 100644 --- a/lib/capybara/spec/session/find_spec.rb +++ b/lib/capybara/spec/session/find_spec.rb @@ -136,6 +136,94 @@ Capybara::SpecHelper.spec '#find' do 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 + 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 + 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 before do @session.visit('/with_scope') diff --git a/lib/capybara/spec/spec_helper.rb b/lib/capybara/spec/spec_helper.rb index 30e6a9c7..0b170017 100644 --- a/lib/capybara/spec/spec_helper.rb +++ b/lib/capybara/spec/spec_helper.rb @@ -20,6 +20,7 @@ module Capybara Capybara.default_selector = :xpath Capybara.default_wait_time = 1 Capybara.exact = false + Capybara.match = :smart end def filter(requires, metadata) diff --git a/lib/capybara/spec/views/with_html.erb b/lib/capybara/spec/views/with_html.erb index 7116dba6..babb19a9 100644 --- a/lib/capybara/spec/views/with_html.erb +++ b/lib/capybara/spec/views/with_html.erb @@ -81,3 +81,11 @@ banana
  • Monkey John
  • Monkey Paul
  • + +
    +
    singular
    +
    multiple one
    +
    multiple two
    +
    almost singular but not quite
    +
    almost singular
    +
    From 4a617bcafcaa85ef2c9e714cc28a862e10d7fd60 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Fri, 15 Feb 2013 21:43:30 +0100 Subject: [PATCH 5/7] Add prefer_exact match strategy which behaves like Capybara 1.x --- lib/capybara/node/finders.rb | 2 +- lib/capybara/spec/session/find_spec.rb | 62 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/lib/capybara/node/finders.rb b/lib/capybara/node/finders.rb index 4566d5e8..a5886cb2 100644 --- a/lib/capybara/node/finders.rb +++ b/lib/capybara/node/finders.rb @@ -25,7 +25,7 @@ module Capybara def find(*args) synchronize do query = Capybara::Query.new(*args) - if query.match == :smart + 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 diff --git a/lib/capybara/spec/session/find_spec.rb b/lib/capybara/spec/session/find_spec.rb index 99c63d20..22cc8a01 100644 --- a/lib/capybara/spec/session/find_spec.rb +++ b/lib/capybara/spec/session/find_spec.rb @@ -189,6 +189,11 @@ Capybara::SpecHelper.spec '#find' 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 @@ -211,6 +216,63 @@ Capybara::SpecHelper.spec '#find' 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 From 0303ed84c5a4af849f788c4c03712a78074ea885 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Fri, 15 Feb 2013 22:09:40 +0100 Subject: [PATCH 6/7] Fix some specs, due to visibility changes --- lib/capybara/spec/session/all_spec.rb | 17 +++++++++-------- lib/capybara/spec/session/first_spec.rb | 18 ++++++++++-------- lib/capybara/spec/session/node_spec.rb | 1 + lib/capybara/spec/spec_helper.rb | 1 + 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/capybara/spec/session/all_spec.rb b/lib/capybara/spec/session/all_spec.rb index 15fe8ed0..413bea52 100644 --- a/lib/capybara/spec/session/all_spec.rb +++ b/lib/capybara/spec/session/all_spec.rb @@ -48,22 +48,23 @@ Capybara::SpecHelper.spec "#all" do @session.all('h1').first.text.should == 'This is a test' @session.all("input[id='test_field']").first[:value].should == 'monkey' end - after { Capybara.default_selector = :xpath } end context "with visible filter" do - after { Capybara.ignore_hidden_elements = true } - 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 + it "should only find visible nodes when true" do @session.all(:css, "a.simple", :visible => true).should have(1).elements end - it "should only find invisible nodes" do - Capybara.ignore_hidden_elements = true + it "should find nodes regardless of whether they are invisible when false" do @session.all(:css, "a.simple", :visible => false).should have(2).elements 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 context "within a scope" do diff --git a/lib/capybara/spec/session/first_spec.rb b/lib/capybara/spec/session/first_spec.rb index 30ee66ed..6875ceed 100644 --- a/lib/capybara/spec/session/first_spec.rb +++ b/lib/capybara/spec/session/first_spec.rb @@ -38,22 +38,24 @@ Capybara::SpecHelper.spec '#first' do @session.first('h1').text.should == 'This is a test' @session.first("input[id='test_field']")[:value].should == 'monkey' end - after { Capybara.default_selector = :xpath } end context "with visible filter" do - after { Capybara.ignore_hidden_elements = false } - it "should only find visible nodes if true given" do - @session.first(:css, "a#invisible").should_not be_nil + it "should only find visible nodes when true" do @session.first(:css, "a#invisible", :visible => true).should be_nil - Capybara.ignore_hidden_elements = true - @session.first(:css, "a#invisible").should be_nil end - it "should include invisible nodes if false given" do - Capybara.ignore_hidden_elements = true + it "should find nodes regardless of whether they are invisible when false" do @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 + Capybara.ignore_hidden_elements = false + @session.first(:css, "a#invisible").should_not be_nil + @session.first(:css, "a").should_not be_nil end end diff --git a/lib/capybara/spec/session/node_spec.rb b/lib/capybara/spec/session/node_spec.rb index a039947f..9e5a601c 100644 --- a/lib/capybara/spec/session/node_spec.rb +++ b/lib/capybara/spec/session/node_spec.rb @@ -83,6 +83,7 @@ Capybara::SpecHelper.spec "node" do describe "#visible?" do it "should extract node visibility" do + Capybara.ignore_hidden_elements = false @session.first('//a').should be_visible @session.find('//div[@id="hidden"]').should_not be_visible diff --git a/lib/capybara/spec/spec_helper.rb b/lib/capybara/spec/spec_helper.rb index 0b170017..7cebf623 100644 --- a/lib/capybara/spec/spec_helper.rb +++ b/lib/capybara/spec/spec_helper.rb @@ -19,6 +19,7 @@ module Capybara Capybara.app_host = nil Capybara.default_selector = :xpath Capybara.default_wait_time = 1 + Capybara.ignore_hidden_elements = true Capybara.exact = false Capybara.match = :smart end From c6cd6acad3a67109f8b0bcbb80a6302bef61183f Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Fri, 15 Feb 2013 22:14:07 +0100 Subject: [PATCH 7/7] Fix basics nodes --- lib/capybara/node/simple.rb | 7 ++++--- spec/basic_node_spec.rb | 12 ++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/capybara/node/simple.rb b/lib/capybara/node/simple.rb index 5049893d..a5e25069 100644 --- a/lib/capybara/node/simple.rb +++ b/lib/capybara/node/simple.rb @@ -130,9 +130,10 @@ module Capybara yield # simple nodes don't need to wait end - def all(*args) - query = Capybara::Query.new(*args) - elements = native.xpath(query.xpath).map do |node| + private + + def resolve_query(query, exact=nil) + elements = native.xpath(query.xpath(exact)).map do |node| self.class.new(node) end Capybara::Result.new(elements, query) diff --git a/spec/basic_node_spec.rb b/spec/basic_node_spec.rb index 8b65ba00..0ace354d 100644 --- a/spec/basic_node_spec.rb +++ b/spec/basic_node_spec.rb @@ -10,7 +10,7 @@ describe Capybara do

    Yes it is

    -