Class: TestCentricity::Elements::SelectList
- Defined in:
- lib/testcentricity_web/web_elements/select_list.rb
Constant Summary
Constants inherited from UIElement
UIElement::CSS_SELECTORS, UIElement::XPATH_SELECTORS
Instance Attribute Summary collapse
-
#group_heading ⇒ Object
Returns the value of attribute group_heading.
-
#group_item ⇒ Object
Returns the value of attribute group_item.
-
#list_item ⇒ Object
Returns the value of attribute list_item.
-
#list_trigger ⇒ Object
Returns the value of attribute list_trigger.
-
#options_list ⇒ Object
Returns the value of attribute options_list.
-
#selected_item ⇒ Object
Returns the value of attribute selected_item.
-
#text_field ⇒ Object
Returns the value of attribute text_field.
Attributes inherited from UIElement
#alt_locator, #base_object, #context, #locator, #locator_type, #mru_driver, #mru_locator, #mru_object, #mru_parent, #name, #original_style, #parent, #type
Instance Method Summary collapse
-
#choose_option(option) ⇒ Object
Select the specified option in a select box object.
- #define_list_elements(element_spec) ⇒ Object
-
#get_group_count ⇒ Integer
Return the number of groups in a select box object.
-
#get_group_headings ⇒ Array
Return array of strings of all group headings in a select box object.
-
#get_option_count ⇒ Integer
(also: #get_item_count)
Return the number of options in a select box object.
-
#get_options ⇒ Array
(also: #get_list_items)
Return array of strings of all options in a select box object.
-
#get_selected_option ⇒ String
(also: #selected?)
Return text of first selected option in a select box object.
-
#initialize(name, parent, locator, context) ⇒ SelectList
constructor
A new instance of SelectList.
- #set(text) ⇒ Object
- #verify_options(expected, enqueue = false) ⇒ Object
Methods inherited from UIElement
#aria_autocomplete, #aria_busy?, #aria_checked?, #aria_colcount, #aria_controls, #aria_describedby, #aria_disabled?, #aria_expanded?, #aria_haspopup?, #aria_hidden?, #aria_invalid?, #aria_keyshortcuts, #aria_label, #aria_labelledby, #aria_live, #aria_modal?, #aria_multiline?, #aria_multiselectable?, #aria_orientation, #aria_pressed?, #aria_readonly?, #aria_required?, #aria_roledescription, #aria_rowcount, #aria_selected?, #aria_sort, #aria_valuemax, #aria_valuemin, #aria_valuenow, #aria_valuetext, #clear_alt_locator, #click, #click_at, #content_editable?, #count, #crossorigin, #disabled?, #displayed?, #double_click, #drag_and_drop, #drag_by, #enabled?, #exists?, #find_element, #focused?, #get_attribute, #get_locator, #get_locator_type, #get_name, #get_native_attribute, #get_object_type, #get_value, #height, #hidden?, #highlight, #hover, #hover_at, #obscured?, #required?, #reset_mru_cache, #right_click, #role, #scroll_to, #send_keys, #set_alt_locator, #set_locator_type, #style, #tabindex, #title, #unhighlight, #verify_value, #visible?, #wait_until_enabled, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #wait_while_busy, #width, #x, #y
Constructor Details
#initialize(name, parent, locator, context) ⇒ SelectList
Returns a new instance of SelectList.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 12 def initialize(name, parent, locator, context) super @type = :selectlist list_spec = { selected_item: "li[class*='result-selected']", list_item: "li[class*='active-result']", list_trigger: nil, text_field: nil, options_list: nil, group_item: 'li.group-result', group_heading: 'li.group-result' } define_list_elements(list_spec) end |
Instance Attribute Details
#group_heading ⇒ Object
Returns the value of attribute group_heading.
10 11 12 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 10 def group_heading @group_heading end |
#group_item ⇒ Object
Returns the value of attribute group_item.
9 10 11 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 9 def group_item @group_item end |
#list_item ⇒ Object
Returns the value of attribute list_item.
4 5 6 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 4 def list_item @list_item end |
#list_trigger ⇒ Object
Returns the value of attribute list_trigger.
6 7 8 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 6 def list_trigger @list_trigger end |
#options_list ⇒ Object
Returns the value of attribute options_list.
8 9 10 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 8 def @options_list end |
#selected_item ⇒ Object
Returns the value of attribute selected_item.
5 6 7 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 5 def selected_item @selected_item end |
#text_field ⇒ Object
Returns the value of attribute text_field.
7 8 9 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 7 def text_field @text_field end |
Instance Method Details
#choose_option(option) ⇒ Object
Select the specified option in a select box object. Accepts a String or Hash. Supports standard HTML select objects and Chosen select objects.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 63 def choose_option(option) @base_object, = find_element object_not_found_exception(@base_object, 'SelectList') trigger_list unless @options_list.nil? find_component(@options_list, 'drop menu') raise "Could not find option #{option} to choose" unless first(:css, @list_item, minimum: 0, wait: 5) if option.is_a?(Array) option.each do |item| page.find(:css, @list_item, text: item.strip).click end else if option.is_a?(Hash) @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:index]})").click if option.key?(:index) @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:value]})").click if option.key?(:value) @base_object.first(:css, "#{@list_item}:nth-of-type(#{option[:text]})").click if option.key?(:text) else = @base_object.all(@list_item).collect(&:text) sleep(2) unless .include?(option) first(:css, @list_item, text: option).click end end return end if first(:css, @list_item, minimum: 0, wait: 2) if option.is_a?(Array) option.each do |item| page.find(:css, @list_item, text: item.strip).click end else if option.is_a?(Hash) page.find(:css, "#{@list_item}:nth-of-type(#{option[:index]})").click if option.key?(:index) page.find(:css, "#{@list_item}:nth-of-type(#{option[:value]})").click if option.key?(:value) page.find(:css, "#{@list_item}:nth-of-type(#{option[:text]})").click if option.key?(:text) else = @base_object.all(@list_item).collect(&:text) sleep(2) unless .include?(option) first(:css, @list_item, text: option).click end end else if option.is_a?(Array) option.each do |item| select_item(@base_object, item) end else select_item(@base_object, option) end end end |
#define_list_elements(element_spec) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 27 def define_list_elements(element_spec) element_spec.each do |element, value| case element when :list_item @list_item = value when :selected_item @selected_item = value when :list_trigger @list_trigger = value when :text_field @text_field = value when :options_list @options_list = value when :group_item @group_item = value when :group_heading @group_heading = value else raise "#{element} is not a recognized selectlist element" end end end |
#get_group_count ⇒ Integer
Return the number of groups in a select box object. Supports React and Chosen select objects.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 213 def get_group_count @base_object, = find_element object_not_found_exception(@base_object, 'SelectList') if @options_list.nil? if @base_object.first(:css, @group_item, minimum: 0, wait: 2) @base_object.all(@group_item).count else 0 end else trigger_list = find_component(@options_list, 'drop menu') num_items = .all(@group_item, visible: true, minimum: 0, wait: 2).count trigger_list num_items end end |
#get_group_headings ⇒ Array
Return array of strings of all group headings in a select box object. Supports React and Chosen select objects.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 188 def get_group_headings @base_object, = find_element object_not_found_exception(@base_object, 'SelectList') if @options_list.nil? if @base_object.first(:css, @group_heading, minimum: 0, wait: 2) @base_object.all(@group_heading).collect(&:text) else nil end else trigger_list = find_component(@options_list, 'drop menu') groups = .all(@group_heading, visible: true, minimum: 0, wait: 2).collect(&:text) trigger_list groups end end |
#get_option_count ⇒ Integer Also known as: get_item_count
Return the number of options in a select box object. Supports standard HTML select objects and Chosen select objects.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 161 def get_option_count @base_object, = find_element object_not_found_exception(@base_object, 'SelectList') if @options_list.nil? if @base_object.first(:css, @list_item, minimum: 0, wait: 2) @base_object.all(@list_item).count else @base_object.all('option', visible: :all).count end else trigger_list = find_component(@options_list, 'drop menu') num_items = .all(@list_item, visible: true, minimum: 0, wait: 2).count trigger_list num_items end end |
#get_options ⇒ Array Also known as: get_list_items
Return array of strings of all options in a select box object. Supports standard HTML select objects and Chosen select objects.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 134 def @base_object, = find_element object_not_found_exception(@base_object, 'SelectList') if @options_list.nil? if @base_object.first(:css, @list_item, minimum: 0, wait: 2) @base_object.all(@list_item).collect(&:text) else @base_object.all('option', visible: :all).collect(&:text) end else trigger_list = find_component(@options_list, 'drop menu') = .all(@list_item, visible: true, minimum: 0, wait: 2).collect(&:text) trigger_list end end |
#get_selected_option ⇒ String Also known as: selected?
Return text of first selected option in a select box object. Supports standard HTML select objects and Chosen select objects.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 247 def get_selected_option @base_object, = find_element object_not_found_exception(@base_object, 'SelectList') trigger_list unless @options_list.nil? selection = if @base_object.first(:css, @list_item, minimum: 0, wait: 1, visible: :all) @base_object.first(:css, @selected_item, wait: 1, visible: :all).text elsif @base_object.first(:css, @selected_item, minimum: 0, wait: 1, visible: :all) @base_object.first(:css, @selected_item, visible: :all).text elsif @base_object.first('option[selected]', minimum: 0, wait: 1, visible: :all) @base_object.first('option[selected]', wait: 1, visible: :all).text else index = get_attribute(:selectedIndex).to_i if index >= 0 = [index] else '' end end trigger_list unless @options_list.nil? selection end |
#set(text) ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 118 def set(text) raise "A 'text_field' list element must be defined before calling the 'set' method on a selectlist object" if @text_field.nil? @base_object, = find_element object_not_found_exception(@base_object, 'SelectList') trigger_list input = find_component(@text_field, 'text field') input.set("#{text}\n") end |
#verify_options(expected, enqueue = false) ⇒ Object
231 232 233 234 235 236 237 238 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 231 def (expected, enqueue = false) actual = if enqueue ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list of options in list #{}") else assert_equal(expected, actual, "Expected list of options in list #{} to be #{expected} but found #{actual}") end end |