Class: AePageObjects::ElementProxy

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

Instance Method Summary collapse

Constructor Details

#initialize(element_class, *args) ⇒ ElementProxy

Returns a new instance of ElementProxy.



12
13
14
15
16
17
# File 'lib/ae_page_objects/element_proxy.rb', line 12

def initialize(element_class, *args)
  @element_class = element_class
  @args          = args

  @loaded_element = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



123
124
125
126
127
128
129
# File 'lib/ae_page_objects/element_proxy.rb', line 123

def method_missing(name, *args, &block)
  if name == :class
    return @element_class
  end

  implicit_element.__send__(name, *args, &block)
end

Instance Method Details

#absent?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/ae_page_objects/element_proxy.rb', line 45

def absent?
  wait_until_absent
  true
rescue ElementNotAbsent
  false
end

#hidden?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'lib/ae_page_objects/element_proxy.rb', line 26

def hidden?
  wait_until_hidden
  true
rescue ElementNotHidden
  false
end

#is_a?(type) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/ae_page_objects/element_proxy.rb', line 115

def is_a?(type)
  type == @element_class || type == ElementProxy
end

#kind_of?(type) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/ae_page_objects/element_proxy.rb', line 119

def kind_of?(type)
  is_a?(type)
end

#not_present?Boolean

Returns:

  • (Boolean)


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

def not_present?
  warn "[DEPRECATION WARNING]: AePageObjects::Element#not_present? is deprecated and will be removed in version 2.0.0. Use AePageObjects::Element#absent? instead."
  absent?
end

#not_visible?Boolean

Returns:

  • (Boolean)


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

def not_visible?
  warn "[DEPRECATION WARNING]: AePageObjects::Element#not_visible? is deprecated and will be removed in version 2.0.0. Use AePageObjects::Element#hidden? instead."
  hidden?
end

#presenceObject



57
58
59
60
61
# File 'lib/ae_page_objects/element_proxy.rb', line 57

def presence
  implicit_element
rescue LoadingElementFailed
  nil
end

#present?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/ae_page_objects/element_proxy.rb', line 38

def present?
  wait_until_present
  true
rescue ElementNotPresent
  false
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/ae_page_objects/element_proxy.rb', line 131

def respond_to?(*args)
  super || @element_class.allocate.respond_to?(*args)
end

#visible?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
# File 'lib/ae_page_objects/element_proxy.rb', line 19

def visible?
  wait_until_visible
  true
rescue ElementNotVisible
  false
end

#wait_for_absence(timeout = nil) ⇒ Object



110
111
112
113
# File 'lib/ae_page_objects/element_proxy.rb', line 110

def wait_for_absence(timeout = nil)
  warn "[DEPRECATION WARNING]: AePageObjects::Element#wait_for_absence is deprecated and will be removed in version 2.0.0. Use AePageObjects::Element#wait_until_absent instead."
  wait_until_absent(timeout)
end

#wait_for_presence(timeout = nil) ⇒ Object



95
96
97
98
# File 'lib/ae_page_objects/element_proxy.rb', line 95

def wait_for_presence(timeout = nil)
  warn "[DEPRECATION WARNING]: AePageObjects::Element#wait_for_presence is deprecated and will be removed in version 2.0.0. Use AePageObjects::Element#wait_until_present instead."
  wait_until_present(timeout)
end

#wait_until_absent(timeout = nil) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'lib/ae_page_objects/element_proxy.rb', line 100

def wait_until_absent(timeout = nil)
  is_absent = Waiter.wait_until(timeout) do
    check_absence
  end

  unless is_absent
    raise ElementNotAbsent, "element_class: #{@element_class}, options: #{@options.inspect}"
  end
end

#wait_until_hidden(timeout = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/ae_page_objects/element_proxy.rb', line 74

def wait_until_hidden(timeout = nil)
  is_hidden = Waiter.wait_until(timeout) do
    inst = presence
    inst.nil? || ! inst.visible?
  end

  unless is_hidden
    raise ElementNotHidden, "element_class: #{@element_class}, options: #{@options.inspect}"
  end
end

#wait_until_present(timeout = nil) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/ae_page_objects/element_proxy.rb', line 85

def wait_until_present(timeout = nil)
  is_present = Waiter.wait_until(timeout) do
    ! presence.nil?
  end

  unless is_present
    raise ElementNotPresent, "element_class: #{@element_class}, options: #{@options.inspect}"
  end
end

#wait_until_visible(timeout = nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/ae_page_objects/element_proxy.rb', line 63

def wait_until_visible(timeout = nil)
  is_visible = Waiter.wait_until(timeout) do
    inst = presence
    ! inst.nil? && inst.visible?
  end

  unless is_visible
    raise ElementNotVisible, "element_class: #{@element_class}, options: #{@options.inspect}"
  end
end