Class: TestCentricity::List
- Defined in:
- lib/testcentricity_web/web_elements/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.
-
#selected_item ⇒ Object
Returns the value of attribute selected_item.
Attributes inherited from UIElement
#alt_locator, #context, #locator, #locator_type, #name, #original_style, #parent, #type
Instance Method Summary collapse
- #choose_item(item) ⇒ Object
- #define_list_elements(element_spec) ⇒ Object
- #get_all_items_count ⇒ Object
- #get_all_list_items(element_spec = nil) ⇒ Object
-
#get_item_count ⇒ Integer
(also: #item_count)
Return the number of items in a list object.
- #get_list_item(index, visible = true) ⇒ Object
-
#get_list_items(element_spec = nil) ⇒ Array
Return array of strings of all items in a list object.
- #get_list_row_locator(row) ⇒ Object
-
#get_selected_item ⇒ String
(also: #selected?)
Return text of first selected item in a list object.
-
#initialize(name, parent, locator, context) ⇒ List
constructor
A new instance of List.
- #verify_list_items(expected, enqueue = false) ⇒ Object
-
#wait_until_item_count_changes(seconds = nil, post_exception = true) ⇒ Object
Wait until the list's item count changes to a different value, or until the specified wait time has expired.
-
#wait_until_item_count_is(value, seconds = nil, post_exception = true) ⇒ Object
Wait until the list's item_count equals the specified value, or until the specified wait time has expired.
Methods inherited from UIElement
#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, #invoke_siebel_dialog, #right_click, #send_keys, #set, #set_alt_locator, #set_locator_type, #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) ⇒ List
Returns a new instance of List.
6 7 8 9 10 11 12 13 14 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 6 def initialize(name, parent, locator, context) super @type = :list list_spec = { list_item: 'li', selected_item: 'li.selected' } 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/list.rb', line 3 def list_item @list_item end |
#selected_item ⇒ Object
Returns the value of attribute selected_item.
4 5 6 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 4 def selected_item @selected_item end |
Instance Method Details
#choose_item(item) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 29 def choose_item(item) obj, = find_element object_not_found_exception(obj, nil) if item.is_a?(Integer) obj.find(:css, "#{@list_item}:nth-of-type(#{item})").click elsif item.is_a?(String) items = obj.all(@list_item).collect(&:text) sleep(2) unless items.include?(item) obj.first(:css, @list_item, text: item).click end end |
#define_list_elements(element_spec) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 16 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 else raise "#{element} is not a recognized list element" end end end |
#get_all_items_count ⇒ Object
80 81 82 83 84 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 80 def get_all_items_count obj, = find_element object_not_found_exception(obj, nil) obj.all(@list_item, visible: :all).count end |
#get_all_list_items(element_spec = nil) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 73 def get_all_list_items(element_spec = nil) define_list_elements(element_spec) unless element_spec.nil? obj, = find_element object_not_found_exception(obj, nil) obj.all(@list_item, visible: :all).collect(&:text) end |
#get_item_count ⇒ Integer Also known as: item_count
Return the number of items in a list object.
65 66 67 68 69 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 65 def get_item_count obj, = find_element object_not_found_exception(obj, nil) obj.all(@list_item).count end |
#get_list_item(index, visible = true) ⇒ Object
54 55 56 57 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 54 def get_list_item(index, visible = true) items = visible ? get_list_items : get_all_list_items items[index - 1] end |
#get_list_items(element_spec = nil) ⇒ Array
Return array of strings of all items in a list object.
47 48 49 50 51 52 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 47 def get_list_items(element_spec = nil) define_list_elements(element_spec) unless element_spec.nil? obj, = find_element object_not_found_exception(obj, nil) obj.all(@list_item).collect(&:text) end |
#get_list_row_locator(row) ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 109 def get_list_row_locator(row) case @locator_type when :xpath "#{@locator}/#{@list_item}[#{row}]" when :css "#{@locator} > #{@list_item}:nth-of-type(#{row})" end end |
#get_selected_item ⇒ String Also known as: selected?
Return text of first selected item in a list object.
92 93 94 95 96 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 92 def get_selected_item obj, = find_element object_not_found_exception(obj, nil) obj.first(:css, @list_item, minimum: 0) ? obj.first(:css, @selected_item).text : nil end |
#verify_list_items(expected, enqueue = false) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 100 def verify_list_items(expected, enqueue = false) actual = get_list_items if enqueue ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list #{}") else assert_equal(expected, actual, "Expected list #{} to be #{expected} but found #{actual}") end end |
#wait_until_item_count_changes(seconds = nil, post_exception = true) ⇒ Object
Wait until the list's item count changes to a different value, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 147 def wait_until_item_count_changes(seconds = nil, post_exception = true) value = get_item_count timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { get_item_count != value } rescue if post_exception raise "Value of List #{} failed to change from '#{value}' after #{timeout} seconds" if get_item_count == value else get_item_count == value end end |
#wait_until_item_count_is(value, seconds = nil, post_exception = true) ⇒ Object
Wait until the list's item_count equals the specified value, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Capybara.default_max_wait_time.
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/testcentricity_web/web_elements/list.rb', line 128 def wait_until_item_count_is(value, seconds = nil, post_exception = true) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { compare(value, get_item_count) } rescue if post_exception raise "Value of List #{} failed to equal '#{value}' after #{timeout} seconds" unless get_item_count == value else get_item_count == value end end |