lib/watir/locators/element/selector_builder.rb in watir-6.9.1 vs lib/watir/locators/element/selector_builder.rb in watir-6.10.0
- old
+ new
@@ -1,16 +1,19 @@
module Watir
module Locators
class Element
class SelectorBuilder
+ attr_reader :custom_attributes
+
VALID_WHATS = [Array, String, Regexp, TrueClass, FalseClass, ::Symbol].freeze
WILDCARD_ATTRIBUTE = /^(aria|data)_(.+)$/
def initialize(query_scope, selector, valid_attributes)
@query_scope = query_scope # either element or browser
@selector = selector
@valid_attributes = valid_attributes
+ @custom_attributes = []
end
def normalized_selector
selector = {}
@@ -32,10 +35,14 @@
end
when :visible
unless what.is_a?(TrueClass) || what.is_a?(FalseClass)
raise TypeError, "expected TrueClass or FalseClass, got #{what.inspect}:#{what.class}"
end
+ when :visible_text
+ unless what.is_a?(String) || what.is_a?(Regexp)
+ raise TypeError, "expected String or Regexp, got #{what.inspect}:#{what.class}"
+ end
else
if what.is_a?(Array) && how != :class && how != :class_name
raise TypeError, "Only :class locator can have a value of an Array"
end
if what.is_a?(Symbol) && how != :adjacent
@@ -64,26 +71,26 @@
private
def normalize_selector(how, what)
case how
- when :tag_name, :text, :xpath, :index, :class, :label, :css, :visible, :adjacent
+ when :tag_name, :text, :xpath, :index, :class, :label, :css, :visible, :visible_text, :adjacent
# include :class since the valid attribute is 'class_name'
# include :for since the valid attribute is 'html_for'
[how, what]
when :class_name
[:class, what]
when :caption
[:text, what]
else
- assert_valid_as_attribute how
+ check_custom_attribute how
[how, what]
end
end
- def assert_valid_as_attribute(attribute)
+ def check_custom_attribute(attribute)
return if valid_attribute?(attribute) || attribute.to_s =~ WILDCARD_ATTRIBUTE
- raise Exception::MissingWayOfFindingObjectException, "invalid attribute: #{attribute.inspect}"
+ @custom_attributes << attribute.to_s
end
def given_xpath_or_css(selector)
xpath = selector.delete(:xpath)
css = selector.delete(:css)