Class: Capybara::Queries::SelectorQuery Private
- Defined in:
- lib/capybara/queries/selector_query.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Constant Summary collapse
- SPATIAL_KEYS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%i[above below left_of right_of near].freeze
- VALID_KEYS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
SPATIAL_KEYS + COUNT_KEYS + %i[text id class style visible obscured exact exact_text normalize_ws match wait filter_set focused]
- VALID_MATCH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%i[first smart prefer_exact one].freeze
Constants inherited from BaseQuery
Instance Attribute Summary collapse
- #expression ⇒ Object readonly private
- #locator ⇒ Object readonly private
- #options ⇒ Object readonly private
- #selector ⇒ Object readonly private
Attributes inherited from BaseQuery
Instance Method Summary collapse
- #applied_description ⇒ Object private
- #css ⇒ Object private
-
#description(only_applied = false) ⇒ Object
private
rubocop:disable Style/OptionalBooleanParameter.
- #exact? ⇒ Boolean private
- #failure_message ⇒ Object private
-
#initialize(*args, session_options:, enable_aria_label: session_options.enable_aria_label, enable_aria_role: session_options.enable_aria_role, test_id: session_options.test_id, selector_format: nil, order: nil, **options, &filter_block) ⇒ SelectorQuery
constructor
private
A new instance of SelectorQuery.
- #label ⇒ Object private
- #match ⇒ Object private
- #matches_filters?(node, node_filter_errors = []) ⇒ Boolean private
- #name ⇒ Object private
- #negative_failure_message ⇒ Object private
- #resolve_for(node, exact = nil) ⇒ Object private
- #supports_exact? ⇒ Boolean private
- #visible ⇒ Object private
- #xpath(exact = nil) ⇒ Object private
Methods inherited from BaseQuery
#expects_none?, #matches_count?, wait, #wait
Constructor Details
#initialize(*args, session_options:, enable_aria_label: session_options.enable_aria_label, enable_aria_role: session_options.enable_aria_role, test_id: session_options.test_id, selector_format: nil, order: nil, **options, &filter_block) ⇒ SelectorQuery
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of SelectorQuery.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/capybara/queries/selector_query.rb', line 15 def initialize(*args, session_options:, enable_aria_label: .enable_aria_label, enable_aria_role: .enable_aria_role, test_id: .test_id, selector_format: nil, order: nil, **, &filter_block) @resolved_node = nil @resolved_count = 0 @options = .dup @order = order @filter_cache = Hash.new { |hsh, key| hsh[key] = {} } if @options[:text].is_a?(Regexp) && [true, false].include?(@options[:exact_text]) Capybara::Helpers.warn( "Boolean 'exact_text' option is not supported when 'text' option is a Regexp - ignoring" ) end super(@options) self. = @selector = Selector.new( find_selector(args[0].is_a?(Symbol) ? args.shift : args[0]), config: { enable_aria_label: enable_aria_label, enable_aria_role: enable_aria_role, test_id: test_id }, format: selector_format ) @locator = args.shift @filter_block = filter_block raise ArgumentError, "Unused parameters passed to #{self.class.name} : #{args}" unless args.empty? @expression = selector.call(@locator, **@options) warn_exact_usage assert_valid_keys end |
Instance Attribute Details
#expression ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/capybara/queries/selector_query.rb', line 8 def expression @expression end |
#locator ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/capybara/queries/selector_query.rb', line 8 def locator @locator end |
#options ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/capybara/queries/selector_query.rb', line 8 def @options end |
#selector ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 |
# File 'lib/capybara/queries/selector_query.rb', line 8 def selector @selector end |
Instance Method Details
#applied_description ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
114 115 116 |
# File 'lib/capybara/queries/selector_query.rb', line 114 def applied_description description(true) end |
#css ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
155 156 157 |
# File 'lib/capybara/queries/selector_query.rb', line 155 def css filtered_expression(apply_expression_filters(@expression)) end |
#description(only_applied = false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Style/OptionalBooleanParameter
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/capybara/queries/selector_query.rb', line 64 def description(only_applied = false) # rubocop:disable Style/OptionalBooleanParameter desc = +'' show_for = show_for_stage(only_applied) if show_for[:any] desc << 'visible ' if visible == :visible desc << 'non-visible ' if visible == :hidden end desc << label.to_s desc << " #{locator.inspect}" unless locator.nil? if show_for[:any] desc << " with#{' exact' if exact_text == true} text #{[:text].inspect}" if [:text] desc << " with exact text #{exact_text}" if exact_text.is_a?(String) end desc << " with id #{[:id]}" if [:id] desc << " with classes [#{Array([:class]).join(',')}]" if [:class] desc << ' that is focused' if [:focused] desc << ' that is not focused' if [:focused] == false desc << case [:style] when String " with style attribute #{[:style].inspect}" when Regexp " with style attribute matching #{[:style].inspect}" when Hash " with styles #{[:style].inspect}" else '' end %i[above below left_of right_of near].each do |spatial_filter| if [spatial_filter] && show_for[:spatial] desc << " #{spatial_filter} #{[spatial_filter] rescue '<ERROR>'}" # rubocop:disable Style/RescueModifier end end desc << selector.description(node_filters: show_for[:node], **) desc << ' that also matches the custom filter block' if @filter_block && show_for[:node] desc << " within #{@resolved_node.inspect}" if describe_within? if locator.is_a?(String) && locator.start_with?('#', './/', '//') && !selector.raw_locator? desc << "\nNote: It appears you may be passing a CSS selector or XPath expression rather than a locator. " \ "Please see the documentation for acceptable locator values.\n\n" end desc end |
#exact? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
138 139 140 |
# File 'lib/capybara/queries/selector_query.rb', line 138 def exact? supports_exact? ? .fetch(:exact, .exact) : false end |
#failure_message ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
179 180 181 |
# File 'lib/capybara/queries/selector_query.rb', line 179 def +"expected to find #{applied_description}" << end |
#label ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 |
# File 'lib/capybara/queries/selector_query.rb', line 62 def label; selector.label || selector.name; end |
#match ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
142 143 144 |
# File 'lib/capybara/queries/selector_query.rb', line 142 def match .fetch(:match, .match) end |
#matches_filters?(node, node_filter_errors = []) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/capybara/queries/selector_query.rb', line 118 def matches_filters?(node, node_filter_errors = []) return true if (@resolved_node&.== node) && [:allow_self] matches_locator_filter?(node) && matches_system_filters?(node) && matches_spatial_filters?(node) && matches_node_filters?(node, node_filter_errors) && matches_filter_block?(node) rescue *(node.respond_to?(:session) ? node.session.driver.invalid_element_errors : []) false end |
#name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 |
# File 'lib/capybara/queries/selector_query.rb', line 61 def name; selector.name; end |
#negative_failure_message ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
183 184 185 |
# File 'lib/capybara/queries/selector_query.rb', line 183 def +"expected not to find #{applied_description}" << end |
#resolve_for(node, exact = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/capybara/queries/selector_query.rb', line 160 def resolve_for(node, exact = nil) applied_filters.clear @filter_cache.clear @resolved_node = node @resolved_count += 1 node.synchronize do children = find_nodes_by_selector_format(node, exact).map(&method(:to_element)) Capybara::Result.new(ordered_results(children), self) end end |
#supports_exact? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
173 174 175 176 177 |
# File 'lib/capybara/queries/selector_query.rb', line 173 def supports_exact? return @expression.respond_to? :to_xpath if @selector.supports_exact?.nil? @selector.supports_exact? end |
#visible ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
130 131 132 133 134 135 136 |
# File 'lib/capybara/queries/selector_query.rb', line 130 def visible case (vis = .fetch(:visible) { default_visibility }) when true then :visible when false then :all else vis end end |
#xpath(exact = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
146 147 148 149 150 151 152 153 |
# File 'lib/capybara/queries/selector_query.rb', line 146 def xpath(exact = nil) exact = exact? if exact.nil? expr = apply_expression_filters(@expression) expr = exact ? expr.to_xpath(:exact) : expr.to_s if expr.respond_to?(:to_xpath) expr = filtered_expression(expr) expr = "(#{expr})[#{xpath_text_conditions}]" if try_text_match_in_expression? expr end |