Best Capybara code snippet using Capybara.expression_filter
selector.rb
Source:selector.rb
...4Capybara::Selector::FilterSet.add(:_field) do5 node_filter(:checked, :boolean) { |node, value| !(value ^ node.checked?) }6 node_filter(:unchecked, :boolean) { |node, value| (value ^ node.checked?) }7 node_filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| !(value ^ node.disabled?) }8 expression_filter(:name) { |xpath, val| xpath[XPath.attr(:name) == val] }9 expression_filter(:placeholder) { |xpath, val| xpath[XPath.attr(:placeholder) == val] }10 expression_filter(:disabled) { |xpath, val| val ? xpath : xpath[~XPath.attr(:disabled)] }11 expression_filter(:multiple) { |xpath, val| xpath[val ? XPath.attr(:multiple) : ~XPath.attr(:multiple)] }12 describe(:expression_filters) do |name: nil, placeholder: nil, disabled: nil, multiple: nil, **|13 desc = +''14 desc << ' that is not disabled' if disabled == false15 desc << " with name #{name}" if name16 desc << " with placeholder #{placeholder}" if placeholder17 desc << ' with the multiple attribute' if multiple == true18 desc << ' without the multiple attribute' if multiple == false19 desc20 end21 describe(:node_filters) do |checked: nil, unchecked: nil, disabled: nil, **|22 desc, states = +'', []23 states << 'checked' if checked || (unchecked == false)24 states << 'not checked' if unchecked || (checked == false)25 states << 'disabled' if disabled == true26 desc << " that is #{states.join(' and ')}" unless states.empty?27 desc28 end29end30# rubocop:disable Metrics/BlockLength31Capybara.add_selector(:xpath, locator_type: [:to_xpath, String], raw_locator: true) do32 xpath { |xpath| xpath }33end34Capybara.add_selector(:css, locator_type: [String, Symbol], raw_locator: true) do35 css { |css| css }36end37Capybara.add_selector(:id, locator_type: [String, Symbol, Regexp]) do38 xpath { |id| builder(XPath.descendant).add_attribute_conditions(id: id) }39 locator_filter { |node, id| id.is_a?(Regexp) ? id.match?(node[:id]) : true }40end41Capybara.add_selector(:field, locator_type: [String, Symbol]) do42 visible { |options| :hidden if options[:type].to_s == 'hidden' }43 xpath do |locator, **options|44 invalid_types = %w[submit image]45 invalid_types << 'hidden' unless options[:type].to_s == 'hidden'46 xpath = XPath.descendant(:input, :textarea, :select)[!XPath.attr(:type).one_of(*invalid_types)]47 locate_field(xpath, locator, options)48 end49 expression_filter(:type) do |expr, type|50 type = type.to_s51 if %w[textarea select].include?(type)52 expr.self(type.to_sym)53 else54 expr[XPath.attr(:type) == type]55 end56 end57 filter_set(:_field) # checked/unchecked/disabled/multiple/name/placeholder58 node_filter(:readonly, :boolean) { |node, value| !(value ^ node.readonly?) }59 node_filter(:with) do |node, with|60 val = node.value61 (with.is_a?(Regexp) ? with.match?(val) : val == with.to_s).tap do |res|62 add_error("Expected value to be #{with.inspect} but was #{val.inspect}") unless res63 end64 end65 describe_expression_filters do |type: nil, **|66 " of type #{type.inspect}" if type67 end68 describe_node_filters do |**options|69 " with value #{options[:with].to_s.inspect}" if options.key?(:with)70 end71end72Capybara.add_selector(:fieldset, locator_type: [String, Symbol]) do73 xpath do |locator, legend: nil, **|74 locator_matchers = (XPath.attr(:id) == locator.to_s) | XPath.child(:legend)[XPath.string.n.is(locator.to_s)]75 locator_matchers |= XPath.attr(test_id) == locator.to_s if test_id76 xpath = XPath.descendant(:fieldset)[locator && locator_matchers]77 xpath = xpath[XPath.child(:legend)[XPath.string.n.is(legend)]] if legend78 xpath79 end80 node_filter(:disabled, :boolean) { |node, value| !(value ^ node.disabled?) }81 expression_filter(:disabled) { |xpath, val| val ? xpath : xpath[~XPath.attr(:disabled)] }82end83Capybara.add_selector(:link, locator_type: [String, Symbol]) do84 xpath do |locator, href: true, alt: nil, title: nil, **|85 xpath = builder(XPath.descendant(:a)).add_attribute_conditions(href: href)86 unless locator.nil?87 locator = locator.to_s88 matchers = [XPath.attr(:id) == locator,89 XPath.string.n.is(locator),90 XPath.attr(:title).is(locator),91 XPath.descendant(:img)[XPath.attr(:alt).is(locator)]]92 matchers << XPath.attr(:'aria-label').is(locator) if enable_aria_label93 matchers << XPath.attr(test_id).equals(locator) if test_id94 xpath = xpath[matchers.reduce(:|)]95 end96 xpath = xpath[find_by_attr(:title, title)]97 xpath = xpath[XPath.descendant(:img)[XPath.attr(:alt) == alt]] if alt98 xpath99 end100 node_filter(:href) do |node, href|101 # If not a Regexp it's been handled in the main XPath102 (href.is_a?(Regexp) ? node[:href].match(href) : true).tap do |res|103 add_error "Expected href to match #{href.inspect} but it was #{node[:href].inspect}" unless res104 end105 end106 expression_filter(:download, valid_values: [true, false, String]) do |expr, download|107 builder(expr).add_attribute_conditions(download: download)108 end109 describe_expression_filters do |download: nil, **options|110 desc = +''111 if (href = options[:href])112 desc << " with href #{'matching ' if href.is_a? Regexp}#{href.inspect}"113 elsif options.key?(:href) # is nil/false specified?114 desc << ' with no href attribute'115 end116 desc << " with download attribute#{" #{download}" if download.is_a? String}" if download117 desc << ' without download attribute' if download == false118 desc119 end120end121Capybara.add_selector(:button, locator_type: [String, Symbol]) do122 xpath(:value, :title, :type, :name) do |locator, **options|123 input_btn_xpath = XPath.descendant(:input)[XPath.attr(:type).one_of('submit', 'reset', 'image', 'button')]124 btn_xpath = XPath.descendant(:button)125 image_btn_xpath = XPath.descendant(:input)[XPath.attr(:type) == 'image']126 unless locator.nil?127 locator = locator.to_s128 locator_matchers = XPath.attr(:id).equals(locator) | XPath.attr(:name).equals(locator) | XPath.attr(:value).is(locator) | XPath.attr(:title).is(locator)129 locator_matchers |= XPath.attr(:'aria-label').is(locator) if enable_aria_label130 locator_matchers |= XPath.attr(test_id) == locator if test_id131 input_btn_xpath = input_btn_xpath[locator_matchers]132 btn_xpath = btn_xpath[locator_matchers | XPath.string.n.is(locator) | XPath.descendant(:img)[XPath.attr(:alt).is(locator)]]133 alt_matches = XPath.attr(:alt).is(locator)134 alt_matches |= XPath.attr(:'aria-label').is(locator) if enable_aria_label135 image_btn_xpath = image_btn_xpath[alt_matches]136 end137 %i[value title type name].inject(input_btn_xpath.union(btn_xpath).union(image_btn_xpath)) do |memo, ef|138 memo[find_by_attr(ef, options[ef])]139 end140 end141 node_filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| !(value ^ node.disabled?) }142 expression_filter(:disabled) { |xpath, val| val ? xpath : xpath[~XPath.attr(:disabled)] }143 describe_expression_filters do |disabled: nil, **options|144 desc = +''145 desc << ' that is not disabled' if disabled == false146 desc << describe_all_expression_filters(options)147 end148 describe_node_filters do |disabled: nil, **|149 ' that is disabled' if disabled == true150 end151end152Capybara.add_selector(:link_or_button, locator_type: [String, Symbol]) do153 label 'link or button'154 xpath do |locator, **options|155 self.class.all.values_at(:link, :button).map do |selector|156 instance_exec(locator, options, &selector.xpath)157 end.reduce(:union)158 end159 node_filter(:disabled, :boolean, default: false, skip_if: :all) { |node, value| !(value ^ node.disabled?) }160 describe_node_filters do |disabled: nil, **|161 ' that is disabled' if disabled == true162 end163end164Capybara.add_selector(:fillable_field, locator_type: [String, Symbol]) do165 label 'field'166 xpath do |locator, allow_self: nil, **options|167 xpath = XPath.axis(allow_self ? :"descendant-or-self" : :descendant, :input, :textarea)[168 !XPath.attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')169 ]170 locate_field(xpath, locator, options)171 end172 expression_filter(:type) do |expr, type|173 type = type.to_s174 if type == 'textarea'175 expr.self(type.to_sym)176 else177 expr[XPath.attr(:type) == type]178 end179 end180 filter_set(:_field, %i[disabled multiple name placeholder])181 node_filter(:with) do |node, with|182 val = node.value183 (with.is_a?(Regexp) ? with.match?(val) : val == with.to_s).tap do |res|184 add_error("Expected value to be #{with.inspect} but was #{val.inspect}") unless res185 end186 end187 describe_node_filters do |**options|188 " with value #{options[:with].to_s.inspect}" if options.key?(:with)189 end190end191Capybara.add_selector(:radio_button, locator_type: [String, Symbol]) do192 label 'radio button'193 xpath do |locator, allow_self: nil, **options|194 xpath = XPath.axis(allow_self ? :"descendant-or-self" : :descendant, :input)[195 XPath.attr(:type) == 'radio'196 ]197 locate_field(xpath, locator, options)198 end199 filter_set(:_field, %i[checked unchecked disabled name])200 node_filter(:option) do |node, value|201 val = node.value202 (val == value.to_s).tap do |res|203 add_error("Expected option value to be #{value.inspect} but it was #{val.inspect}") unless res204 end205 end206 describe_node_filters do |option: nil, **|207 " with value #{option.inspect}" if option208 end209end210Capybara.add_selector(:checkbox, locator_type: [String, Symbol]) do211 xpath do |locator, allow_self: nil, **options|212 xpath = XPath.axis(allow_self ? :"descendant-or-self" : :descendant, :input)[213 XPath.attr(:type) == 'checkbox'214 ]215 locate_field(xpath, locator, options)216 end217 filter_set(:_field, %i[checked unchecked disabled name])218 node_filter(:option) do |node, value|219 val = node.value220 (val == value.to_s).tap do |res|221 add_error("Expected option value to be #{value.inspect} but it was #{val.inspect}") unless res222 end223 end224 describe_node_filters do |option: nil, **|225 " with value #{option.inspect}" if option226 end227end228Capybara.add_selector(:select, locator_type: [String, Symbol]) do229 label 'select box'230 xpath do |locator, **options|231 xpath = XPath.descendant(:select)232 locate_field(xpath, locator, options)233 end234 filter_set(:_field, %i[disabled multiple name placeholder])235 node_filter(:options) do |node, options|236 actual = if node.visible?237 node.all(:xpath, './/option', wait: false).map(&:text)238 else239 node.all(:xpath, './/option', visible: false, wait: false).map { |option| option.text(:all) }240 end241 (options.sort == actual.sort).tap do |res|242 add_error("Expected options #{options.inspect} found #{actual.inspect}") unless res243 end244 end245 expression_filter(:with_options) do |expr, options|246 options.inject(expr) do |xpath, option|247 xpath[self.class.all[:option].call(option)]248 end249 end250 node_filter(:selected) do |node, selected|251 actual = node.all(:xpath, './/option', visible: false, wait: false).select(&:selected?).map { |option| option.text(:all) }252 (Array(selected).sort == actual.sort).tap do |res|253 add_error("Expected #{selected.inspect} to be selected found #{actual.inspect}") unless res254 end255 end256 node_filter(:with_selected) do |node, selected|257 actual = node.all(:xpath, './/option', visible: false, wait: false).select(&:selected?).map { |option| option.text(:all) }258 (Array(selected) - actual).empty?.tap do |res|259 add_error("Expected at least #{selected.inspect} to be selected found #{actual.inspect}") unless res260 end261 end262 describe_expression_filters do |with_options: nil, **|263 desc = +''264 desc << " with at least options #{with_options.inspect}" if with_options265 desc266 end267 describe_node_filters do |options: nil, selected: nil, with_selected: nil, disabled: nil, **|268 desc = +''269 desc << " with options #{options.inspect}" if options270 desc << " with #{selected.inspect} selected" if selected271 desc << " with at least #{with_selected.inspect} selected" if with_selected272 desc << ' which is disabled' if disabled273 desc274 end275end276Capybara.add_selector(:datalist_input, locator_type: [String, Symbol]) do277 label 'input box with datalist completion'278 xpath do |locator, **options|279 xpath = XPath.descendant(:input)[XPath.attr(:list)]280 locate_field(xpath, locator, options)281 end282 filter_set(:_field, %i[disabled name placeholder])283 node_filter(:options) do |node, options|284 actual = node.find("//datalist[@id=#{node[:list]}]", visible: :all).all(:datalist_option, wait: false).map(&:value)285 (options.sort == actual.sort).tap do |res|286 add_error("Expected #{options.inspect} options found #{actual.inspect}") unless res287 end288 end289 expression_filter(:with_options) do |expr, options|290 options.inject(expr) do |xpath, option|291 xpath[XPath.attr(:list) == XPath.anywhere(:datalist)[self.class.all[:datalist_option].call(option)].attr(:id)]292 end293 end294 describe_expression_filters do |with_options: nil, **|295 desc = +''296 desc << " with at least options #{with_options.inspect}" if with_options297 desc298 end299 describe_node_filters do |options: nil, **|300 " with options #{options.inspect}" if options301 end302end303Capybara.add_selector(:option, locator_type: [String, Symbol]) do304 xpath do |locator|305 xpath = XPath.descendant(:option)306 xpath = xpath[XPath.string.n.is(locator.to_s)] unless locator.nil?307 xpath308 end309 node_filter(:disabled, :boolean) { |node, value| !(value ^ node.disabled?) }310 expression_filter(:disabled) { |xpath, val| val ? xpath : xpath[~XPath.attr(:disabled)] }311 node_filter(:selected, :boolean) { |node, value| !(value ^ node.selected?) }312 describe_expression_filters do |disabled: nil, **options|313 desc = +''314 desc << ' that is not disabled' if disabled == false315 (expression_filters.keys & options.keys).inject(desc) { |memo, ef| memo << " with #{ef} #{options[ef]}" }316 end317 describe_node_filters do |**options|318 desc = +''319 desc << ' that is disabled' if options[:disabled]320 desc << " that is#{' not' unless options[:selected]} selected" if options.key?(:selected)321 desc322 end323end324Capybara.add_selector(:datalist_option, locator_type: [String, Symbol]) do325 label 'datalist option'326 visible(:all)327 xpath do |locator|328 xpath = XPath.descendant(:option)329 xpath = xpath[XPath.string.n.is(locator.to_s) | (XPath.attr(:value) == locator.to_s)] unless locator.nil?330 xpath331 end332 node_filter(:disabled, :boolean) { |node, value| !(value ^ node.disabled?) }333 expression_filter(:disabled) { |xpath, val| val ? xpath : xpath[~XPath.attr(:disabled)] }334 describe_expression_filters do |disabled: nil, **options|335 desc = +''336 desc << ' that is not disabled' if disabled == false337 desc << describe_all_expression_filters(options)338 end339 describe_node_filters do |**options|340 ' that is disabled' if options[:disabled]341 end342end343Capybara.add_selector(:file_field, locator_type: [String, Symbol]) do344 label 'file field'345 xpath do |locator, allow_self: nil, **options|346 xpath = XPath.axis(allow_self ? :"descendant-or-self" : :descendant, :input)[347 XPath.attr(:type) == 'file'348 ]349 locate_field(xpath, locator, options)350 end351 filter_set(:_field, %i[disabled multiple name])352end353Capybara.add_selector(:label, locator_type: [String, Symbol]) do354 label 'label'355 xpath(:for) do |locator, options|356 xpath = XPath.descendant(:label)357 unless locator.nil?358 locator_matchers = XPath.string.n.is(locator.to_s) | (XPath.attr(:id) == locator.to_s)359 locator_matchers |= XPath.attr(test_id) == locator if test_id360 xpath = xpath[locator_matchers]361 end362 if options.key?(:for)363 if (for_option = options[:for].is_a?(Capybara::Node::Element) ? options[:for][:id] : options[:for])364 with_attr = XPath.attr(:for) == for_option.to_s365 labelable_elements = %i[button input keygen meter output progress select textarea]366 wrapped = !XPath.attr(:for) &367 XPath.descendant(*labelable_elements)[XPath.attr(:id) == for_option.to_s]368 xpath = xpath[with_attr | wrapped]369 end370 end371 xpath372 end373 node_filter(:for) do |node, field_or_value|374 # Non element values were handled through the expression filter375 next true unless field_or_value.is_a? Capybara::Node::Element376 if (for_val = node[:for])377 field_or_value[:id] == for_val378 else379 field_or_value.find_xpath('./ancestor::label[1]').include? node.base380 end381 end382 describe_expression_filters do |**options|383 " for element with id of \"#{options[:for]}\"" if options.key?(:for) && !options[:for].is_a?(Capybara::Node::Element)384 end385 describe_node_filters do |**options|386 " for element #{options[:for]}" if options[:for]&.is_a?(Capybara::Node::Element)387 end388end389Capybara.add_selector(:table, locator_type: [String, Symbol]) do390 xpath do |locator, caption: nil, **|391 xpath = XPath.descendant(:table)392 unless locator.nil?393 locator_matchers = (XPath.attr(:id) == locator.to_s) | XPath.descendant(:caption).is(locator.to_s)394 locator_matchers |= XPath.attr(test_id) == locator if test_id395 xpath = xpath[locator_matchers]396 end397 xpath = xpath[XPath.descendant(:caption) == caption] if caption398 xpath399 end400 expression_filter(:with_cols, valid_values: [Array]) do |xpath, cols|401 col_conditions = cols.map do |col|402 if col.is_a? Hash403 col.reduce(nil) do |xp, (header, cell_str)|404 header = XPath.descendant(:th)[XPath.string.n.is(header)]405 td = XPath.descendant(:tr)[header].descendant(:td)406 cell_condition = XPath.string.n.is(cell_str)407 cell_condition &= prev_col_position?(XPath.ancestor(:table)[1].join(xp)) if xp408 td[cell_condition]409 end410 else411 cells_xp = col.reduce(nil) do |prev_cell, cell_str|412 cell_condition = XPath.string.n.is(cell_str)413 if prev_cell414 prev_cell = XPath.ancestor(:tr)[1].preceding_sibling(:tr).join(prev_cell)415 cell_condition &= prev_col_position?(prev_cell)416 end417 XPath.descendant(:td)[cell_condition]418 end419 XPath.descendant(:tr).join(cells_xp)420 end421 end.reduce(:&)422 xpath[col_conditions]423 end424 expression_filter(:cols, valid_values: [Array]) do |xpath, cols|425 raise ArgumentError, ':cols must be an Array of Arrays' unless cols.all? { |col| col.is_a? Array }426 rows = cols.transpose427 col_conditions = rows.map { |row| match_row(row, match_size: true) }.reduce(:&)428 xpath[match_row_count(rows.size)][col_conditions]429 end430 expression_filter(:with_rows, valid_values: [Array]) do |xpath, rows|431 rows_conditions = rows.map { |row| match_row(row) }.reduce(:&)432 xpath[rows_conditions]433 end434 expression_filter(:rows, valid_values: [Array]) do |xpath, rows|435 rows_conditions = rows.map { |row| match_row(row, match_size: true) }.reduce(:&)436 xpath[match_row_count(rows.size)][rows_conditions]437 end438 describe_expression_filters do |caption: nil, **|439 " with caption \"#{caption}\"" if caption440 end441 def prev_col_position?(cell)442 XPath.position.equals(cell_position(cell))443 end444 def cell_position(cell)445 cell.preceding_sibling(:td).count.plus(1)446 end447 def match_row(row, match_size: false)448 xp = XPath.descendant(:tr)[449 if row.is_a? Hash450 row_match_cells_to_headers(row)451 else452 XPath.descendant(:td)[row_match_ordered_cells(row)]453 end454 ]455 xp = xp[XPath.descendant(:td).count.equals(row.size)] if match_size456 xp457 end458 def match_row_count(size)459 XPath.descendant(:tbody).descendant(:tr).count.equals(size) | (XPath.descendant(:tr).count.equals(size) & ~XPath.descendant(:tbody))460 end461 def row_match_cells_to_headers(row)462 row.map do |header, cell|463 header_xp = XPath.ancestor(:table)[1].descendant(:tr)[1].descendant(:th)[XPath.string.n.is(header)]464 XPath.descendant(:td)[465 XPath.string.n.is(cell) & XPath.position.equals(header_xp.preceding_sibling.count.plus(1))466 ]467 end.reduce(:&)468 end469 def row_match_ordered_cells(row)470 row_conditions = row.map do |cell|471 XPath.self(:td)[XPath.string.n.is(cell)]472 end473 row_conditions.reverse.reduce do |cond, cell|474 cell[XPath.following_sibling[cond]]475 end476 end477end478Capybara.add_selector(:table_row, locator_type: [Array, Hash]) do479 xpath do |locator|480 xpath = XPath.descendant(:tr)481 if locator.is_a? Hash482 locator.reduce(xpath) do |xp, (header, cell)|483 header_xp = XPath.ancestor(:table)[1].descendant(:tr)[1].descendant(:th)[XPath.string.n.is(header)]484 cell_xp = XPath.descendant(:td)[485 XPath.string.n.is(cell) & XPath.position.equals(header_xp.preceding_sibling.count.plus(1))486 ]487 xp[cell_xp]488 end489 else490 initial_td = XPath.descendant(:td)[XPath.string.n.is(locator.shift)]491 tds = locator.reverse.map { |cell| XPath.following_sibling(:td)[XPath.string.n.is(cell)] }.reduce { |xp, cell| xp[cell] }492 xpath[initial_td[tds]]493 end494 end495end496Capybara.add_selector(:frame, locator_type: [String, Symbol]) do497 xpath do |locator, name: nil, **|498 xpath = XPath.descendant(:iframe).union(XPath.descendant(:frame))499 unless locator.nil?500 locator_matchers = (XPath.attr(:id) == locator.to_s) | (XPath.attr(:name) == locator.to_s)501 locator_matchers |= XPath.attr(test_id) == locator if test_id502 xpath = xpath[locator_matchers]503 end504 xpath[find_by_attr(:name, name)]505 end506 describe_expression_filters do |name: nil, **|507 " with name #{name}" if name508 end509end510Capybara.add_selector(:element, locator_type: [String, Symbol]) do511 xpath do |locator, **|512 XPath.descendant.where(locator ? XPath.local_name == locator.to_s : nil)513 end514 expression_filter(:attributes, matcher: /.+/) do |xpath, name, val|515 builder(xpath).add_attribute_conditions(name => val)516 end517 node_filter(:attributes, matcher: /.+/) do |node, name, val|518 next true unless val.is_a?(Regexp)519 (val.match? node[name]).tap do |res|520 add_error("Expected #{name} to match #{val.inspect} but it was #{node[name]}") unless res521 end522 end523 describe_expression_filters do |**options|524 booleans, values = options.partition { |_k, v| [true, false].include? v }.map(&:to_h)525 desc = describe_all_expression_filters(values)526 desc + booleans.map do |k, v|527 v ? " with #{k} attribute" : "without #{k} attribute"528 end.join529 end530end531# rubocop:enable Metrics/BlockLength...
filter_set_spec.rb
Source:filter_set_spec.rb
...6 end7 it 'allows node filters' do8 fs = Capybara::Selector::FilterSet.add(:test) do9 node_filter(:node_test, :boolean) { |_node, _value| true }10 expression_filter(:expression_test, :boolean) { |_expr, _value| true }11 end12 expect(fs.node_filters.keys).to include(:node_test)13 expect(fs.node_filters.keys).not_to include(:expression_test)14 end15 it 'allows expression filters' do16 fs = Capybara::Selector::FilterSet.add(:test) do17 node_filter(:node_test, :boolean) { |_node, _value| true }18 expression_filter(:expression_test, :boolean) { |_expr, _value| true }19 end20 expect(fs.expression_filters.keys).to include(:expression_test)21 expect(fs.expression_filters.keys).not_to include(:node_test)22 end23 it 'allows node filter and expression filter with the same name' do24 fs = Capybara::Selector::FilterSet.add(:test) do25 node_filter(:test, :boolean) { |_node, _value| true }26 expression_filter(:test, :boolean) { |_expr, _value| true }27 end28 expect(fs.expression_filters[:test]).not_to eq fs.node_filters[:test]29 end30 it 'allows `filter` as an alias of `node_filter`' do31 fs = Capybara::Selector::FilterSet.add(:test) do32 filter(:node_test, :boolean) { |_node, _value| true }33 end34 expect(fs.node_filters.keys).to include(:node_test)35 end36end...
expression_filter
Using AI Code Generation
1Capybara.visit('/')2Capybara.fill_in('q', :with => 'Capybara')3Capybara.click_button('Google Search')4Capybara.expression_filter(/Capybara/) do5Capybara.click_link('Capybara')6Capybara.click_link('Capybara')7Capybara.click_link('Capybara')8Capybara.click_link('Capybara')9Capybara.click_link('Capybara')10Capybara.click_link('Capybara')11Capybara.click_link('Capybara')12Capybara.click_link('Capybara')13Capybara.click_link('Capybara')14Capybara.click_link('Capybara')15Capybara.click_link('Capybara')16Capybara.click_link('Capybara')17Capybara.click_link('Capybara')18visit('/')19fill_in('q', :with => 'Capybara')20click_button('Google Search')21expression_filter(/Capybara/) do22click_link('Capybara')23click_link('Capybara')24click_link('Capybara')25click_link('Capybara')26click_link('Capybara')27click_link('Capybara')28click_link('Capybara')29click_link('Capybara')30click_link('Capybara')31click_link('Capybara')32click_link('Capybara')33click_link('Capybara')34click_link('Capybara')35click_link('Capybara')
expression_filter
Using AI Code Generation
1Capybara.expression_filter(:foo) do |node, args|2Capybara.expression_filter(:foo) do |node, args|3Capybara.expression_filter(:foo) do |node, args|4Capybara.expression_filter(:foo) do |node, args|5Capybara.expression_filter(:foo) do |node, args|6Capybara.expression_filter(:foo) do |node, args|7Capybara.expression_filter(:foo) do |node, args|8Capybara.expression_filter(:foo) do |node, args|9Capybara.expression_filter(:foo) do |node, args|10Capybara.expression_filter(:foo) do |node, args|11puts Capybara.evaluate_script('document.body.innerHTML')
expression_filter
Using AI Code Generation
1 config.allow_url("http://www.google.co.in")2 config.allow_url("http://www.google.com")3 config.allow_url("http://www.google.com/search")4 config.allow_url("http://www.google.com/search?complete=1")5 config.allow_url("http://www.google.com/search?complete=1&hl=en")
expression_filter
Using AI Code Generation
1Capybara.expression_filter(:foo) do |node, args|2Capybara.expression_filter(:foo) do |node, args|3Capybara.expression_filter(:foo) do |node, args|4Capybara.expression_filter(:foo) do |node, args|5Capybara.expression_filter(:foo) do |node, args|6Capybara.expression_filter(:foo) do |node, args|7Capybara.expression_filter(:foo) do |node, args|8Capybara.expression_filter(:foo) do |node, args|9Capybara.expression_filter(:foo) do |node, args|10Capybara.expression_filter(:foo) do |node, args|
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!