module SeleniumRecord::Axis

Helper methods for comparing the relative position in DOM among selenium objects

Public Instance Methods

after?(other_view) click to toggle source

@param view [SeleniumRecord::Base] @return [Boolean] Marks whether the current view is located in DOM

after the view passed as parameter
# File lib/selenium_record/axis.rb, line 8
def after?(other_view)
  preceding_sibling_elements.member? other_view.root_el
end
before?(other_view) click to toggle source

@param view [SeleniumRecord::Base] @return [Boolean] Marks whether the current view is located in DOM

before the view passed as parameter
# File lib/selenium_record/axis.rb, line 15
def before?(other_view)
  following_sibling_elements.member? other_view.root_el
end
following_sibling_elements() click to toggle source

Returns all elements belonging to following sibling xpath axe @return [Array<Selenium::WebDriver::Element>]

# File lib/selenium_record/axis.rb, line 38
def following_sibling_elements
  find_elements(following_sibling_locator)
end
ordered?(*models) click to toggle source

@param models [Array<PORO>] list of models associated to views @return [Boolean] Marks whether the model views are ordered in the dom

# File lib/selenium_record/axis.rb, line 21
def ordered?(*models)
  result = []
  models.reduce(nil) do |prev, current|
    result << (view_for(prev).before? view_for(current)) if prev
    current
  end
  result.any?
end
preceding_sibling_elements() click to toggle source

Returns all elements belonging to preceding sibling xpath axe @return [Array<Selenium::WebDriver::Element>]

# File lib/selenium_record/axis.rb, line 32
def preceding_sibling_elements
  find_elements(preceding_sibling_locator)
end

Private Instance Methods

following_sibling_locator() click to toggle source

@return [String] locator for finding following sibling dom elements

# File lib/selenium_record/axis.rb, line 50
def following_sibling_locator
  { xpath: "./following-sibling::#{tag_name}" }
end
preceding_sibling_locator() click to toggle source

@return [String] locator for finding preceding sibling dom elements

# File lib/selenium_record/axis.rb, line 45
def preceding_sibling_locator
  { xpath: "./preceding-sibling::#{tag_name}" }
end