From 3a8cec7a63babc8c47be707e15601a1879f4eb01 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Tue, 31 Jan 2012 16:28:28 +0100 Subject: [PATCH] Yank prefer visible elements --- lib/capybara.rb | 4 +--- lib/capybara/node/finders.rb | 7 +----- lib/capybara/spec/session/first_spec.rb | 32 ------------------------- 3 files changed, 2 insertions(+), 41 deletions(-) diff --git a/lib/capybara.rb b/lib/capybara.rb index f1203dea..cd0f5b33 100644 --- a/lib/capybara.rb +++ b/lib/capybara.rb @@ -18,7 +18,7 @@ module Capybara class << self attr_accessor :asset_root, :app_host, :run_server, :default_host attr_accessor :server_host, :server_port - attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements, :prefer_visible_elements + 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 attr_accessor :app @@ -40,7 +40,6 @@ module Capybara # [default_selector = :css/:xpath] Methods which take a selector use the given type by default (Default: CSS) # [default_wait_time = Integer] The number of seconds to wait for asynchronous processes to finish (Default: 2) # [ignore_hidden_elements = Boolean] Whether to ignore hidden elements on the page (Default: false) - # [prefer_visible_elements = Boolean] Whether to prefer visible elements over hidden elements (Default: true) # [automatic_reload = Boolean] Whether to automatically reload elements as Capybara is waiting (Default: true) # [save_and_open_page_path = String] Where to put pages saved through save_and_open_page (Default: Dir.pwd) # @@ -354,7 +353,6 @@ Capybara.configure do |config| config.default_selector = :css config.default_wait_time = 2 config.ignore_hidden_elements = false - config.prefer_visible_elements = true config.default_host = "http://www.example.com" config.automatic_reload = true end diff --git a/lib/capybara/node/finders.rb b/lib/capybara/node/finders.rb index 328364bc..ed7883a2 100644 --- a/lib/capybara/node/finders.rb +++ b/lib/capybara/node/finders.rb @@ -131,12 +131,7 @@ module Capybara # @return [Capybara::Element] The found element or nil # def first(*args) - results = all(*args) - if Capybara.prefer_visible_elements - results.find(&:visible?) or results.first - else - results.first - end + all(*args).first end protected diff --git a/lib/capybara/spec/session/first_spec.rb b/lib/capybara/spec/session/first_spec.rb index e4d0cfa4..87c8983c 100644 --- a/lib/capybara/spec/session/first_spec.rb +++ b/lib/capybara/spec/session/first_spec.rb @@ -58,38 +58,6 @@ shared_examples_for "first" do end end - context "with prefer visible elements" do - it "should find invisible elements if no visible element exists" do - @session.first(:css, 'a#invisible')[:id].should == 'invisible' - end - - it "should prefer visible elements over invisible elements" do - @session.first(:css, 'a.visibility')[:id].should == 'visible' - end - - it "should return the first invisible element if no visible elements exist" do - @session.first(:css, 'a.hidden')[:id].should == 'first_invisble' - end - - it "find visible links normally" do - @session.first(:css, 'a#visible')[:id].should == 'visible' - end - end - - context "without prefer visible elements" do - before { Capybara.prefer_visible_elements = false } - - it "should find invisible elements if no visible element exists" do - @session.first(:css, 'a#invisible')[:id].should == 'invisible' - end - - it "should not prefer visible elements over invisible elements" do - @session.first(:css, 'a.visibility')[:id].should == 'invisible' - end - - after { Capybara.prefer_visible_elements = true } - end - context "within a scope" do before do @session.visit('/with_scope')