mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Yank prefer visible elements
This commit is contained in:
parent
cc05b1d63b
commit
3a8cec7a63
3 changed files with 2 additions and 41 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Add table
Reference in a new issue