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.



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

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



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ae_page_objects/element_proxy.rb', line 96

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

  implicit_element.__send__(name, *args, &block)
rescue Selenium::WebDriver::Error::StaleElementReferenceError
  #
  # A StaleElementReferenceError can occur when a selenium node is referenced but is no longer attached to the DOM.
  # In this case we need to work our way up the element tree to make sure we are referencing the latest DOM nodes.
  #
  # In some cases we get this exception and cannot recover from it.  This usually occurs when code outside of
  # ae_page_objects calls capybara queries directly.  In these cases we need to raise the original exception
  #
  @retry_count ||= 0
  @retry_count += 1
  if @retry_count < 5
    implicit_element.reload_ancestors
    retry
  else
    raise
  end
end

Instance Method Details

#absent?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


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

def absent?(options = {})
  wait_until_absent(options[:wait])
  true
rescue ElementNotAbsent
  false
end

#hidden?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


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

def hidden?(options = {})
  wait_until_hidden(options[:wait])
  true
rescue ElementNotHidden
  false
end

#is_a?(type) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/ae_page_objects/element_proxy.rb', line 88

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

#kind_of?(type) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/ae_page_objects/element_proxy.rb', line 92

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

#presenceObject



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

def presence
  implicit_element
rescue LoadingElementFailed
  nil
end

#present?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


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

def present?(options = {})
  wait_until_present(options[:wait])
  true
rescue ElementNotPresent
  false
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#visible?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


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

def visible?(options = {})
  wait_until_visible(options[:wait])
  true
rescue ElementNotVisible
  false
end

#wait_until_absent(timeout = nil) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/ae_page_objects/element_proxy.rb', line 79

def wait_until_absent(timeout = nil)
  with_reloaded_element(timeout) do
    @loaded_element.nil?
  end

rescue AePageObjects::WaitTimeoutError
  raise ElementNotAbsent, "element_class: #{@element_class}, options: #{@options.inspect}"
end

#wait_until_hidden(timeout = nil) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/ae_page_objects/element_proxy.rb', line 61

def wait_until_hidden(timeout = nil)
  with_reloaded_element(timeout) do
    @loaded_element.nil? || !@loaded_element.visible?
  end

rescue AePageObjects::WaitTimeoutError
  raise ElementNotHidden, "element_class: #{@element_class}, options: #{@options.inspect}"
end

#wait_until_present(timeout = nil) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/ae_page_objects/element_proxy.rb', line 70

def wait_until_present(timeout = nil)
  with_reloaded_element(timeout) do
    !@loaded_element.nil?
  end

rescue AePageObjects::WaitTimeoutError
  raise ElementNotPresent, "element_class: #{@element_class}, options: #{@options.inspect}"
end

#wait_until_visible(timeout = nil) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/ae_page_objects/element_proxy.rb', line 52

def wait_until_visible(timeout = nil)
  with_reloaded_element(timeout) do
    !@loaded_element.nil? && @loaded_element.visible?
  end

rescue AePageObjects::WaitTimeoutError
  raise ElementNotVisible, "element_class: #{@element_class}, options: #{@options.inspect}"
end