Module: SeleniumRecord::Lookup

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

Overview

Responsible methods for looking up the root element for each selenium object

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/selenium_record/lookup.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#lookupWebdriver::Element

Searchs for root element of current object based on other element

Returns:

  • (Webdriver::Element)


10
11
12
13
14
15
16
# File 'lib/selenium_record/lookup.rb', line 10

def lookup
  @root_el = parent_el || browser
  lookup_sequence.each { |locator| @root_el = lookup_step(locator) }
rescue
  @root_el = nil
  raise
end

#lookup_sequenceObject

Clasess extending SeleniumRecord::Base should overwrite this method or call to class method ‘lookup_strategy` defined in `SeleniumRecord::Lookup` in order to search for Selenium::WebDriver::Element used as scope for finding elements inside the instance object



42
43
44
# File 'lib/selenium_record/lookup.rb', line 42

def lookup_sequence
  fail 'LookupUndefinedSequenceError'
end

#lookup_step(locator) ⇒ Object

Given the current root element for the view, applies a scoped search for the web element identified by the locator passed as parameter

Parameters:

  • locator (Hash)

    contains unique value where the key is the locator_type (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)

Raises:

  • (LookupMultipleElementsError)

    if it is found multiple web elements in the scope of the current root element for the locator passed

  • (LookupUndefinedElementError)

    if it isn’t found any web elements in the scope of the current root element for the locator passed



30
31
32
33
34
35
36
# File 'lib/selenium_record/lookup.rb', line 30

def lookup_step(locator)
  lookup_elements = find_elements(locator)
  size = lookup_elements.size
  fail 'LookupMultipleElementsError' if size > 1
  fail 'LookupUndefinedElementError' if size == 0
  lookup_elements.first
end