Class: TestCentricity::AppElements::AppSelectList

Inherits:
AppUIElement show all
Defined in:
lib/testcentricity_apps/app_elements/selectlist.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) ⇒ AppSelectList

Returns a new instance of AppSelectList.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/testcentricity_apps/app_elements/selectlist.rb', line 6

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

Instance Attribute Details

#list_itemObject

Returns the value of attribute list_item.



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

def list_item
  @list_item
end

Instance Method Details

#choose_item(item) ⇒ Object

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

Examples:

convert_list.choose_item(2)
convert_list.choose_item('Power')

Parameters:

  • item (String, Integer)

    text or index of item to select



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/testcentricity_apps/app_elements/selectlist.rb', line 87

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
    self.click if Environ.is_macos?
    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



21
22
23
24
25
26
27
28
29
30
# File 'lib/testcentricity_apps/app_elements/selectlist.rb', line 21

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 selectlist element"
    end
  end
end

#get_item_countInteger

Return the number of items in a list object.

Examples:

num_convert_items = convert_list.get_list_items

Returns:

  • (Integer)


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/testcentricity_apps/app_elements/selectlist.rb', line 38

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
  self.click if Environ.is_macos?
  items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
  self.click if Environ.is_macos?
  items.count
end

#get_list_item(index) ⇒ Object



74
75
76
77
# File 'lib/testcentricity_apps/app_elements/selectlist.rb', line 74

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 selectlist object.

Examples:

convert_items = convert_list.get_list_items

Returns:

  • (Array)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/testcentricity_apps/app_elements/selectlist.rb', line 57

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
  self.click if Environ.is_macos?
  items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
  items.each do |item|
    list_items.push(item.text)
  end
  self.click if Environ.is_macos?
  list_items
end