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 included from Node::Methods

Node::Methods::METHODS_TO_DELEGATE_TO_NODE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Dsl

#collection, #element, #form_for, #inherited

Methods included from InternalHelpers

#ensure_class_for_param!

Methods included from Node::ClassMethods

#current_url, #current_url_without_params, #new_subclass

Methods included from Concerns::Staleable

#node, #stale?

Methods included from Node::Methods

#current_url, #current_url_without_params, #node

Constructor Details

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

Returns a new instance of Element.

Raises:

  • (ArgumentError)


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

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.



3
4
5
# File 'lib/ae_page_objects/element.rb', line 3

def parent
  @parent
end

Instance Method Details

#__full_name__Object



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

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



56
57
58
# File 'lib/ae_page_objects/element.rb', line 56

def __name__
  @name
end

#browserObject



31
32
33
# File 'lib/ae_page_objects/element.rb', line 31

def browser
  @browser ||= document.browser
end

#documentObject



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

def document
  @document ||= begin
    node = self.parent
    
    until node.is_a?(::AePageObjects::Document)
      node = node.parent
    end
    
    node
  end
end

#full_nameObject



52
53
54
# File 'lib/ae_page_objects/element.rb', line 52

def full_name
  __full_name__
end

#nameObject



60
61
62
# File 'lib/ae_page_objects/element.rb', line 60

def name
  __name__
end

#to_sObject



64
65
66
67
68
# File 'lib/ae_page_objects/element.rb', line 64

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

#using_default_locator?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/ae_page_objects/element.rb', line 70

def using_default_locator?
  @locator == default_locator
end

#windowObject



35
36
37
# File 'lib/ae_page_objects/element.rb', line 35

def window
  @window ||= document.window
end