Class: Capybara::Selector::Definition
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Inherits: | Object |
Defined in: | lib/capybara/selector/definition.rb |
Class Method Summary
Instance Attribute Summary
- #expressions readonly
- #name readonly
- #raw_locator? ⇒ Boolean readonly Internal use only Internal use only
- #supports_exact? ⇒ Boolean readonly Internal use only Internal use only
Instance Method Summary
-
#css(*expression_filters) {|locator, options| ... } ⇒ #call
Define a selector by a
CSS
selector. - #custom_filters
- #default_format
- #default_visibility(fallback = Capybara.ignore_hidden_elements, options = {})
- #describe_all_expression_filters(**opts)
- #describe_expression_filters(&block)
- #describe_node_filters(&block)
- #description(options) ⇒ String
- #expression_filter(name, *types, matcher: nil, **options, &block)
- #expression_filters
- #filter_set(name, filters_to_use = nil)
-
#label(label) ⇒ String
Set/get a descriptive label for the selector.
- #locator_filter(*types, **options, &block)
-
#match {|locator| ... } ⇒ #call
Automatic selector detection.
-
#match?(locator) ⇒ Boolean
Should this selector be used for the passed in locator.
- #node_filter(name, *types, options = {}, &block)
- #node_filters
-
#visible(default_visibility = nil, &block)
Set the default visibility mode that should be used if no visible option is passed when using the selector.
-
#xpath(*expression_filters) {|locator, options| ... } ⇒ #call
Define a selector by an xpath expression.
- #expression(type, allowed_filters, &block) private
- #handled_custom_options(filter, options) private
- #parameter_names(block) private
- #locator_types Internal use only Internal use only
Constructor Details
.new(name, locator_type: nil, raw_locator: false, supports_exact: nil, &block) ⇒ Definition
# File 'lib/capybara/selector/definition.rb', line 16
def initialize(name, locator_type: nil, raw_locator: false, supports_exact: nil, &block) @name = name @filter_set = Capybara::Selector::FilterSet.add(name) @match = nil @label = nil @failure_message = nil @expressions = {} @expression_filters = {} @locator_filter = nil @default_visibility = nil @locator_type = locator_type @raw_locator = raw_locator @supports_exact = supports_exact instance_eval(&block) end
Instance Attribute Details
#expressions (readonly)
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 12
attr_reader :name, :expressions
#name (readonly)
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 12
attr_reader :name, :expressions
#raw_locator? ⇒ Boolean
(readonly)
This method is for internal use only.
# File 'lib/capybara/selector/definition.rb', line 227
def raw_locator? !!@raw_locator end
#supports_exact? ⇒ Boolean
(readonly)
This method is for internal use only.
# File 'lib/capybara/selector/definition.rb', line 232
def supports_exact? @supports_exact end
Instance Method Details
Define a selector by a CSS
selector
# File 'lib/capybara/selector/definition.rb', line 77
def css(*allowed_filters, &block) expression(:css, allowed_filters, &block) end
#custom_filters
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 32
def custom_filters warn "Deprecated: Selector#custom_filters is not valid when same named expression and node filter exist - don't use" node_filters.merge(expression_filters).freeze end
#default_format
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 236
def default_format return nil if @expressions.keys.empty? if @expressions.size == 1 @expressions.keys.first else :xpath end end
#default_visibility(fallback = Capybara.ignore_hidden_elements, options = {})
[ GitHub ]#describe_all_expression_filters(**opts)
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 190
def describe_all_expression_filters(**opts) expression_filters.map do |ef_name, ef| if ef.matcher? (ef, opts).map { |option, value| " with #{ef_name}[#{option} => #{value}]" }.join elsif opts.key?(ef_name) " with #{ef_name} #{opts[ef_name]}" end end.join end
#describe_expression_filters(&block)
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 180
def describe_expression_filters(&block) if block describe(:expression_filters, &block) else describe(:expression_filters) do |**| describe_all_expression_filters(** ) end end end
#describe_node_filters(&block)
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 200
def describe_node_filters(&block) describe(:node_filters, &block) end
#description(options) ⇒ String
# File 'lib/capybara/selector/definition.rb', line 116
def_delegator :@filter_set, :description
#expression(type, allowed_filters, &block) (private)
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 268
def expression(type, allowed_filters, &block) if block @expressions[type] = block allowed_filters = parameter_names(block) if allowed_filters.empty? allowed_filters.flatten.each do |ef| expression_filters[ef] = Capybara::Selector::Filters::IdentityExpressionFilter.new(ef) end end @expressions[type] end
#expression_filter(name, *types, matcher: nil, **options, &block)
# File 'lib/capybara/selector/definition.rb', line 166
def_delegators :@filter_set, :node_filter, :expression_filter, :filter
#expression_filters
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 41
def expression_filters @filter_set.expression_filters end
#filter_set(name, filters_to_use = nil)
[ GitHub ]#handled_custom_options(filter, options) (private)
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 255
def (filter, ) .select do |option, _| filter.handles_option?(option) && !::Capybara::Queries::SelectorQuery::VALID_KEYS.include?(option) end end
#label(label) ⇒ String
#label ⇒ String
String
#label ⇒ String
Set/get a descriptive label for the selector
# File 'lib/capybara/selector/definition.rb', line 104
def label(label = nil) @label = label if label @label end
#locator_filter(*types, **options, &block)
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 168
def locator_filter(*types, **, &block) types.each { |type| [type] = true } @locator_filter = Capybara::Selector::Filters::LocatorFilter.new(block, ** ) if block @locator_filter end
#locator_types
This method is for internal use only.
[ GitHub ]
# File 'lib/capybara/selector/definition.rb', line 247
def locator_types return nil unless @locator_type Array(@locator_type) end
#match {|locator| ... } ⇒ #call
Automatic selector detection
# File 'lib/capybara/selector/definition.rb', line 90
def match(&block) @match = block if block @match end
#match?(locator) ⇒ Boolean
Should this selector be used for the passed in locator
This is used by the automatic selector selection mechanism when no selector type is passed to a selector query
# File 'lib/capybara/selector/definition.rb', line 127
def match?(locator) @match&.call(locator) end
#node_filter(name, *types, options = {}, &block)
#node_filters
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 37
def node_filters @filter_set.node_filters end
#parameter_names(block) (private)
[ GitHub ]# File 'lib/capybara/selector/definition.rb', line 261
def parameter_names(block) key_types = %i[key keyreq] # user filter_map when we drop dupport for 2.6 # block.parameters.select { |(type, _name)| key_types.include? type }.map { |(_, name)| name } block.parameters.filter_map { |(type, name)| name if key_types.include? type } end
#visible(default_visibility = nil, &block)
Set the default visibility mode that should be used if no visible option is passed when using the selector. If not specified will default to the behavior indicated by Capybara.ignore_hidden_elements
# File 'lib/capybara/selector/definition.rb', line 213
def visible(default_visibility = nil, &block) @default_visibility = block || default_visibility end
Define a selector by an xpath expression
# File 'lib/capybara/selector/definition.rb', line 59
def xpath(*allowed_filters, &block) expression(:xpath, allowed_filters, &block) end