class PageFieldConstructor

Public Class Methods

add_click_method(page_object, name) click to toggle source
# 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) click to toggle source

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

# 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) click to toggle source
# 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) click to toggle source
# 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