class TestCentricity::List

Attributes

list_item[RW]

Public Class Methods

new(name, parent, locator, context) click to toggle source
Calls superclass method
# File lib/testcentricity/web_elements/list.rb, line 5
def initialize(name, parent, locator, context)
  super
  @type = :list
  define_list_elements({ :list_item => 'li' })
end

Public Instance Methods

define_list_elements(element_spec) click to toggle source
# File lib/testcentricity/web_elements/list.rb, line 11
def define_list_elements(element_spec)
  element_spec.each do |element, value|
    case element
    when :list_item
      @list_item = value
    else
      raise "#{element} is not a recognized list element"
    end
  end
end
get_all_items_count() click to toggle source
# File lib/testcentricity/web_elements/list.rb, line 51
def get_all_items_count
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.all(@list_item, :visible => :all).count
end
get_all_list_items(element_spec = nil) click to toggle source
# File lib/testcentricity/web_elements/list.rb, line 44
def get_all_list_items(element_spec = nil)
  define_list_elements(element_spec) unless element_spec.nil?
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.all(@list_item, :visible => :all).collect(&:text)
end
get_item_count() click to toggle source
# File lib/testcentricity/web_elements/list.rb, line 38
def get_item_count
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.all(@list_item).count
end
get_list_item(index, visible = true) click to toggle source
# File lib/testcentricity/web_elements/list.rb, line 29
def get_list_item(index, visible = true)
  if visible
    items = get_list_items
  else
    items = get_all_list_items
  end
  items[index - 1]
end
get_list_items(element_spec = nil) click to toggle source
# File lib/testcentricity/web_elements/list.rb, line 22
def get_list_items(element_spec = nil)
  define_list_elements(element_spec) unless element_spec.nil?
  obj, = find_element
  object_not_found_exception(obj, nil)
  obj.all(@list_item).collect(&:text)
end
get_list_row_locator(row) click to toggle source
# File lib/testcentricity/web_elements/list.rb, line 64
def get_list_row_locator(row)
  case @locator_type
  when :xpath
    "#{@locator}/#{@list_item}[#{row}]"
  when :css
    "#{@locator} > #{@list_item}:nth-of-type(#{row})"
  end
end
verify_list_items(expected, enqueue = false) click to toggle source
# File lib/testcentricity/web_elements/list.rb, line 57
def verify_list_items(expected, enqueue = false)
  actual = get_list_items
  enqueue ?
      ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list #{object_ref_message}") :
      assert_equal(expected, actual, "Expected list #{object_ref_message} to be #{expected} but found #{actual}")
end
wait_until_item_count_changes(seconds = nil) click to toggle source
# File lib/testcentricity/web_elements/list.rb, line 91
def wait_until_item_count_changes(seconds = nil)
  value = get_item_count
  timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { get_item_count != value }
rescue
  raise "Value of List #{object_ref_message} failed to change from '#{value}' after #{timeout} seconds" if get_item_count == value
end
wait_until_item_count_is(value, seconds = nil) click to toggle source

Wait until the list's item_count equals the specified value, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.

@param value [Integer or Hash] value expected or comparison hash @param seconds [Integer or Float] wait time in seconds @example

search_results_list.wait_until_item_count_is(10, 15)
  or
search_results_list.wait_until_item_count_is({ :greater_than_or_equal => 1 }, 5)
# File lib/testcentricity/web_elements/list.rb, line 83
def wait_until_item_count_is(value, seconds = nil)
  timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { compare(value, get_item_count) }
rescue
  raise "Value of List #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_item_count == value
end