Module: Watirsome
- Defined in:
- lib/watirsome.rb,
lib/watirsome/errors.rb,
lib/watirsome/version.rb,
lib/watirsome/accessors.rb,
lib/watirsome/initializers.rb
Overview
General module which holds all appropriate Watirsome API. Includers can use accessors and initializers API.
Defined Under Namespace
Modules: Accessors, Initializers
Constant Summary collapse
- CannotPluralizeError =
Class.new(StandardError)
- VERSION =
'0.2.0'.freeze
Class Method Summary collapse
-
.clickable ⇒ Array<Symbol>
Returns array of clickable elements.
-
.clickable?(tag) ⇒ Boolean
Returns true if tag can have click accessor.
-
.included(kls) ⇒ Object
self.
-
.plural?(method) ⇒ Boolean
private
Returns true if method is element accessor in plural form.
-
.pluralize(method) ⇒ Symbol
private
Pluralizes element.
-
.readable ⇒ Array<Symbol>
Returns array of readable elements.
-
.readable?(tag) ⇒ Boolean
Returns true if tag can have text accessor.
-
.settable ⇒ Array<Symbol>
Returns array of settable elements.
-
.settable?(tag) ⇒ Boolean
Returns true if tag can have set accessor.
-
.watir_methods ⇒ Array<Sybmol>
Returns array of Watir element methods.
-
.watirsome?(method) ⇒ Boolean
Return true if method can be proxied to Watir, false otherwise.
Class Method Details
.clickable ⇒ Array<Symbol>
Returns array of clickable elements.
84 85 86 |
# File 'lib/watirsome.rb', line 84 def clickable @clickable ||= %i[a link button] end |
.clickable?(tag) ⇒ Boolean
Returns true if tag can have click accessor.
106 107 108 |
# File 'lib/watirsome.rb', line 106 def clickable?(tag) clickable.include? tag.to_sym end |
.included(kls) ⇒ Object
self
212 213 214 215 216 |
# File 'lib/watirsome.rb', line 212 def self.included(kls) kls.extend Watirsome::Accessors::ClassMethods kls.__send__ :include, Watirsome::Accessors::InstanceMethods kls.__send__ :include, Watirsome::Initializers end |
.plural?(method) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if method is element accessor in plural form.
176 177 178 179 180 181 182 183 184 |
# File 'lib/watirsome.rb', line 176 def plural?(method) str = method.to_s plr = str.to_sym sgl = str.sub(/e?s$/, '').to_sym !str.match(/s$/).nil? && Watirsome.watir_methods.include?(plr) && Watirsome.watir_methods.include?(sgl) end |
.pluralize(method) ⇒ Symbol
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Pluralizes element.
197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/watirsome.rb', line 197 def pluralize(method) str = method.to_s # first try to pluralize with "s" if Watirsome.watir_methods.include?(:"#{str}s") :"#{str}s" # now try to pluralize with "es" elsif Watirsome.watir_methods.include?(:"#{str}es") :"#{str}es" else # looks like we can't pluralize it raise Errors::CannotPluralizeError, "Can't find plural form for #{str}!" end end |
.readable ⇒ Array<Symbol>
Returns array of readable elements.
76 77 78 |
# File 'lib/watirsome.rb', line 76 def readable @readable ||= %i[div span p h1 h2 h3 h4 h5 h6 select_list text_field textarea checkbox radio] end |
.readable?(tag) ⇒ Boolean
Returns true if tag can have text accessor.
134 135 136 |
# File 'lib/watirsome.rb', line 134 def readable?(tag) readable.include? tag.to_sym end |
.settable ⇒ Array<Symbol>
Returns array of settable elements.
92 93 94 |
# File 'lib/watirsome.rb', line 92 def settable @settable ||= %i[text_field file_field textarea checkbox select_list] end |
.settable?(tag) ⇒ Boolean
Returns true if tag can have set accessor.
120 121 122 |
# File 'lib/watirsome.rb', line 120 def settable?(tag) settable.include? tag.to_sym end |
.watir_methods ⇒ Array<Sybmol>
Returns array of Watir element methods.
142 143 144 145 146 147 148 149 |
# File 'lib/watirsome.rb', line 142 def watir_methods unless @watir_methods @watir_methods = Watir::Container.instance_methods @watir_methods.delete(:extract_selector) end @watir_methods end |
.watirsome?(method) ⇒ Boolean
Return true if method can be proxied to Watir, false otherwise.
161 162 163 |
# File 'lib/watirsome.rb', line 161 def watirsome?(method) Watirsome.watir_methods.include? method.to_sym end |