mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Add LocatorFilter class
This commit is contained in:
parent
5931e249a7
commit
f4ba9f4c1f
4 changed files with 26 additions and 3 deletions
|
@ -309,7 +309,7 @@ module Capybara
|
|||
def matches_locator_filter?(node)
|
||||
return true if @selector.locator_filter.nil?
|
||||
|
||||
@selector.locator_filter.call(node, @locator)
|
||||
@selector.locator_filter.matches?(node, @locator, @selector)
|
||||
end
|
||||
|
||||
def matches_system_filters?(node)
|
||||
|
|
|
@ -2,3 +2,4 @@
|
|||
|
||||
require 'capybara/selector/filters/node_filter'
|
||||
require 'capybara/selector/filters/expression_filter'
|
||||
require 'capybara/selector/filters/locator_filter'
|
||||
|
|
21
lib/capybara/selector/filters/locator_filter.rb
Normal file
21
lib/capybara/selector/filters/locator_filter.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'capybara/selector/filters/base'
|
||||
|
||||
module Capybara
|
||||
class Selector
|
||||
module Filters
|
||||
class LocatorFilter < NodeFilter
|
||||
def initialize(block, **options)
|
||||
super(nil, nil, block, options)
|
||||
end
|
||||
|
||||
def matches?(node, value, context = nil)
|
||||
apply(node, nil, value, true, context)
|
||||
rescue Capybara::ElementNotFound
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -348,8 +348,9 @@ module Capybara
|
|||
|
||||
def_delegators :@filter_set, :node_filter, :expression_filter, :filter
|
||||
|
||||
def locator_filter(&block)
|
||||
@locator_filter = block if block
|
||||
def locator_filter(*types, **options, &block)
|
||||
types.each { |type| options[type] = true }
|
||||
@locator_filter = Filters::LocatorFilter.new(block, options) if block
|
||||
@locator_filter
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue