Module: Watirsome

Defined in:
lib/watirsome.rb,
lib/watirsome/errors.rb,
lib/watirsome/version.rb,
lib/watirsome/accessors.rb,
lib/watirsome/initializers.rb

Defined Under Namespace

Modules: Accessors, Errors, Initializers

Constant Summary collapse

VERSION =
'0.1.6'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clickableArray<Symbol>

Returns array of clickable elements.

Returns:

  • (Array<Symbol>)


8
9
10
# File 'lib/watirsome.rb', line 8

def clickable
  @clickable
end

.readableArray<Symbol>

Returns array of readable elements.

Returns:

  • (Array<Symbol>)


5
6
7
# File 'lib/watirsome.rb', line 5

def readable
  @readable
end

.selectableArray<Symbol>

Returns array of selectable elements.

Returns:

  • (Array<Symbol>)


14
15
16
# File 'lib/watirsome.rb', line 14

def selectable
  @selectable
end

.settableArray<Symbol>

Returns array of settable elements.

Returns:

  • (Array<Symbol>)


11
12
13
# File 'lib/watirsome.rb', line 11

def settable
  @settable
end

Class Method Details

.clickable?(tag) ⇒ Boolean

Returns true if tag can have click accessor.

Parameters:

  • method (Symbol, String)

Returns:

  • (Boolean)


54
55
56
# File 'lib/watirsome.rb', line 54

def clickable?(tag)
  clickable.include? tag.to_sym
end

.included(kls) ⇒ Object



158
159
160
161
162
# File 'lib/watirsome.rb', line 158

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.

Examples:

Watirsome.plural? :div   #=> false
Watirsome.plural? :divs  #=> true

Parameters:

  • method (Symbol, String)

Returns:

  • (Boolean)


122
123
124
125
126
127
128
# File 'lib/watirsome.rb', line 122

def plural?(method)
  str = method.to_s
  plr = str.to_sym
  sgl = str.sub(/e?s$/, '').to_sym

  /s$/ === str && 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.

Examples:

Watirsome.pluralize :div       #=> :divs
Watirsome.pluralize :checkbox  #=> :checkboxes

Parameters:

  • method (Symbol, String)

Returns:

  • (Symbol)


141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/watirsome.rb', line 141

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?(tag) ⇒ Boolean

Returns true if tag can have text accessor.

Parameters:

  • method (Symbol, String)

Returns:

  • (Boolean)


84
85
86
# File 'lib/watirsome.rb', line 84

def readable?(tag)
  readable.include? tag.to_sym
end

.selectable?(tag) ⇒ Boolean

Returns true if tag can have select accessor.

Parameters:

  • method (Symbol, String)

Returns:

  • (Boolean)


74
75
76
# File 'lib/watirsome.rb', line 74

def selectable?(tag)
  selectable.include? tag.to_sym
end

.settable?(tag) ⇒ Boolean

Returns true if tag can have set accessor.

Parameters:

  • method (Symbol, String)

Returns:

  • (Boolean)


64
65
66
# File 'lib/watirsome.rb', line 64

def settable?(tag)
  settable.include? tag.to_sym
end

.watir_methodsArray<Sybmol>

Returns array of Watir element methods.

Returns:

  • (Array<Sybmol>)


92
93
94
95
96
97
98
99
# File 'lib/watirsome.rb', line 92

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.

Parameters:

  • method (Symbol)

Returns:

  • (Boolean)


107
108
109
# File 'lib/watirsome.rb', line 107

def watirsome?(method)
  Watirsome.watir_methods.include? method.to_sym
end