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, **kwargs, &block) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ae_page_objects/element_proxy.rb', line 86

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

  implicit_element.__send__(name, *args, **kwargs, &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?Boolean

Returns:

  • (Boolean)


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

def absent?
  !present?
end

#hidden?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ae_page_objects/element_proxy.rb', line 23

def hidden?
  !visible?
end

#is_a?(type) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/ae_page_objects/element_proxy.rb', line 78

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

#kind_of?(type) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/ae_page_objects/element_proxy.rb', line 82

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

#presenceObject



36
37
38
39
40
# File 'lib/ae_page_objects/element_proxy.rb', line 36

def presence
  implicit_element
rescue LoadingElementFailed
  nil
end

#present?Boolean

Returns:

  • (Boolean)


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

def present?
  reload_element
  !@loaded_element.nil?
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#visible?Boolean

Returns:

  • (Boolean)


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

def visible?
  reload_element
  @loaded_element&.visible?
end

#wait_until_absent(timeout = nil) ⇒ Object



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

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



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

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



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

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



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

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