testcentricity_apps 4.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +193 -0
- data/LICENSE.md +27 -0
- data/README.md +2297 -0
- data/lib/testcentricity_apps/app_core/appium_connect_helper.rb +667 -0
- data/lib/testcentricity_apps/app_core/screen_object.rb +494 -0
- data/lib/testcentricity_apps/app_core/screen_objects_helper.rb +211 -0
- data/lib/testcentricity_apps/app_core/screen_section.rb +669 -0
- data/lib/testcentricity_apps/app_elements/alert.rb +152 -0
- data/lib/testcentricity_apps/app_elements/app_element.rb +728 -0
- data/lib/testcentricity_apps/app_elements/button.rb +10 -0
- data/lib/testcentricity_apps/app_elements/checkbox.rb +61 -0
- data/lib/testcentricity_apps/app_elements/image.rb +10 -0
- data/lib/testcentricity_apps/app_elements/label.rb +10 -0
- data/lib/testcentricity_apps/app_elements/list.rb +188 -0
- data/lib/testcentricity_apps/app_elements/menu.rb +159 -0
- data/lib/testcentricity_apps/app_elements/menubar.rb +78 -0
- data/lib/testcentricity_apps/app_elements/radio.rb +61 -0
- data/lib/testcentricity_apps/app_elements/selectlist.rb +126 -0
- data/lib/testcentricity_apps/app_elements/switch.rb +66 -0
- data/lib/testcentricity_apps/app_elements/textfield.rb +51 -0
- data/lib/testcentricity_apps/appium_server.rb +76 -0
- data/lib/testcentricity_apps/data_objects/data_objects_helper.rb +100 -0
- data/lib/testcentricity_apps/data_objects/environment.rb +423 -0
- data/lib/testcentricity_apps/exception_queue_helper.rb +160 -0
- data/lib/testcentricity_apps/utility_helpers.rb +48 -0
- data/lib/testcentricity_apps/version.rb +3 -0
- data/lib/testcentricity_apps/world_extensions.rb +61 -0
- data/lib/testcentricity_apps.rb +103 -0
- metadata +322 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
module TestCentricity
|
2
|
+
module AppElements
|
3
|
+
class AppCheckBox < AppUIElement
|
4
|
+
def initialize(name, parent, locator, context)
|
5
|
+
super
|
6
|
+
@type = :checkbox
|
7
|
+
end
|
8
|
+
|
9
|
+
# Is checkbox checked?
|
10
|
+
#
|
11
|
+
# @return [Boolean]
|
12
|
+
# @example
|
13
|
+
# remember_me_checkbox.checked?
|
14
|
+
#
|
15
|
+
def checked?
|
16
|
+
obj = element
|
17
|
+
object_not_found_exception(obj)
|
18
|
+
if Environ.is_macos?
|
19
|
+
state = obj.value
|
20
|
+
state.to_bool
|
21
|
+
else
|
22
|
+
obj.selected?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set the check state of a checkbox object.
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# remember_me_checkbox.check
|
30
|
+
#
|
31
|
+
def check
|
32
|
+
set_checkbox_state(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Uncheck a checkbox object.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# remember_me_checkbox.uncheck
|
39
|
+
#
|
40
|
+
def uncheck
|
41
|
+
set_checkbox_state(false)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Set the check state of a checkbox object.
|
45
|
+
#
|
46
|
+
# @param state [Boolean] true = checked / false = unchecked
|
47
|
+
# @example
|
48
|
+
# remember_me_checkbox.set_checkbox_state(true)
|
49
|
+
#
|
50
|
+
def set_checkbox_state(state)
|
51
|
+
obj = element
|
52
|
+
object_not_found_exception(obj)
|
53
|
+
if state
|
54
|
+
obj.click unless obj.selected?
|
55
|
+
else
|
56
|
+
obj.click if obj.selected?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
module TestCentricity
|
2
|
+
module AppElements
|
3
|
+
class AppList < AppUIElement
|
4
|
+
attr_accessor :list_item
|
5
|
+
attr_accessor :scrolling
|
6
|
+
attr_accessor :item_objects
|
7
|
+
|
8
|
+
def initialize(name, parent, locator, context)
|
9
|
+
super
|
10
|
+
@type = :list
|
11
|
+
@item_objects = nil
|
12
|
+
@scrolling = :vertical
|
13
|
+
@list_item = case Environ.device_os
|
14
|
+
when :ios, :mac
|
15
|
+
{ class: 'XCUIElementTypeOther' }
|
16
|
+
when :android
|
17
|
+
{ class: 'android.view.ViewGroup' }
|
18
|
+
else
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def define_list_elements(element_spec)
|
24
|
+
element_spec.each do |element, value|
|
25
|
+
case element
|
26
|
+
when :list_item
|
27
|
+
@list_item = value
|
28
|
+
when :scrolling
|
29
|
+
@scrolling = value
|
30
|
+
else
|
31
|
+
raise "#{element} is not a recognized list element"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def scroll_mode
|
37
|
+
obj = element
|
38
|
+
object_not_found_exception(obj)
|
39
|
+
@scrolling
|
40
|
+
end
|
41
|
+
|
42
|
+
def item_refs
|
43
|
+
obj = element
|
44
|
+
object_not_found_exception(obj)
|
45
|
+
@item_objects
|
46
|
+
end
|
47
|
+
|
48
|
+
# Return the number of items in a list object.
|
49
|
+
#
|
50
|
+
# @return [Integer]
|
51
|
+
# @example
|
52
|
+
# num_nav_items = nav_list.get_item_count
|
53
|
+
#
|
54
|
+
def get_item_count
|
55
|
+
obj = element
|
56
|
+
object_not_found_exception(obj)
|
57
|
+
if Environ.is_ios? && obj.attribute(:type) == 'XCUIElementTypePickerWheel'
|
58
|
+
raise 'This method is not supported for XCUIElementTypePickerWheel controls'
|
59
|
+
end
|
60
|
+
list_loc = get_list_item_locator
|
61
|
+
items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
|
62
|
+
if items.size > 0 && Environ.is_android?
|
63
|
+
start_count = items.count
|
64
|
+
direction = @scrolling == :horizontal ? :right : :down
|
65
|
+
scroll_count = 0
|
66
|
+
loop do
|
67
|
+
save_count = items.count
|
68
|
+
swipe_gesture(direction)
|
69
|
+
scroll_count += 1
|
70
|
+
obj.find_elements(list_loc.keys[0], list_loc.values[0]).each do |item|
|
71
|
+
items.push(item) unless items.include?(item)
|
72
|
+
end
|
73
|
+
break if items.count == save_count
|
74
|
+
end
|
75
|
+
direction = @scrolling == :horizontal ? :left : :up
|
76
|
+
scroll_count.times do
|
77
|
+
swipe_gesture(direction)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
@item_objects = items if Environ.is_android? && start_count < items.count
|
81
|
+
items.count
|
82
|
+
end
|
83
|
+
|
84
|
+
# Return array of strings of all items in a list object.
|
85
|
+
#
|
86
|
+
# @return [Array]
|
87
|
+
# @example
|
88
|
+
# nav_items = nav_list.get_options
|
89
|
+
#
|
90
|
+
def get_list_items
|
91
|
+
list_items = []
|
92
|
+
obj = element
|
93
|
+
object_not_found_exception(obj)
|
94
|
+
if Environ.is_ios? && obj.attribute(:type) == 'XCUIElementTypePickerWheel'
|
95
|
+
raise 'This method is not supported for XCUIElementTypePickerWheel controls'
|
96
|
+
end
|
97
|
+
list_loc = get_list_item_locator
|
98
|
+
items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
|
99
|
+
items.each do |item|
|
100
|
+
list_items.push(item.text)
|
101
|
+
end
|
102
|
+
list_items
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_list_item(index)
|
106
|
+
items = get_list_items
|
107
|
+
items[index - 1]
|
108
|
+
end
|
109
|
+
|
110
|
+
# Select the specified item in a list object. Accepts a String or Integer.
|
111
|
+
#
|
112
|
+
# @param item [String, Integer] text or index of item to select
|
113
|
+
#
|
114
|
+
# @example
|
115
|
+
# province_list.choose_item(2)
|
116
|
+
# province_list.choose_item('Manitoba')
|
117
|
+
#
|
118
|
+
def choose_item(item)
|
119
|
+
obj = element
|
120
|
+
object_not_found_exception(obj)
|
121
|
+
if Environ.is_ios? && obj.attribute(:type) == 'XCUIElementTypePickerWheel'
|
122
|
+
obj.send_keys(item)
|
123
|
+
else
|
124
|
+
list_loc = get_list_item_locator
|
125
|
+
items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
|
126
|
+
if item.is_a?(Integer)
|
127
|
+
items[item - 1].click
|
128
|
+
else
|
129
|
+
items.each do |list_item|
|
130
|
+
if list_item.text == item
|
131
|
+
list_item.click
|
132
|
+
break
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# Wait until the list's item_count equals the specified value, or until the specified wait time has expired. If the
|
140
|
+
# wait time is nil, then the wait time will be Environ.default_max_wait_time.
|
141
|
+
#
|
142
|
+
# @param value [Integer or Hash] value expected or comparison hash
|
143
|
+
# @param seconds [Integer or Float] wait time in seconds
|
144
|
+
# @example
|
145
|
+
# search_results_list.wait_until_item_count_is(10, 15)
|
146
|
+
# or
|
147
|
+
# search_results_list.wait_until_item_count_is({ :greater_than_or_equal => 1 }, 5)
|
148
|
+
#
|
149
|
+
def wait_until_item_count_is(value, seconds = nil)
|
150
|
+
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
|
151
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
152
|
+
wait.until { compare(value, get_item_count) }
|
153
|
+
rescue
|
154
|
+
raise "Value of List #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_item_count == value
|
155
|
+
end
|
156
|
+
|
157
|
+
# Wait until the list's item_count changes, or until the specified wait time has expired. If the wait time is nil,
|
158
|
+
# then the wait time will be Environ.default_max_wait_time.
|
159
|
+
#
|
160
|
+
# @param seconds [Integer or Float] wait time in seconds
|
161
|
+
# @example
|
162
|
+
# search_results_list.wait_until_item_count_changes(10)
|
163
|
+
#
|
164
|
+
def wait_until_item_count_changes(seconds = nil)
|
165
|
+
value = get_item_count
|
166
|
+
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
|
167
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
168
|
+
wait.until { get_item_count != value }
|
169
|
+
rescue
|
170
|
+
raise "Value of List #{object_ref_message} failed to change from '#{value}' after #{timeout} seconds" if get_item_count == value
|
171
|
+
end
|
172
|
+
|
173
|
+
private
|
174
|
+
|
175
|
+
def get_list_item_locator
|
176
|
+
if @list_item.nil?
|
177
|
+
case Environ.device_os
|
178
|
+
when :ios, :mac
|
179
|
+
define_list_elements({ :list_item => { class: 'XCUIElementTypeOther' } } )
|
180
|
+
when :android
|
181
|
+
define_list_elements({ :list_item => { class: 'android.view.ViewGroup' } } )
|
182
|
+
end
|
183
|
+
end
|
184
|
+
@list_item
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
module TestCentricity
|
2
|
+
module AppElements
|
3
|
+
class AppMenu < AppUIElement
|
4
|
+
attr_accessor :menu_item
|
5
|
+
attr_accessor :key_map
|
6
|
+
|
7
|
+
def initialize(name, parent, locator, context)
|
8
|
+
super
|
9
|
+
@type = :menu
|
10
|
+
@menu_item = { class: 'XCUIElementTypeMenuItem' }
|
11
|
+
@key_map = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def define_menu_elements(element_spec)
|
15
|
+
element_spec.each do |element, value|
|
16
|
+
case element
|
17
|
+
when :menu_item
|
18
|
+
@menu_item = value
|
19
|
+
when :key_map
|
20
|
+
@key_map = value
|
21
|
+
else
|
22
|
+
raise "#{element} is not a recognized menu element"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Return the number of menu items in a menu object.
|
28
|
+
#
|
29
|
+
# @return [Integer]
|
30
|
+
# @example
|
31
|
+
# num_menu_items = view_menu.get_item_count
|
32
|
+
#
|
33
|
+
def get_item_count
|
34
|
+
obj = element
|
35
|
+
object_not_found_exception(obj)
|
36
|
+
menu_loc = get_menu_item_locator
|
37
|
+
items = obj.find_elements(menu_loc.keys[0], menu_loc.values[0])
|
38
|
+
items.count
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return array of strings of all menu item captions in a menu object.
|
42
|
+
#
|
43
|
+
# @return [Array]
|
44
|
+
# @example
|
45
|
+
# view_items = view_menu.get_menu_items
|
46
|
+
#
|
47
|
+
def get_menu_items
|
48
|
+
menu_items = []
|
49
|
+
obj = element
|
50
|
+
object_not_found_exception(obj)
|
51
|
+
menu_loc = get_menu_item_locator
|
52
|
+
items = obj.find_elements(menu_loc.keys[0], menu_loc.values[0])
|
53
|
+
items.each do |item|
|
54
|
+
menu_items.push(item.text)
|
55
|
+
end
|
56
|
+
menu_items
|
57
|
+
end
|
58
|
+
|
59
|
+
alias get_list_items get_menu_items
|
60
|
+
|
61
|
+
# Return text caption of menu item at specified index.
|
62
|
+
#
|
63
|
+
# @return [String]
|
64
|
+
# @example
|
65
|
+
# menu_item_text = view_menu.get_menu_item(3)
|
66
|
+
#
|
67
|
+
def get_menu_item(index)
|
68
|
+
items = get_menu_items
|
69
|
+
items[index - 1]
|
70
|
+
end
|
71
|
+
|
72
|
+
alias get_list_item get_menu_item
|
73
|
+
|
74
|
+
def get_item_data(index = nil)
|
75
|
+
menu_items = []
|
76
|
+
obj = element
|
77
|
+
object_not_found_exception(obj)
|
78
|
+
menu_loc = get_menu_item_locator
|
79
|
+
items = obj.find_elements(menu_loc.keys[0], menu_loc.values[0])
|
80
|
+
items.each do |item|
|
81
|
+
caption = item.text
|
82
|
+
state = item.enabled?
|
83
|
+
menu_items.push(
|
84
|
+
{
|
85
|
+
caption: caption,
|
86
|
+
enabled: state
|
87
|
+
}
|
88
|
+
)
|
89
|
+
end
|
90
|
+
if index.nil?
|
91
|
+
menu_items
|
92
|
+
else
|
93
|
+
menu_items[index - 1]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Return enabled state of menu item at specified index.
|
98
|
+
#
|
99
|
+
# @return [Boolean]
|
100
|
+
# @example
|
101
|
+
# menu_item_status = view_menu.get_item_enabled(3)
|
102
|
+
#
|
103
|
+
def get_item_enabled(index)
|
104
|
+
obj = element
|
105
|
+
object_not_found_exception(obj)
|
106
|
+
menu_loc = get_menu_item_locator
|
107
|
+
items = obj.find_elements(menu_loc.keys[0], menu_loc.values[0])
|
108
|
+
items[index - 1].enabled?
|
109
|
+
end
|
110
|
+
|
111
|
+
# Select the specified menu item in a menu object using the specified selection method (mouse or keyboard shortcut).
|
112
|
+
# Accepts a String or Integer representing either the menu item caption or item index.
|
113
|
+
#
|
114
|
+
# @param item [String, Integer] menu item text or index of menu item to select
|
115
|
+
# @param method [Symbol] valid selectors are :mouse, :keys, or :keyboard (default = :mouse)
|
116
|
+
#
|
117
|
+
# @example
|
118
|
+
# view_menu.choose_menu_item(2)
|
119
|
+
# view_menu.choose_menu_item('Programmer')
|
120
|
+
#
|
121
|
+
def choose_menu_item(item, method = :mouse)
|
122
|
+
obj = element
|
123
|
+
object_not_found_exception(obj)
|
124
|
+
case method
|
125
|
+
when :mouse
|
126
|
+
self.click unless self.visible?
|
127
|
+
menu_loc = get_menu_item_locator
|
128
|
+
items = obj.find_elements(menu_loc.keys[0], menu_loc.values[0])
|
129
|
+
case
|
130
|
+
when item == :last
|
131
|
+
items.last.click
|
132
|
+
when item.is_a?(Integer)
|
133
|
+
items[item - 1].click
|
134
|
+
else
|
135
|
+
items.each do |list_item|
|
136
|
+
if list_item.text == item
|
137
|
+
list_item.click
|
138
|
+
break
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
when :keys, :keyboard
|
143
|
+
keys = @key_map[item]
|
144
|
+
raise "No key map found for item #{item}" if keys.empty?
|
145
|
+
Environ.appium_driver.execute_script('macos: keys', { keys: keys })
|
146
|
+
else
|
147
|
+
raise "#{method} is not a valid selector"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
private
|
152
|
+
|
153
|
+
def get_menu_item_locator
|
154
|
+
define_menu_elements({ :menu_item => { class: 'XCUIElementTypeMenuItem' } }) if @menu_item.nil?
|
155
|
+
@menu_item
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module TestCentricity
|
2
|
+
class MenuBar < TestCentricity::ScreenSection
|
3
|
+
trait(:section_name) { 'Menu Bar' }
|
4
|
+
trait(:section_locator) { { class_chain: '**/XCUIElementTypeMenuBar' } }
|
5
|
+
|
6
|
+
# Menu Bar UI elements
|
7
|
+
list :menu_list, { xpath: '//XCUIElementTypeMenuBar' }
|
8
|
+
|
9
|
+
def initialize(name, parent, locator, context)
|
10
|
+
super
|
11
|
+
@parent = nil
|
12
|
+
# define the menu bar item element for the menu bar list object
|
13
|
+
list_elements = { list_item: { xpath: '(//XCUIElementTypeMenuBarItem)' } }
|
14
|
+
menu_list.define_list_elements(list_elements)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_object_type
|
18
|
+
:menubar
|
19
|
+
end
|
20
|
+
|
21
|
+
# Declare and instantiate a single menu UI Element for this MenuBar object.
|
22
|
+
#
|
23
|
+
# @param element_name [Symbol] name of menu object (as a symbol)
|
24
|
+
# @param locator [Hash] { locator_strategy: locator_identifier }
|
25
|
+
# @example
|
26
|
+
# menu :convert_menu, { xpath: '//XCUIElementTypeMenuBarItem[6]' }
|
27
|
+
#
|
28
|
+
def self.menu(element_name, locator)
|
29
|
+
define_section_element(element_name, TestCentricity::AppElements::AppMenu, locator)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Declare and instantiate a collection of menus for this MenuBar object.
|
33
|
+
#
|
34
|
+
# @param element_hash [Hash] names of menus (as symbol) and locator Hash
|
35
|
+
# @example
|
36
|
+
# menus convert_menu: { xpath: '//XCUIElementTypeMenuBarItem[6]' },
|
37
|
+
# view_menu: { xpath: '//XCUIElementTypeMenuBarItem[5]' }
|
38
|
+
#
|
39
|
+
def self.menus(element_hash)
|
40
|
+
element_hash.each_pair { |element_name, locator| menu(element_name, locator) }
|
41
|
+
end
|
42
|
+
|
43
|
+
# Return the number of menus in a MenuBar object.
|
44
|
+
#
|
45
|
+
# @return [Integer]
|
46
|
+
# @example
|
47
|
+
# num_menus = menu_bar.get_item_count
|
48
|
+
#
|
49
|
+
def get_item_count
|
50
|
+
menu_list.get_item_count
|
51
|
+
end
|
52
|
+
|
53
|
+
# Return array of strings of all menus in a MenuBar object.
|
54
|
+
#
|
55
|
+
# @return [Array]
|
56
|
+
# @example
|
57
|
+
# menu_items = menu_bar.get_menubar_items
|
58
|
+
#
|
59
|
+
def get_menubar_items
|
60
|
+
menu_list.get_list_items
|
61
|
+
end
|
62
|
+
|
63
|
+
alias get_list_items get_menubar_items
|
64
|
+
|
65
|
+
# Return text caption of menu item at specified index.
|
66
|
+
#
|
67
|
+
# @return [String]
|
68
|
+
# @example
|
69
|
+
# menubar_item_text = menu_bar.get_menubar_item(3)
|
70
|
+
#
|
71
|
+
def get_menubar_item(index)
|
72
|
+
items = get_list_items
|
73
|
+
items[index - 1]
|
74
|
+
end
|
75
|
+
|
76
|
+
alias get_list_item get_menubar_item
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module TestCentricity
|
2
|
+
module AppElements
|
3
|
+
class AppRadio < AppUIElement
|
4
|
+
def initialize(name, parent, locator, context)
|
5
|
+
super
|
6
|
+
@type = :radio
|
7
|
+
end
|
8
|
+
|
9
|
+
# Is radio selected?
|
10
|
+
#
|
11
|
+
# @return [Boolean]
|
12
|
+
# @example
|
13
|
+
# unicode_radio.selected?
|
14
|
+
#
|
15
|
+
def selected?
|
16
|
+
obj = element
|
17
|
+
object_not_found_exception(obj)
|
18
|
+
if Environ.is_macos?
|
19
|
+
state = obj.value
|
20
|
+
state.to_bool
|
21
|
+
else
|
22
|
+
obj.selected?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set the selected state of a radio button object.
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# unicode_radio.select
|
30
|
+
#
|
31
|
+
def select
|
32
|
+
set_selected_state(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Unselect a radio button object.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# unicode_radio.unselect
|
39
|
+
#
|
40
|
+
def unselect
|
41
|
+
set_selected_state(false)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Set the selected state of a radio button object.
|
45
|
+
#
|
46
|
+
# @param state [Boolean] true = selected / false = unselected
|
47
|
+
# @example
|
48
|
+
# ascii_radio.set_selected_state(true)
|
49
|
+
#
|
50
|
+
def set_selected_state(state)
|
51
|
+
obj = element
|
52
|
+
object_not_found_exception(obj)
|
53
|
+
if state
|
54
|
+
obj.click unless obj.selected?
|
55
|
+
else
|
56
|
+
obj.click if obj.selected?
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module TestCentricity
|
2
|
+
module AppElements
|
3
|
+
class AppSelectList < AppUIElement
|
4
|
+
attr_accessor :list_item
|
5
|
+
|
6
|
+
def initialize(name, parent, locator, context)
|
7
|
+
super
|
8
|
+
@type = :selectlist
|
9
|
+
@list_item = case Environ.device_os
|
10
|
+
when :mac
|
11
|
+
{ class: 'XCUIElementTypeMenuItem' }
|
12
|
+
when :ios
|
13
|
+
{ class: 'XCUIElementTypeOther' }
|
14
|
+
when :android
|
15
|
+
{ class: 'android.view.ViewGroup' }
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def define_list_elements(element_spec)
|
22
|
+
element_spec.each do |element, value|
|
23
|
+
case element
|
24
|
+
when :list_item
|
25
|
+
@list_item = value
|
26
|
+
else
|
27
|
+
raise "#{element} is not a recognized selectlist element"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return the number of items in a list object.
|
33
|
+
#
|
34
|
+
# @return [Integer]
|
35
|
+
# @example
|
36
|
+
# num_convert_items = convert_list.get_list_items
|
37
|
+
#
|
38
|
+
def get_item_count
|
39
|
+
obj = element
|
40
|
+
object_not_found_exception(obj)
|
41
|
+
if Environ.is_ios? && obj.attribute(:type) == 'XCUIElementTypePickerWheel'
|
42
|
+
raise 'This method is not supported for XCUIElementTypePickerWheel controls'
|
43
|
+
end
|
44
|
+
list_loc = get_list_item_locator
|
45
|
+
self.click if Environ.is_macos?
|
46
|
+
items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
|
47
|
+
self.click if Environ.is_macos?
|
48
|
+
items.count
|
49
|
+
end
|
50
|
+
|
51
|
+
# Return array of strings of all items in a selectlist object.
|
52
|
+
#
|
53
|
+
# @return [Array]
|
54
|
+
# @example
|
55
|
+
# convert_items = convert_list.get_list_items
|
56
|
+
#
|
57
|
+
def get_list_items
|
58
|
+
list_items = []
|
59
|
+
obj = element
|
60
|
+
object_not_found_exception(obj)
|
61
|
+
if Environ.is_ios? && obj.attribute(:type) == 'XCUIElementTypePickerWheel'
|
62
|
+
raise 'This method is not supported for XCUIElementTypePickerWheel controls'
|
63
|
+
end
|
64
|
+
list_loc = get_list_item_locator
|
65
|
+
self.click if Environ.is_macos?
|
66
|
+
items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
|
67
|
+
items.each do |item|
|
68
|
+
list_items.push(item.text)
|
69
|
+
end
|
70
|
+
self.click if Environ.is_macos?
|
71
|
+
list_items
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_list_item(index)
|
75
|
+
items = get_list_items
|
76
|
+
items[index - 1]
|
77
|
+
end
|
78
|
+
|
79
|
+
# Select the specified item in a selectlist object. Accepts a String or Integer.
|
80
|
+
#
|
81
|
+
# @param item [String, Integer] text or index of item to select
|
82
|
+
#
|
83
|
+
# @example
|
84
|
+
# convert_list.choose_item(2)
|
85
|
+
# convert_list.choose_item('Power')
|
86
|
+
#
|
87
|
+
def choose_item(item)
|
88
|
+
obj = element
|
89
|
+
object_not_found_exception(obj)
|
90
|
+
if Environ.is_ios? && obj.attribute(:type) == 'XCUIElementTypePickerWheel'
|
91
|
+
obj.send_keys(item)
|
92
|
+
else
|
93
|
+
list_loc = get_list_item_locator
|
94
|
+
self.click if Environ.is_macos?
|
95
|
+
items = obj.find_elements(list_loc.keys[0], list_loc.values[0])
|
96
|
+
if item.is_a?(Integer)
|
97
|
+
items[item - 1].click
|
98
|
+
else
|
99
|
+
items.each do |list_item|
|
100
|
+
if list_item.text == item
|
101
|
+
list_item.click
|
102
|
+
break
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
|
111
|
+
def get_list_item_locator
|
112
|
+
if @list_item.nil?
|
113
|
+
case Environ.device_os
|
114
|
+
when :mac
|
115
|
+
define_list_elements({ :list_item => { class: 'XCUIElementTypeMenuItem' } } )
|
116
|
+
when :ios
|
117
|
+
define_list_elements({ :list_item => { class: 'XCUIElementTypeOther' } } )
|
118
|
+
when :android
|
119
|
+
define_list_elements({ :list_item => { class: 'android.view.ViewGroup' } } )
|
120
|
+
end
|
121
|
+
end
|
122
|
+
@list_item
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|