Class: TestCentricity::AppList

Inherits:
AppUIElement show all
Defined in:
lib/testcentricity/app_elements/list.rb

Instance Attribute Summary collapse

Attributes inherited from AppUIElement

#context, #locator, #name, #parent, #type

Instance Method Summary collapse

Methods inherited from AppUIElement

#clear, #click, #disabled?, #double_tap, #enabled?, #exists?, #get_attribute, #get_caption, #get_locator, #get_name, #get_object_type, #get_value, #height, #hidden?, #scroll, #selected?, #send_keys, #set, #swipe, #tag_name, #tap, #visible?, #wait_until_enabled, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #width, #x_loc, #y_loc

Constructor Details

#initialize(name, parent, locator, context) ⇒ AppList

Returns a new instance of AppList.



5
6
7
8
9
# File 'lib/testcentricity/app_elements/list.rb', line 5

def initialize(name, parent, locator, context)
  super
  @type      = :list
  @list_item = nil
end

Instance Attribute Details

#list_itemObject

Returns the value of attribute list_item.



3
4
5
# File 'lib/testcentricity/app_elements/list.rb', line 3

def list_item
  @list_item
end

Instance Method Details

#click_list_item(index) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/testcentricity/app_elements/list.rb', line 42

def click_list_item(index)
  obj = element
  object_not_found_exception(obj)
  list_loc = get_list_item_locator
  items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
  list_item = items[index]
  list_item.click
end

#define_list_elements(element_spec) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/testcentricity/app_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_item_countObject



22
23
24
25
26
27
28
# File 'lib/testcentricity/app_elements/list.rb', line 22

def get_item_count
  obj = element
  object_not_found_exception(obj)
  list_loc = get_list_item_locator
  items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
  items.size
end

#get_list_item(index) ⇒ Object



51
52
53
# File 'lib/testcentricity/app_elements/list.rb', line 51

def get_list_item(index)

end

#get_list_itemsObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/testcentricity/app_elements/list.rb', line 30

def get_list_items
  list_items = []
  obj = element
  object_not_found_exception(obj)
  list_loc = get_list_item_locator
  items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
  items.each do |item|
    list_items.push(item.text)
  end
  list_items
end

#wait_until_item_count_changes(seconds = nil) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/testcentricity/app_elements/list.rb', line 73

def wait_until_item_count_changes(seconds = nil)
  value = get_item_count
  timeout = seconds.nil? ? Environ.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) ⇒ Object

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 Environ.default_max_wait_time.

Examples:

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)

Parameters:

  • value (Integer or Hash)

    value expected or comparison hash

  • seconds (Integer or Float) (defaults to: nil)

    wait time in seconds



65
66
67
68
69
70
71
# File 'lib/testcentricity/app_elements/list.rb', line 65

def wait_until_item_count_is(value, seconds = nil)
  timeout = seconds.nil? ? Environ.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