Allow a selector to specify its default visibility setting
This commit is contained in:
parent
6000e0d332
commit
a0e99a8da9
|
@ -76,18 +76,10 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible
|
def visible
|
||||||
if options.has_key?(:visible)
|
case (vis = options.fetch(:visible){ @selector.default_visibility })
|
||||||
case @options[:visible]
|
when true then :visible
|
||||||
when true then :visible
|
when false then :all
|
||||||
when false then :all
|
else vis
|
||||||
else @options[:visible]
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if Capybara.ignore_hidden_elements
|
|
||||||
:visible
|
|
||||||
else
|
|
||||||
:all
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ module Capybara
|
||||||
@format = nil
|
@format = nil
|
||||||
@expression = nil
|
@expression = nil
|
||||||
@expression_filters = []
|
@expression_filters = []
|
||||||
|
@default_visibility = nil
|
||||||
instance_eval(&block)
|
instance_eval(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -186,6 +187,27 @@ module Capybara
|
||||||
@filter_set.describe &block
|
@filter_set.describe &block
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def locate_field(xpath, locator, options={})
|
def locate_field(xpath, locator, options={})
|
||||||
|
|
|
@ -25,6 +25,7 @@ RSpec.describe Capybara do
|
||||||
<label for="my_text_input">My Text Input</label>
|
<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="text" name="form[my_text_input]" placeholder="my text" id="my_text_input"/>
|
||||||
<input type="file" id="file" class=".special file"/>
|
<input type="file" id="file" class=".special file"/>
|
||||||
|
<input type="hidden" id="hidden_field" value="this is hidden"/>
|
||||||
<a href="#">link</a>
|
<a href="#">link</a>
|
||||||
<fieldset></fieldset>
|
<fieldset></fieldset>
|
||||||
<select>
|
<select>
|
||||||
|
@ -51,6 +52,18 @@ RSpec.describe Capybara do
|
||||||
end
|
end
|
||||||
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
|
describe "modify_selector" do
|
||||||
it "allows modifying a selector" do
|
it "allows modifying a selector" do
|
||||||
el = string.find(:custom_selector, 'a')
|
el = string.find(:custom_selector, 'a')
|
||||||
|
|
Loading…
Reference in New Issue