Module: WorldPages

Defined in:
lib/testcentricity_web/world_extensions.rb

Instance Method Summary collapse

Instance Method Details

#instantiate_page_objectsObject

instantiate and register all page objects specified in page_objects method



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/testcentricity_web/world_extensions.rb', line 32

def instantiate_page_objects
  # return if page objects have already been instantiated and registered
  return if TestCentricity::PageManager.loaded?

  # instantiate all page objects
  @pages = {}
  page_objects.each do |page_object, page_class|
    obj = page_class.new
    @pages[page_object] = obj unless @pages.has_key?(page_object)
    page_names = obj.page_name
    page_names = Array(page_names) if page_names.is_a? String
    page_names.each do |name|
      page_key = name.gsub(/\s+/, '').downcase.to_sym
      @pages[page_key] = obj unless @pages.has_key?(page_key)
    end
    # define page object accessor method
    define_method(page_object) do
      if instance_variable_defined?(:"@#{page_object}")
        instance_variable_get(:"@#{page_object}")
      else
        instance_variable_set(:"@#{page_object}", TestCentricity::PageManager.find_page(page_object))
      end
    end
  end
  # register all page objects with PageManager
  TestCentricity::PageManager.register_page_objects(@pages)
end