Class: AutomationObject::BluePrint::PageObjectAdapter::Composite

Inherits:
Composite
  • Object
show all
Defined in:
lib/automation_object/blue_print/page_object_adapter/composite.rb

Overview

Base composite for PageObject adapter

Instance Attribute Summary collapse

Attributes inherited from Composite

#children, #location, #name, #parent

Instance Method Summary collapse

Methods inherited from Composite

#add_has_many_relationships, #add_has_one_relationships, has_many, has_many_relationships, has_one, has_one_relationships, #top

Methods included from Reflection

#add_alias, #add_attribute

Methods included from CompositeHook

#after_create_run, #before_create_run, included

Constructor Details

#initialize(user_defined_module, constant = nil, name = :top, parent = nil, location = 'top') ⇒ Composite

Returns a new instance of Composite

Parameters:

  • user_defined_module (Module)

    runtime defined module for loaded page objects

  • constant (Class) (defaults to: nil)

    class to build composite off of

  • name (Symbol) (defaults to: :top)

    name of composite element

  • parent (Object, nil) (defaults to: nil)

    parent composite object

  • location (String) (defaults to: 'top')

    string location for error/debugging purposes



24
25
26
27
28
29
# File 'lib/automation_object/blue_print/page_object_adapter/composite.rb', line 24

def initialize(user_defined_module, constant = nil, name = :top, parent = nil, location = 'top')
  self.user_defined_module = user_defined_module
  self.constant = constant.is_a?(Class) ? constant : nil

  super(name, parent, location)
end

Instance Attribute Details

#constantAutomationObject::PageObject::Base



17
18
19
# File 'lib/automation_object/blue_print/page_object_adapter/composite.rb', line 17

def constant
  @constant
end

#user_defined_moduleModule

Returns:

  • (Module)


14
15
16
# File 'lib/automation_object/blue_print/page_object_adapter/composite.rb', line 14

def user_defined_module
  @user_defined_module
end

Instance Method Details

#create_composite(constant, interface, name) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/automation_object/blue_print/page_object_adapter/composite.rb', line 69

def create_composite(constant, interface, name)
  # Get the Composite Class that corresponds with the PageObjectAdapter Class
  class_name = interface.name.split('::').last
  child_location = location + "[#{name}]"

  require_relative "../composite/#{class_name.to_underscore}"
  composite_class = AutomationObject::BluePrint::Composite.const_get(class_name)

  composite_class.new(interface.new(user_defined_module, constant, name, self, child_location))
end

#get_child(name, options) ⇒ Object

Get child of composite

Parameters:

  • name (Symbol)

    name of child

  • options (Hash)

    options for child



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/automation_object/blue_print/page_object_adapter/composite.rb', line 35

def get_child(name, options)
  self.constant.constants.each { |constant_symbol|
    constant = self.constant.const_get(constant_symbol)

    # Check to see if constant is a child class of the public PageObject interface
    next unless constant < get_page_object(options[:interface])

    name = constant.name.split('::').last.to_underscore.to_sym
    return create_composite(constant, options[:interface], name)
  }

  nil
end

#get_children(name, options) ⇒ Hash

Get children of composite

Parameters:

  • name (Symbol)

    name of child

  • options (Hash)

    options for child

Returns:

  • (Hash)

    return children and names



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/automation_object/blue_print/page_object_adapter/composite.rb', line 53

def get_children(name, options)
  new_children = {}

  self.constant.constants.each { |constant_symbol|
    constant = self.constant.const_get(constant_symbol)

    # Check to see if constant is a child class of the public PageObject interface
    next unless constant < get_page_object(options[:interface])

    name = constant.name.split('::').last.to_underscore.to_sym
    new_children[name] = create_composite(constant, options[:interface], name)
  }

  new_children
end

#get_page_object(adapter_interface) ⇒ Object



80
81
82
83
# File 'lib/automation_object/blue_print/page_object_adapter/composite.rb', line 80

def get_page_object(adapter_interface)
  name = adapter_interface.name.split('::').last.to_sym
  AutomationObject::PageObject.const_get(name)
end

#get_property(name) ⇒ Object

Parameters:

  • name (Symbol)

Returns:

  • (Object)


87
88
89
# File 'lib/automation_object/blue_print/page_object_adapter/composite.rb', line 87

def get_property(name)
  self.constant.get_property(name)
end