Class: PageFieldConstructor

Inherits:
Object
  • Object
show all
Defined in:
lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb

Overview

end Page

Class Method Summary collapse

Class Method Details

.add_click_method(page_object, name) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb', line 154

def PageFieldConstructor.add_click_method(page_object, name)
  s = <<-CLICK
      def page_object.click_#{name}
#          puts "in #{name} click method"
        #{name}_field.click
      end    
  CLICK
  #    page_object.class.module_eval(s) # do not do this - want to add methods (field) to the object, not the class!
  eval(s)
end

.add_fields(page_object, name, type, key, value) ⇒ Object

Defines methods to access the field of specified type, by specified key & value



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb', line 95

def PageFieldConstructor.add_fields(page_object, name, type, key, value)

  # Fields cannot have the following names : name
  raise "Field on page #{page_object.name} with name of #{name} is not allowed" if ZZnamezzConfig::DISALLOWED_FIELD_NAMES.include?(name)
  
  case type
  when :button
    real_type = :input
  else
    real_type = type
  end
  
  # add accessor to field
  s = <<-METHOD
  def page_object.#{name}_field
#      puts "in #{name} method"
    @browser.#{real_type}(#{key.inspect} => "#{value}")
  end    
  METHOD
  #    page_object.class.module_eval(s) # do not do this - want to add methods (field) to the object, not the class!
  eval(s)

  case type
    when :text_field
      add_read_method(page_object, name)
      add_write_method(page_object, name)
    when :button
      add_click_method(page_object, name)
    when :link
      add_read_method(page_object, name)
      add_click_method(page_object, name)
    else
      add_read_method(page_object, name)
  end

end

.add_read_method(page_object, name) ⇒ Object



132
133
134
135
136
137
138
139
140
141
# File 'lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb', line 132

def PageFieldConstructor.add_read_method(page_object, name)
  s = <<-READ
      def page_object.#{name}
#          puts "in #{name} read method"
        #{name}_field.text # value
      end    
  READ
  #    page_object.class.module_eval(s) # do not do this - want to add methods (field) to the object, not the class!
  eval(s)
end

.add_write_method(page_object, name) ⇒ Object



143
144
145
146
147
148
149
150
151
152
# File 'lib/taft_files/framework/zznamezz/watir/pages/page_objects.rb', line 143

def PageFieldConstructor.add_write_method(page_object, name)
  s = <<-WRITE
      def page_object.#{name}=(v)
#          puts "in #{name} write method"
        #{name}_field.set(v) 
      end    
  WRITE
  #    page_object.class.module_eval(s) # do not do this - want to add methods (field) to the object, not the class!
  eval(s)
end