Class: TestCentricity::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
-
#list_item ⇒ Object
Returns the value of attribute list_item.
-
#list_trigger ⇒ Object
Returns the value of attribute list_trigger.
-
#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, #context, #locator, #locator_type, #name, #original_style, #parent, #type
Instance Method Summary collapse
-
#choose_option(option) ⇒ Object
Select the specified option in a select box object.
-
#choose_siebel_option(option) ⇒ Object
Select the specified option in a Siebel OUI select box object.
- #define_list_elements(element_spec) ⇒ 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.
-
#get_siebel_options ⇒ Array
Return array of strings of all options in a Siebel OUI select box object.
-
#initialize(name, parent, locator, context) ⇒ SelectList
constructor
A new instance of SelectList.
-
#read_only? ⇒ Boolean
Is Siebel JComboBox set to read-only?.
- #set(text) ⇒ Object
- #verify_options(expected, enqueue = false) ⇒ Object
- #verify_siebel_options(expected, enqueue = false) ⇒ Object
Methods inherited from UIElement
#aria_checked?, #aria_colcount, #aria_describedby, #aria_disabled?, #aria_expanded?, #aria_haspopup?, #aria_hidden?, #aria_invalid?, #aria_label, #aria_labelledby, #aria_live, #aria_pressed?, #aria_readonly?, #aria_required?, #aria_rowcount, #aria_selected?, #aria_sort, #clear_alt_locator, #click, #click_at, #count, #disabled?, #displayed?, #double_click, #drag_and_drop, #drag_by, #enabled?, #exists?, #get_attribute, #get_locator, #get_locator_type, #get_name, #get_native_attribute, #get_object_type, #get_siebel_object_type, #get_value, #height, #hidden?, #highlight, #hover, #hover_at, #invoke_siebel_dialog, #right_click, #role, #send_keys, #set_alt_locator, #set_locator_type, #style, #tabindex, #unhighlight, #verify_value, #visible?, #wait_until_exists, #wait_until_gone, #wait_until_hidden, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible, #width, #x, #y
Constructor Details
#initialize(name, parent, locator, context) ⇒ SelectList
Returns a new instance of SelectList.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 8 def initialize(name, parent, locator, context) super @type = :selectlist list_spec = { list_item: "li[class*='active-result']", selected_item: "li[class*='result-selected']", list_trigger: nil, text_field: nil } define_list_elements(list_spec) end |
Instance Attribute Details
#list_item ⇒ Object
Returns the value of attribute list_item.
3 4 5 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 3 def list_item @list_item end |
#list_trigger ⇒ Object
Returns the value of attribute list_trigger.
5 6 7 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 5 def list_trigger @list_trigger end |
#selected_item ⇒ Object
Returns the value of attribute selected_item.
4 5 6 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 4 def selected_item @selected_item end |
#text_field ⇒ Object
Returns the value of attribute text_field.
6 7 8 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 6 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.
50 51 52 53 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 83 84 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 50 def choose_option(option) obj, = find_element object_not_found_exception(obj, nil) if @list_trigger.nil? obj.click else page.find(:css, @list_trigger).click sleep(1) end if first(:css, @list_item, minimum: 0) 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 = obj.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(obj, item) end else select_item(obj, option) end end end |
#choose_siebel_option(option) ⇒ Object
Select the specified option in a Siebel OUI select box object.
172 173 174 175 176 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 172 def choose_siebel_option(option) Capybara.wait_on_first_by_default = true invoke_siebel_popup first(:xpath, "//li[@class='ui-menu-item']", exact: true, match: :prefer_exact, text: option).click end |
#define_list_elements(element_spec) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 20 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 else raise "#{element} is not a recognized selectlist element" end 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.
126 127 128 129 130 131 132 133 134 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 126 def get_option_count obj, = find_element object_not_found_exception(obj, nil) if obj.first(:css, @list_item, minimum: 0) obj.all(@list_item).count else obj.all('option', visible: :all).count 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.
107 108 109 110 111 112 113 114 115 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 107 def obj, = find_element object_not_found_exception(obj, nil) if obj.first(:css, @list_item, minimum: 0) obj.all(@list_item).collect(&:text) else obj.all('option', visible: :all).collect(&:text) 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.
154 155 156 157 158 159 160 161 162 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 154 def get_selected_option obj, = find_element object_not_found_exception(obj, nil) if obj.first(:css, @list_item, minimum: 0) obj.first(:css, @selected_item).text else obj.first('option[selected]', visible: :all).text end end |
#get_siebel_options ⇒ Array
Return array of strings of all options in a Siebel OUI select box object.
184 185 186 187 188 189 190 191 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 184 def invoke_siebel_popup sleep(0.5) = page.all(:xpath, "//li[@class='ui-menu-item']").collect(&:text) obj, = find_element obj.native.send_keys(:escape) end |
#read_only? ⇒ Boolean
Is Siebel JComboBox set to read-only?
212 213 214 215 216 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 212 def read_only? obj, = find_element object_not_found_exception(obj, nil) !obj.native.attribute('readonly') end |
#set(text) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 86 def set(text) if @text_field.nil? raise "A 'text_field' list element must be defined before calling the 'set' method on a selectlist object" end obj, = find_element object_not_found_exception(obj, nil) if @list_trigger.nil? obj.click else page.find(:css, @list_trigger).click end page.find(:css, @text_field, wait: 2).set(text) end |
#verify_options(expected, enqueue = false) ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 138 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 |
#verify_siebel_options(expected, enqueue = false) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/testcentricity_web/web_elements/select_list.rb', line 193 def (expected, enqueue = false) invoke_siebel_popup sleep(0.5) actual = page.all(:xpath, "//li[@class='ui-menu-item']").collect(&:text) 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 obj, = find_element obj.native.send_keys(:escape) end |