How to use matches_exact_text_filter method of Capybara.Queries Package

Best Capybara code snippet using Capybara.Queries.matches_exact_text_filter

selector_query.rb

Source:selector_query.rb Github

copy

Full Screen

...35 @description36 end37 def matches_filters?(node)38 return false if options[:text] && !matches_text_filter(node, options[:text])39 return false if exact_text.is_a?(String) && !matches_exact_text_filter(node, exact_text)40 case visible41 when :visible then return false unless node.visible?42 when :hidden then return false if node.visible?43 end44 matches_node_filters?(node) && matches_filter_block?(node)45 rescue *(node.respond_to?(:session) ? node.session.driver.invalid_element_errors : [])46 false47 end48 def visible49 case (vis = options.fetch(:visible) { @selector.default_visibility(session_options.ignore_hidden_elements) })50 when true then :visible51 when false then :all52 else vis53 end54 end55 def exact?56 supports_exact? ? options.fetch(:exact, session_options.exact) : false57 end58 def match59 options.fetch(:match, session_options.match)60 end61 def xpath(exact = nil)62 exact = exact? if exact.nil?63 expr = apply_expression_filters(@expression)64 expr = exact ? expr.to_xpath(:exact) : expr.to_s if expr.respond_to?(:to_xpath)65 filtered_xpath(expr)66 end67 def css68 filtered_css(apply_expression_filters(@expression))69 end70 # @api private71 def resolve_for(node, exact = nil)72 @resolved_node = node73 node.synchronize do74 children = if selector.format == :css75 node.find_css(css)76 else77 node.find_xpath(xpath(exact))78 end.map do |child|79 if node.is_a?(Capybara::Node::Base)80 Capybara::Node::Element.new(node.session, child, node, self)81 else82 Capybara::Node::Simple.new(child)83 end84 end85 Capybara::Result.new(children, self)86 end87 end88 # @api private89 def supports_exact?90 @expression.respond_to? :to_xpath91 end92 private93 def find_selector(locator)94 selector = if locator.is_a?(Symbol)95 Selector.all.fetch(locator) { |sel_type| raise ArgumentError, "Unknown selector type (:#{sel_type})" }96 else97 Selector.all.values.find { |s| s.match?(locator) }98 end99 selector || Selector.all[session_options.default_selector]100 end101 def valid_keys102 VALID_KEYS + custom_keys103 end104 def matches_node_filters?(node)105 unapplied_options = options.keys - valid_keys106 node_filters.all? do |filter_name, filter|107 if filter.matcher?108 unapplied_options.select { |option_name| filter.handles_option?(option_name) }.all? do |option_name|109 unapplied_options.delete(option_name)110 filter.matches?(node, option_name, options[option_name])111 end112 elsif options.key?(filter_name)113 unapplied_options.delete(filter_name)114 filter.matches?(node, filter_name, options[filter_name])115 elsif filter.default?116 filter.matches?(node, filter_name, filter.default)117 else118 true119 end120 end121 end122 def matches_filter_block?(node)123 return true unless @filter_block124 if node.respond_to?(:session)125 node.session.using_wait_time(0) { @filter_block.call(node) }126 else127 @filter_block.call(node)128 end129 end130 def node_filters131 if options.key?(:filter_set)132 ::Capybara::Selector::FilterSet.all[options[:filter_set]].node_filters133 else134 @selector.node_filters135 end136 end137 def expression_filters138 filters = @selector.expression_filters139 filters.merge ::Capybara::Selector::FilterSet.all[options[:filter_set]].expression_filters if options.key?(:filter_set)140 filters141 end142 def custom_keys143 @custom_keys ||= node_filters.keys + expression_filters.keys144 end145 def assert_valid_keys146 unless VALID_MATCH.include?(match)147 raise ArgumentError, "invalid option #{match.inspect} for :match, should be one of #{VALID_MATCH.map(&:inspect).join(', ')}"148 end149 unhandled_options = @options.keys - valid_keys150 unhandled_options -= @options.keys.select do |option_name|151 expression_filters.any? { |_nmae, ef| ef.handles_option? option_name } ||152 node_filters.any? { |_name, nf| nf.handles_option? option_name }153 end154 return if unhandled_options.empty?155 invalid_names = unhandled_options.map(&:inspect).join(", ")156 valid_names = valid_keys.map(&:inspect).join(", ")157 raise ArgumentError, "invalid keys #{invalid_names}, should be one of #{valid_names}"158 end159 def filtered_xpath(expr)160 if options.key?(:id) && !custom_keys.include?(:id)161 expr = if options[:id].is_a? XPath::Expression162 "(#{expr})[#{XPath.attr(:id)[options[:id]]}]"163 else164 "(#{expr})[#{XPath.attr(:id) == options[:id]}]"165 end166 end167 if options.key?(:class) && !custom_keys.include?(:class)168 class_xpath = if options[:class].is_a?(XPath::Expression)169 XPath.attr(:class)[options[:class]]170 else171 Array(options[:class]).map do |klass|172 if klass.start_with?('!')173 !XPath.attr(:class).contains_word(klass.slice(1))174 else175 XPath.attr(:class).contains_word(klass)176 end177 end.reduce(:&)178 end179 expr = "(#{expr})[#{class_xpath}]"180 end181 expr182 end183 def filtered_css(expr)184 process_id = options.key?(:id) && !custom_keys.include?(:id)185 process_class = options.key?(:class) && !custom_keys.include?(:class)186 if process_id && options[:id].is_a?(XPath::Expression)187 raise ArgumentError, "XPath expressions are not supported for the :id filter with CSS based selectors"188 end189 if process_class && options[:class].is_a?(XPath::Expression)190 raise ArgumentError, "XPath expressions are not supported for the :class filter with CSS based selectors"191 end192 if process_class || process_id193 css_selectors = expr.split(',').map(&:rstrip)194 expr = css_selectors.map do |sel|195 sel += "##{Capybara::Selector::CSS.escape(options[:id])}" if process_id196 sel += css_from_classes(Array(options[:class])) if process_class197 sel198 end.join(", ")199 end200 expr201 end202 def css_from_classes(classes)203 classes = classes.group_by { |c| c.start_with? '!' }204 (classes[false].to_a.map { |c| ".#{Capybara::Selector::CSS.escape(c)}" } +205 classes[true].to_a.map { |c| ":not(.#{Capybara::Selector::CSS.escape(c.slice(1))})" }).join206 end207 def apply_expression_filters(expr)208 unapplied_options = options.keys - valid_keys209 expression_filters.inject(expr) do |memo, (name, ef)|210 if ef.matcher?211 unapplied_options.select { |option_name| ef.handles_option?(option_name) }.each do |option_name|212 unapplied_options.delete(option_name)213 memo = ef.apply_filter(memo, option_name, options[option_name])214 end215 memo216 elsif options.key?(name)217 unapplied_options.delete(name)218 ef.apply_filter(memo, name, options[name])219 elsif ef.default?220 ef.apply_filter(memo, name, ef.default)221 else222 memo223 end224 end225 end226 def warn_exact_usage227 return unless options.key?(:exact) && !supports_exact?228 warn "The :exact option only has an effect on queries using the XPath#is method. Using it with the query \"#{expression}\" has no effect."229 end230 def exact_text231 options.fetch(:exact_text, session_options.exact_text)232 end233 def describe_within?234 @resolved_node && !document?(@resolved_node) && !simple_root?(@resolved_node)235 end236 def document?(node)237 node.is_a?(::Capybara::Node::Document)238 end239 def simple_root?(node)240 node.is_a?(::Capybara::Node::Simple) && node.path == '/'241 end242 def matches_text_filter(node, value)243 return matches_exact_text_filter(node, value) if exact_text == true244 regexp = value.is_a?(Regexp) ? value : Regexp.escape(value.to_s)245 matches_text_regexp(node, regexp)246 end247 def matches_exact_text_filter(node, value)248 regexp = value.is_a?(Regexp) ? value : /\A#{Regexp.escape(value.to_s)}\z/249 matches_text_regexp(node, regexp)250 end251 def matches_text_regexp(node, regexp)252 text_visible = visible253 text_visible = :all if text_visible == :hidden254 node.text(text_visible).match(regexp)255 end256 end257 end258end...

