module SeleniumRecord::Core

Core helpers to get easier access to selenium api

Constants

SUBCLASS_RESPONSABILITY

Public Instance Methods

find(locator, opts = {}) click to toggle source

@param [Hash] opts the options to find element @param opts [String] :global_scope Marks whether the global scope is used

whenever a root element is not present

@return [Selenium::WebDriver::Element]

# File lib/selenium_record/core.rb, line 25
def find(locator, opts = {})
  cover do
    finder = root_el
    finder = browser if opts[:global_scope] && !finder
    element = finder.find_element(locator)
    element.extend(Axiable)
    element
  end
end
find!(locator) click to toggle source
# File lib/selenium_record/core.rb, line 35
def find!(locator)
  find(locator, global_scope: true)
end
find_elements(locator) click to toggle source
# File lib/selenium_record/core.rb, line 39
def find_elements(locator)
  cover { root_el.find_elements(locator) }
end
first_last(list) click to toggle source
# File lib/selenium_record/core.rb, line 43
def first_last(list)
  blk = ->(first, *_, last) { [first, last] }
  blk.call(*list)
end
load_dom(attrs = {}) click to toggle source
# File lib/selenium_record/core.rb, line 15
def load_dom(attrs = {})
  load_dom! attrs
rescue
  false
end
load_dom!(attrs = {}) click to toggle source
# File lib/selenium_record/core.rb, line 6
def load_dom!(attrs = {})
  @load_attributes = attrs
  before_load_dom if respond_to? :before_load_dom
  before_lookup if respond_to? :before_lookup
  lookup
  after_load_dom if respond_to? :after_load_dom
  self
end

Protected Instance Methods

cover(&block) click to toggle source

Runs block code free of: ‘Selenium::WebDriver::Error::StaleElementReferenceError` Case the exception is raised it is reloaded the dom of the object

@param block [Block] The block of code to be executed

# File lib/selenium_record/core.rb, line 55
def cover(&block)
  block.call
rescue Selenium::WebDriver::Error::StaleElementReferenceError
  load_dom
  retry
end