module SeleniumRecord::Lookup
Responsible methods for looking up the root element for each selenium object
Public Class Methods
# File lib/selenium_record/lookup.rb, line 4 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
Searchs for root element of current object based on other element @return [Webdriver::Element]
# 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
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
# File lib/selenium_record/lookup.rb, line 42 def lookup_sequence fail 'LookupUndefinedSequenceError' end
Given the current root element for the view, applies a scoped search for the web element identified by the locator passed as parameter
@raise [LookupMultipleElementsError] if it is found multiple web elements
in the scope of the current root element for the locator passed
@raise [LookupUndefinedElementError] if it isn’t found any web elements
in the scope of the current root element for the locator passed
@param locator [Hash] contains unique {key: value} where the key is the
locator_type (:class, :class_name, :css, :id, :link_text, :link, :partial_link_text, :name, :tag_name, :xpath)
@return element [Selenium::WebDriver::Element]
# 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