Full Screen

Full Screen

matches_exact_text_filter

Using AI Code Generation

copy

Full Screen

1 def initialize(text)2 def filter(nodes)3puts page.all(:exact_text, 'Capybara').length

Full Screen

Full Screen

matches_exact_text_filter

Using AI Code Generation

copy

Full Screen

1 def matches_exact_text_filter?(node)2 def matches_exact_text_filter?(node)3 page.should have_selector('div', :exact_text => 'test')

Full Screen

Full Screen

matches_exact_text_filter

Using AI Code Generation

copy

Full Screen

1Capybara.Queries.matches_exact_text_filter = (node, text) ->2 node.text() == text3Capybara.Queries.matches_exact_text_filter = (node, text) ->4 node.text() == text5Capybara.Queries.matches_exact_text_filter = (node, text) ->6 node.text() == text7Capybara.Queries.matches_exact_text_filter = (node, text) ->8 node.text() == text9Capybara.Queries.matches_exact_text_filter = (node, text) ->10 node.text() == text11Capybara.Queries.matches_exact_text_filter = (node, text) ->12 node.text() == text13Capybara.Queries.matches_exact_text_filter = (node, text) ->14 node.text() == text15Capybara.Queries.matches_exact_text_filter = (node, text) ->16 node.text() == text17Capybara.Queries.matches_exact_text_filter = (node, text) ->18 node.text() == text

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful