Module: Watir::Reflector

Included in:
ElementCollections
Defined in:
lib/watirloo/extension/watir_reflector.rb

Overview

Watirloo::Page objects scaffold creation. Talks to the current page and reflects the watir elements to be used for semantic test objects tests.

Instance Method Summary collapse

Instance Method Details

#get_attribs(item) ⇒ Object

glean(:text_fields, [:id, :name, :value] glean(:radios, [:id, :name, :value]) glean and make a map of types and attributes needed for reflection this should be private I think



28
29
30
31
32
33
34
35
36
# File 'lib/watirloo/extension/watir_reflector.rb', line 28

def get_attribs(item)
  attribs = [:id, :name, :value]
  h = {}
  attribs.each do |k|
    v = item.attribute_value k.to_s
    h[k] = v
  end
  h
end

#get_how_what(h) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/watirloo/extension/watir_reflector.rb', line 38

def get_how_what h
  how, what = '', ''
  if h[:id] != '' #First Choice: if id is not blank then we'll use it
    how, what = :id, h[:id]
  elsif h[:name] != '' #Second Choice: if name is not blank then we'll use it instead of id
    how, what = :name, h[:name]
  elsif h[:value] != ''
    how, what = :value, h[:value]
  end
  [how, what]
end

#reflectObject

public interface for Reflector. ie.reflect # => returns object definitions for entire dom using ie as container ie.frame(‘main’).select_lists.reflect# => returns definitions for select_lists only contained by the frame you can be as granular as needed



55
56
57
# File 'lib/watirloo/extension/watir_reflector.rb', line 55

def reflect
  puts "I has not exist. Implements me please"
end

#suggest_def_name(how) ⇒ Object

cleanup the def name for some kind of semantic name



17
18
19
20
21
22
# File 'lib/watirloo/extension/watir_reflector.rb', line 17

def suggest_def_name(how)
  how.gsub!(/_+/,'_') # double underscores to one
  how.gsub!(/^_/, '') # if it begins with undrscore kill it.
  how.gsub!(/\s+/, '_') # kill spaces if for some strange reason they exist
  how.underscore #Any CamelCase will be converted to camel_no_case
end