Class: TestCentricity::AppElements::AppList

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

Instance Attribute Summary collapse

Attributes inherited from AppUIElement

#context, #locator, #mru_app_session, #mru_locator, #mru_object, #mru_parent, #name, #parent, #type

Instance Method Summary collapse

Methods inherited from AppUIElement

#clear, #click, #count, #disabled?, #double_tap, #drag_and_drop, #drag_by, #element, #enabled?, #exists?, #get_attribute, #get_caption, #get_locator, #get_name, #get_object_type, #get_value, #height, #hidden?, #hover, #id, #identifier, #long_press, #reset_mru_cache, #scroll_into_view, #selected?, #send_keys, #set, #swipe_gesture, #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.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/testcentricity_apps/app_elements/list.rb', line 8

def initialize(name, parent, locator, context)
  super
  @type = :list
  @item_objects = nil
  @scrolling = :vertical
  @list_item = case Environ.device_os
               when :ios, :mac
                 { class: 'XCUIElementTypeOther' }
               when :android
                 { class: 'android.view.ViewGroup' }
               else
                 nil
               end
end

Instance Attribute Details

#item_objectsObject

Returns the value of attribute item_objects.



6
7
8
# File 'lib/testcentricity_apps/app_elements/list.rb', line 6

def item_objects
  @item_objects
end

#list_itemObject

Returns the value of attribute list_item.



4
5
6
# File 'lib/testcentricity_apps/app_elements/list.rb', line 4

def list_item
  @list_item
end

#scrollingObject

Returns the value of attribute scrolling.



5
6
7
# File 'lib/testcentricity_apps/app_elements/list.rb', line 5

def scrolling
  @scrolling
end

Instance Method Details

#choose_item(item) ⇒ Object

Select the specified item in a list object. Accepts a String or Integer.

Examples:

province_list.choose_item(2)
province_list.choose_item('Manitoba')

Parameters:

  • item (String, Integer)

    text or index of item to select



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/testcentricity_apps/app_elements/list.rb', line 118

def choose_item(item)
  obj = element
  object_not_found_exception(obj)
  if Environ.is_ios? && obj.attribute(:type) == 'XCUIElementTypePickerWheel'
    obj.send_keys(item)
  else
    list_loc = get_list_item_locator
    items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
    if item.is_a?(Integer)
      items[item - 1].click
    else
      items.each do |list_item|
        if list_item.text == item
          list_item.click
          break
        end
      end
    end
  end
end

#define_list_elements(element_spec) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/testcentricity_apps/app_elements/list.rb', line 23

def define_list_elements(element_spec)
  element_spec.each do |element, value|
    case element
    when :list_item
      @list_item = value
    when :scrolling
      @scrolling = value
    else
      raise "#{element} is not a recognized list element"
    end
  end
end

#get_item_countInteger

Return the number of items in a list object.

Examples:

num_nav_items = nav_list.get_item_count

Returns:

  • (Integer)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/testcentricity_apps/app_elements/list.rb', line 54

def get_item_count
  obj = element
  object_not_found_exception(obj)
  if Environ.is_ios? && obj.attribute(:type) == 'XCUIElementTypePickerWheel'
    raise 'This method is not supported for XCUIElementTypePickerWheel controls'
  end
  list_loc = get_list_item_locator
  items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
  if items.size > 0 && Environ.is_android?
    start_count = items.count
    direction = @scrolling == :horizontal ? :right : :down
    scroll_count = 0
    loop do
      save_count = items.count
      swipe_gesture(direction)
      scroll_count += 1
      obj.find_elements(list_loc.keys[0], list_loc.values[0]).each do |item|
        items.push(item) unless items.include?(item)
      end
      break if items.count == save_count
    end
    direction = @scrolling == :horizontal ? :left : :up
    scroll_count.times do
      swipe_gesture(direction)
    end
  end
  @item_objects = items if Environ.is_android? && start_count < items.count
  items.count
end

#get_list_item(index) ⇒ Object



105
106
107
108
# File 'lib/testcentricity_apps/app_elements/list.rb', line 105

def get_list_item(index)
  items = get_list_items
  items[index - 1]
end

#get_list_itemsArray

Return array of strings of all items in a list object.

Examples:

nav_items = nav_list.get_options

Returns:

  • (Array)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/testcentricity_apps/app_elements/list.rb', line 90

def get_list_items
  list_items = []
  obj = element
  object_not_found_exception(obj)
  if Environ.is_ios? && obj.attribute(:type) == 'XCUIElementTypePickerWheel'
    raise 'This method is not supported for XCUIElementTypePickerWheel controls'
  end
  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

#item_refsObject



42
43
44
45
46
# File 'lib/testcentricity_apps/app_elements/list.rb', line 42

def item_refs
  obj = element
  object_not_found_exception(obj)
  @item_objects
end

#scroll_modeObject



36
37
38
39
40
# File 'lib/testcentricity_apps/app_elements/list.rb', line 36

def scroll_mode
  obj = element
  object_not_found_exception(obj)
  @scrolling
end

#wait_until_item_count_changes(seconds = nil) ⇒ Object

Wait until the list's item_count changes, 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_changes(10)

Parameters:

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

    wait time in seconds



164
165
166
167
168
169
170
171
# File 'lib/testcentricity_apps/app_elements/list.rb', line 164

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



149
150
151
152
153
154
155
# File 'lib/testcentricity_apps/app_elements/list.rb', line 149

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