lib/watir-classic/supported_elements.rb in watir-classic-3.3.0 vs lib/watir-classic/supported_elements.rb in watir-classic-3.4.0
- old
+ new
@@ -1,10 +1,33 @@
module Watir
module Container
class << self
- def support_element method_name, args={}
+
+ private
+
+ # @!macro support_element
+ # @!method $1
+ # Create an $1 html element instance.
+ #
+ # Elements can be searched by using different locators.
+ #
+ # @example Search by partial text:
+ # browser.$1(:text => /partial text/)
+ #
+ # @example Search by id:
+ # browser.$1(:id => "htmlid")
+ #
+ # @example Search by any arbitrary html attribute:
+ # browser.$1(:foo => "value-of-foo-attribute)
+ #
+ # @example Search by multiple attributes, all provided locators should evaluate to true - only then element is considered to be found:
+ # browser.$1(:text => "some text", :class => "css class")
+ #
+ # @example It is also possible to search for multiple elements of the same type like this:
+ # browser.divs(:class => "foo") # => instance of Watir::DivCollection
+ def support_element(method_name, args={})
klass = args[:class] || method_name.to_s.capitalize
super_class = args[:super_class] || "Element"
unless Watir.const_defined? klass
Watir.class_eval %Q[class #{klass} < #{super_class}; end]
@@ -26,24 +49,12 @@
#{klass}Collection.new(self, specifiers)
end
]
end
- private :support_element
end
- def format_specifiers(tag_name, how, what)
- defaults = {:tag_name => [tag_name].flatten.map(&:to_s)}
- formatted_specifiers = defaults.merge(what ? {how => what} : how)
- if (formatted_specifiers[:css] || formatted_specifiers[:xpath]) && formatted_specifiers.size > 2
- raise ArgumentError, ":xpath and :css specifiers should be the only one when used in #{formatted_specifiers.inspect}"
- end
- formatted_specifiers
- end
-
- private :format_specifiers
-
support_element :a, :class => :Link
alias_method :link, :a
alias_method :links, :as
support_element :abbr
support_element :address, :plural => :addresses
@@ -101,11 +112,10 @@
support_element :head
support_element :header
support_element :hgroup
support_element :hidden, :super_class => :TextField, :super_collection => :InputElement
support_element :hr
- # html and htmls?!
support_element :i
support_element :img, :class => :Image
alias_method :image, :img
alias_method :images, :imgs
support_element :input, :super_class => :InputElement
@@ -166,7 +176,19 @@
support_element :u
support_element :ul
support_element :var
support_element :video
support_element :wbr
+
+ private
+
+ def format_specifiers(tag_name, how, what)
+ defaults = {:tag_name => [tag_name].flatten.map(&:to_s)}
+ formatted_specifiers = defaults.merge(what ? {how => what} : how)
+ if (formatted_specifiers[:css] || formatted_specifiers[:xpath]) && formatted_specifiers.size > 2
+ raise ArgumentError, ":xpath and :css specifiers should be the only one when used in #{formatted_specifiers.inspect}"
+ end
+ formatted_specifiers
+ end
+
end
end