class TestCentricity::AppSelectList
Attributes
list_item[RW]
selected_item[RW]
Public Class Methods
new(name, parent, locator, context)
click to toggle source
Calls superclass method
# File lib/testcentricity/app_elements/select_list.rb, line 6 def initialize(name, parent, locator, context) super @type = :selectlist list_spec = { :list_item => 'option', :selected_item => 'option[selected]' } define_list_elements(list_spec) end
Public Instance Methods
choose_option(option)
click to toggle source
Select the specified option in a select box object. Accepts a String
or Hash. Supports standard HTML select objects and Chosen select objects.
@param option [String] text of option to select
OR
@param option [Hash] :value, :index, or :text of option to select
@example
province_select.choose_option('Alberta') province_select.choose_option(:value => 'AB') state_select.choose_option(:index => 24) state_select.choose_option(:text => 'Maryland')
# File lib/testcentricity/app_elements/select_list.rb, line 42 def choose_option(option) obj, = find_element object_not_found_exception(obj, nil) obj.click if first(:css, "li[class*='active-result']") if option.is_a?(Array) option.each do |item| page.find(:css, "li[class*='active-result']", text: item.strip).click end else if option.is_a?(Hash) page.find(:css, "li[class*='active-result']:nth-of-type(#{option[:index]})").click if option.has_key?(:index) else options = obj.all("li[class*='active-result']").collect(&:text) sleep(2) unless options.include?(option) first(:css, "li[class*='active-result']", 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
define_list_elements(element_spec)
click to toggle source
# File lib/testcentricity/app_elements/select_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 selectlist element" end end end
get_option_count()
click to toggle source
Return the number of options in a select box object. Supports standard HTML select objects and Chosen select objects.
@return [Integer] @example
num_colors = color_select.get_option_count
# File lib/testcentricity/app_elements/select_list.rb, line 97 def get_option_count obj, = find_element object_not_found_exception(obj, nil) if first(:css, "li[class*='active-result']") obj.all("li[class*='active-result']").count else obj.all(@list_item).count end end
Also aliased as: get_item_count
get_options()
click to toggle source
Return array of strings of all options in a select box object. Supports standard HTML select objects and Chosen select objects.
@return [Array] @example
all_colors = color_select.get_options
# File lib/testcentricity/app_elements/select_list.rb, line 78 def get_options obj, = find_element object_not_found_exception(obj, nil) if first(:css, "li[class*='active-result']") obj.all("li[class*='active-result']").collect(&:text) else obj.all(@list_item).collect(&:text) end end
Also aliased as: get_list_items
get_selected_option()
click to toggle source
Return text of first selected option in a select box object. Supports standard HTML select objects and Chosen select objects.
@return [String] @example
current_color = color_select.get_selected_option
# File lib/testcentricity/app_elements/select_list.rb, line 123 def get_selected_option obj, = find_element object_not_found_exception(obj, nil) if first(:css, "li[class*='active-result']") obj.first(:css, "li[class*='result-selected']").text else obj.first(@selected_item).text end end
Also aliased as: selected?
verify_options(expected, enqueue = false)
click to toggle source
# File lib/testcentricity/app_elements/select_list.rb, line 109 def verify_options(expected, enqueue = false) actual = get_options enqueue ? ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list of options in list #{object_ref_message}") : assert_equal(expected, actual, "Expected list of options in list #{object_ref_message} to be #{expected} but found #{actual}") end
Private Instance Methods
select_item(obj, option)
click to toggle source
# File lib/testcentricity/app_elements/select_list.rb, line 137 def select_item(obj, option) if option.is_a?(Hash) obj.find("option[value='#{option[:value]}']").click if option.has_key?(:value) obj.find(:xpath, "option[#{option[:index]}]").select_option if option.has_key?(:index) obj.select option[:text] if option.has_key?(:text) else obj.select option end end