module Testimonium::Find

Find functions

Public Instance Methods

find_all_elements_by_id(id, timeout = 2, retries = 5) click to toggle source

Find all elements with id.

Android needs app package name set as constant ANDROID_PACKAGE.

@param id [String] Element ID. @param timeout [Integer] Timeout seconds between retries. @param retries [Integer] Amount of retries. @return [list] if elements are found.

# File lib/testimonium/find_functions.rb, line 79
def find_all_elements_by_id(id, timeout = 2, retries = 5)
  list = nil
  count = 0

  retries.times do
    sleep timeout
    count += 1

    begin
      list = ids(id) if device_android
      list = find_elements(:id, id) if device_ios
    rescue Selenium::WebDriver::Error::NoSuchElementError
    end

    logger("Found all elements with id '#{id}' on attempt #{count}") if list
    return list if list
  end

  logger("Failed to find elements with id '#{id}'. Number of attempts: #{count}")
  nil
end
find_element_by_id(id, timeout = 2, retries = 5) click to toggle source

Find element by element id.

@param id [String] Element ID. @param timeout [Integer] Timeout seconds between retries. @param retries [Integer] Amount of retries. @return [element] if element is found.

# File lib/testimonium/find_functions.rb, line 39
def find_element_by_id(id, timeout = 2, retries = 5)
  find_element_id(id, timeout, retries)
end
find_element_by_resourceid(id, timeout = 2, retries = 5) click to toggle source

Find element by resourceid.

Android only - Needs app package name set as constant ANDROID_PACKAGE.

@param id [String] Element ID. @param timeout [Integer] Timeout seconds between retries. @param retries [Integer] Amount of retries. @return [element] if element is found.

# File lib/testimonium/find_functions.rb, line 62
def find_element_by_resourceid(id, timeout = 2, retries = 5)
  if defined?(ANDROID_PACKAGE).nil?
    logger('ANDROID_PACKAGE is missing.', 'fatal')
    raise Selenium::WebDriver::Error::NoSuchElementError
  end

  find_element_by_xpath("//*[@resource-id='#{ANDROID_PACKAGE}:id/#{id}']", timeout, retries)
end
find_element_by_text(text, timeout = 2, retries = 5) click to toggle source

Find element by text.

@param text [String] Element Text. @param timeout [Integer] Timeout seconds between retries. @param retries [Integer] Amount of retries. @return [element] if element is found.

# File lib/testimonium/find_functions.rb, line 49
def find_element_by_text(text, timeout = 2, retries = 5)
  return find_element_by_xpath("//*[@text='#{text}']", timeout, retries) if device_android
  return find_text_ios(text, timeout, retries) if device_ios
end
find_element_by_xpath(path, timeout = 3, retries = 5) click to toggle source

Find element by xpath.

@param xpath [String] Element Xpath. @param timeout [Integer] Timeout seconds between retries. @param retries [Integer] Amount of retries. @return [element] if element is found.

# File lib/testimonium/find_functions.rb, line 12
def find_element_by_xpath(path, timeout = 3, retries = 5)
  element = nil
  count = 0

  retries.times do
    sleep timeout
    count += 1

    begin
      element = find_element(:xpath, path)
    rescue Selenium::WebDriver::Error::NoSuchElementError
    end

    logger("Found '#{path}' on attempt #{count}") if element
    return element if element
  end

  logger("Failed to find '#{path}'. Number of attempts: #{count}")
  nil
end