lib/watir/locators/element/selector_builder.rb in watir-6.5.0 vs lib/watir/locators/element/selector_builder.rb in watir-6.6.0

- old
+ new

@@ -1,10 +1,10 @@ module Watir module Locators class Element class SelectorBuilder - VALID_WHATS = [Array, String, Regexp, TrueClass, FalseClass].freeze + 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 @@ -33,13 +33,16 @@ when :visible unless what.is_a?(TrueClass) || what.is_a?(FalseClass) raise TypeError, "expected TrueClass or FalseClass, got #{what.inspect}:#{what.class}" end else - if what.is_a?(Array) && how != :class + 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 + raise TypeError, "Symbol is not a valid value" + end unless VALID_WHATS.any? { |t| what.is_a? t } raise TypeError, "expected one of #{VALID_WHATS.inspect}, got #{what.inspect}:#{what.class}" end end end @@ -47,21 +50,24 @@ def should_use_label_element? !valid_attribute?(:label) end def build(selector) - given_xpath_or_css(selector) || build_wd_selector(selector) + return given_xpath_or_css(selector) if selector.key?(:xpath) || selector.key?(:css) + built = build_wd_selector(selector) + Watir.logger.debug "Converted #{selector.inspect} to #{built}" + built end def xpath_builder @xpath_builder ||= xpath_builder_class.new(should_use_label_element?) end private def normalize_selector(how, what) case how - when :tag_name, :text, :xpath, :index, :class, :label, :css, :visible + when :tag_name, :text, :xpath, :index, :class, :label, :css, :visible, :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]