class AePageObjects::ElementProxy
Public Class Methods
new(element_class, *args)
click to toggle source
# 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
Public Instance Methods
absent?()
click to toggle source
# File lib/ae_page_objects/element_proxy.rb, line 32 def absent? !present? end
is_a?(type)
click to toggle source
# File lib/ae_page_objects/element_proxy.rb, line 78 def is_a?(type) type == @element_class || type == ElementProxy end
kind_of?(type)
click to toggle source
# File lib/ae_page_objects/element_proxy.rb, line 82 def kind_of?(type) is_a?(type) end
method_missing(name, *args, **kwargs, &block)
click to toggle source
# 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
presence()
click to toggle source
# File lib/ae_page_objects/element_proxy.rb, line 36 def presence implicit_element rescue LoadingElementFailed nil end
present?()
click to toggle source
# File lib/ae_page_objects/element_proxy.rb, line 27 def present? reload_element !@loaded_element.nil? end
respond_to?(*args)
click to toggle source
Calls superclass method
# File lib/ae_page_objects/element_proxy.rb, line 110 def respond_to?(*args) super || @element_class.allocate.respond_to?(*args) end
visible?()
click to toggle source
# File lib/ae_page_objects/element_proxy.rb, line 18 def visible? reload_element @loaded_element&.visible? end
wait_until_absent(timeout = nil)
click to toggle source
# 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_present(timeout = nil)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
implicit_element()
click to toggle source
# File lib/ae_page_objects/element_proxy.rb, line 131 def implicit_element @loaded_element ||= load_element end
load_element(wait: true)
click to toggle source
# File lib/ae_page_objects/element_proxy.rb, line 116 def load_element(wait: true) args = @args.dup options_or_locator = args.pop options = if options_or_locator.is_a?(Hash) options_or_locator.merge(wait: wait) else { locator: options_or_locator, wait: wait } end args << options @element_class.new(*args) end
reload_element()
click to toggle source
# File lib/ae_page_objects/element_proxy.rb, line 135 def reload_element @loaded_element = load_element(wait: false) rescue LoadingElementFailed @loaded_element = nil end
with_reloaded_element(timeout) { || ... }
click to toggle source
# File lib/ae_page_objects/element_proxy.rb, line 141 def with_reloaded_element(timeout) AePageObjects.wait_until(timeout) do reload_element yield end end