Class: TestCentricity::AppElements::AppMenu
- Inherits:
-
AppUIElement
- Object
- AppUIElement
- TestCentricity::AppElements::AppMenu
- Defined in:
- lib/testcentricity_apps/app_elements/menu.rb
Instance Attribute Summary collapse
-
#key_map ⇒ Object
Returns the value of attribute key_map.
-
#menu_item ⇒ Object
Returns the value of attribute menu_item.
Attributes inherited from AppUIElement
#context, #locator, #mru_app_session, #mru_locator, #mru_object, #mru_parent, #name, #parent, #type
Instance Method Summary collapse
-
#choose_menu_item(item, method = :mouse) ⇒ Object
Select the specified menu item in a menu object using the specified selection method (mouse or keyboard shortcut).
- #define_menu_elements(element_spec) ⇒ Object
-
#get_item_count ⇒ Integer
Return the number of menu items in a menu object.
- #get_item_data(index = nil) ⇒ Object
-
#get_item_enabled(index) ⇒ Boolean
Return enabled state of menu item at specified index.
-
#get_menu_item(index) ⇒ String
(also: #get_list_item)
Return text caption of menu item at specified index.
-
#get_menu_items ⇒ Array
(also: #get_list_items)
Return array of strings of all menu item captions in a menu object.
-
#initialize(name, parent, locator, context) ⇒ AppMenu
constructor
A new instance of AppMenu.
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) ⇒ AppMenu
Returns a new instance of AppMenu.
7 8 9 10 11 12 |
# File 'lib/testcentricity_apps/app_elements/menu.rb', line 7 def initialize(name, parent, locator, context) super @type = :menu @menu_item = { class: 'XCUIElementTypeMenuItem' } @key_map = nil end |
Instance Attribute Details
#key_map ⇒ Object
Returns the value of attribute key_map.
5 6 7 |
# File 'lib/testcentricity_apps/app_elements/menu.rb', line 5 def key_map @key_map end |
#menu_item ⇒ Object
Returns the value of attribute menu_item.
4 5 6 |
# File 'lib/testcentricity_apps/app_elements/menu.rb', line 4 def @menu_item end |
Instance Method Details
#choose_menu_item(item, method = :mouse) ⇒ Object
Select the specified menu item in a menu object using the specified selection method (mouse or keyboard shortcut). Accepts a String or Integer representing either the menu item caption or item index.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/testcentricity_apps/app_elements/menu.rb', line 121 def (item, method = :mouse) obj = element object_not_found_exception(obj) case method when :mouse self.click unless self.visible? = items = obj.find_elements(.keys[0], .values[0]) case when item == :last items.last.click when 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 when :keys, :keyboard keys = @key_map[item] raise "No key map found for item #{item}" if keys.empty? Environ.appium_driver.execute_script('macos: keys', { keys: keys }) else raise "#{method} is not a valid selector" end end |
#define_menu_elements(element_spec) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/testcentricity_apps/app_elements/menu.rb', line 14 def (element_spec) element_spec.each do |element, value| case element when :menu_item @menu_item = value when :key_map @key_map = value else raise "#{element} is not a recognized menu element" end end end |
#get_item_count ⇒ Integer
Return the number of menu items in a menu object.
33 34 35 36 37 38 39 |
# File 'lib/testcentricity_apps/app_elements/menu.rb', line 33 def get_item_count obj = element object_not_found_exception(obj) = items = obj.find_elements(.keys[0], .values[0]) items.count end |
#get_item_data(index = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/testcentricity_apps/app_elements/menu.rb', line 74 def get_item_data(index = nil) = [] obj = element object_not_found_exception(obj) = items = obj.find_elements(.keys[0], .values[0]) items.each do |item| = item.text state = item.enabled? .push( { caption: , enabled: state } ) end if index.nil? else [index - 1] end end |
#get_item_enabled(index) ⇒ Boolean
Return enabled state of menu item at specified index.
103 104 105 106 107 108 109 |
# File 'lib/testcentricity_apps/app_elements/menu.rb', line 103 def get_item_enabled(index) obj = element object_not_found_exception(obj) = items = obj.find_elements(.keys[0], .values[0]) items[index - 1].enabled? end |
#get_menu_item(index) ⇒ String Also known as: get_list_item
Return text caption of menu item at specified index.
67 68 69 70 |
# File 'lib/testcentricity_apps/app_elements/menu.rb', line 67 def (index) items = items[index - 1] end |
#get_menu_items ⇒ Array Also known as: get_list_items
Return array of strings of all menu item captions in a menu object.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/testcentricity_apps/app_elements/menu.rb', line 47 def = [] obj = element object_not_found_exception(obj) = items = obj.find_elements(.keys[0], .values[0]) items.each do |item| .push(item.text) end end |