Module: SeleniumRecord::Core

Included in:
Base
Defined in:
lib/selenium_record/core.rb

Overview

Core helpers to get easier access to selenium api

Constant Summary collapse

SUBCLASS_RESPONSABILITY =
'SubclassResponsibilityError'

Instance Method Summary collapse

Instance Method Details

#find(locator, opts = {}) ⇒ Selenium::WebDriver::Element

Parameters:

  • opts (Hash) (defaults to: {})

    the options to find element

  • opts (String) (defaults to: {})

    :global_scope Marks whether the global scope is used whenever a root element is not present

Returns:

  • (Selenium::WebDriver::Element)


25
26
27
28
29
30
31
32
33
# 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) ⇒ Object



35
36
37
# File 'lib/selenium_record/core.rb', line 35

def find!(locator)
  find(locator, global_scope: true)
end

#find_elements(locator) ⇒ Object



39
40
41
# File 'lib/selenium_record/core.rb', line 39

def find_elements(locator)
  cover { root_el.find_elements(locator) }
end

#first_last(list) ⇒ Object



43
44
45
46
# File 'lib/selenium_record/core.rb', line 43

def first_last(list)
  blk = ->(first, *_, last) { [first, last] }
  blk.call(*list)
end

#load_dom(attrs = {}) ⇒ Object



15
16
17
18
19
# File 'lib/selenium_record/core.rb', line 15

def load_dom(attrs = {})
  load_dom! attrs
rescue
  false
end

#load_dom!(attrs = {}) ⇒ Object



6
7
8
9
10
11
12
13
# 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