Class: AePageObjects::Element

Inherits:
Node
  • Object
show all
Defined in:
lib/ae_page_objects/element.rb

Direct Known Subclasses

Checkbox, Collection, Form, Select

Constant Summary

Constants inherited from Node

Node::METHODS_TO_DELEGATE_TO_NODE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

current_url, #current_url, current_url_without_params, #current_url_without_params, #element, #node, #stale!, #stale?

Methods included from Dsl

#collection, #element, #element_attributes, #form_for, #inherited, #is_loaded, #is_loaded_blocks

Methods included from InternalHelpers

#ensure_class_for_param!

Constructor Details

#initialize(parent, options_or_locator = {}) ⇒ Element

Returns a new instance of Element.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ae_page_objects/element.rb', line 7

def initialize(parent, options_or_locator = {})
  @parent       = parent
  @locator      = nil
  @name         = nil

  configure(parse_options(options_or_locator))

  raise ArgumentError, ":name or :locator is required" unless @name || @locator

  @locator ||= default_locator

  super(scoped_node)
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



5
6
7
# File 'lib/ae_page_objects/element.rb', line 5

def parent
  @parent
end

Instance Method Details

#__full_name__Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ae_page_objects/element.rb', line 41

def __full_name__
  if parent.respond_to?(:__full_name__)
    name_parts = [ parent.__full_name__, __name__ ].compact
    if name_parts.empty?
      nil
    else
      name_parts.join('_')
    end
  else
    __name__
  end
end

#__name__Object



58
59
60
# File 'lib/ae_page_objects/element.rb', line 58

def __name__
  @name
end

#browserObject



33
34
35
# File 'lib/ae_page_objects/element.rb', line 33

def browser
  @browser ||= document.browser
end

#documentObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ae_page_objects/element.rb', line 21

def document
  @document ||= begin
    node = self.parent

    until node.is_a?(Document)
      node = node.parent
    end

    node
  end
end

#full_nameObject



54
55
56
# File 'lib/ae_page_objects/element.rb', line 54

def full_name
  __full_name__
end

#nameObject



62
63
64
# File 'lib/ae_page_objects/element.rb', line 62

def name
  __name__
end

#reload_ancestorsObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/ae_page_objects/element.rb', line 76

def reload_ancestors
  # Reload the parent first, traversing up until we hit the document
  parent.reload_ancestors if parent.respond_to?(:reload_ancestors)

  return unless @node.respond_to?(:reload)

  # Tell the capybara node to reload
  @node.reload
  ensure_loaded!
end

#to_sObject



66
67
68
69
70
# File 'lib/ae_page_objects/element.rb', line 66

def to_s
  super.tap do |str|
    str << "@name:<#{@name}>; #@locator:<#{@locator}>"
  end
end

#using_default_locator?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/ae_page_objects/element.rb', line 72

def using_default_locator?
  @locator == default_locator
end

#windowObject



37
38
39
# File 'lib/ae_page_objects/element.rb', line 37

def window
  @window ||= document.window
end