mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Merge pull request #1767 from jnicklas/filter_visibile_setting
Allow a selector to specify its default visibility setting
This commit is contained in:
commit
2ebbc92f4a
3 changed files with 39 additions and 12 deletions
|
@ -76,18 +76,10 @@ module Capybara
|
|||
end
|
||||
|
||||
def visible
|
||||
if options.has_key?(:visible)
|
||||
case @options[:visible]
|
||||
case (vis = options.fetch(:visible){ @selector.default_visibility })
|
||||
when true then :visible
|
||||
when false then :all
|
||||
else @options[:visible]
|
||||
end
|
||||
else
|
||||
if Capybara.ignore_hidden_elements
|
||||
:visible
|
||||
else
|
||||
:all
|
||||
end
|
||||
else vis
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ module Capybara
|
|||
@format = nil
|
||||
@expression = nil
|
||||
@expression_filters = []
|
||||
@default_visibility = nil
|
||||
instance_eval(&block)
|
||||
end
|
||||
|
||||
|
@ -186,6 +187,27 @@ module Capybara
|
|||
@filter_set.describe &block
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# Set the default visibility mode that shouble be used if no visibile option is passed when using the selector.
|
||||
# If not specified will default to the behavior indicated by Capybara.ignore_hidden_elements
|
||||
#
|
||||
# @param [Symbol] default_visibility Only find elements with the specified visibility:
|
||||
# * :all - finds visible and invisible elements.
|
||||
# * :hidden - only finds invisible elements.
|
||||
# * :visible - only finds visible elements.
|
||||
def visible(default_visibility)
|
||||
@default_visibility = default_visibility
|
||||
end
|
||||
|
||||
def default_visibility
|
||||
if @default_visibility.nil?
|
||||
Capybara.ignore_hidden_elements
|
||||
else
|
||||
@default_visibility
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def locate_field(xpath, locator, options={})
|
||||
|
|
|
@ -25,6 +25,7 @@ RSpec.describe Capybara do
|
|||
<label for="my_text_input">My Text Input</label>
|
||||
<input type="text" name="form[my_text_input]" placeholder="my text" id="my_text_input"/>
|
||||
<input type="file" id="file" class=".special file"/>
|
||||
<input type="hidden" id="hidden_field" value="this is hidden"/>
|
||||
<a href="#">link</a>
|
||||
<fieldset></fieldset>
|
||||
<select>
|
||||
|
@ -51,6 +52,18 @@ RSpec.describe Capybara do
|
|||
end
|
||||
end
|
||||
|
||||
describe "adding a selector" do
|
||||
it "can set default visiblity" do
|
||||
Capybara.add_selector :hidden_field do
|
||||
visible :hidden
|
||||
css { |sel| 'input[type="hidden"]' }
|
||||
end
|
||||
|
||||
expect(string).to have_no_css('input[type="hidden"]')
|
||||
expect(string).to have_selector(:hidden_field)
|
||||
end
|
||||
end
|
||||
|
||||
describe "modify_selector" do
|
||||
it "allows modifying a selector" do
|
||||
el = string.find(:custom_selector, 'a')
|
||||
|
|
Loading…
Reference in a new issue