Class: TestCentricity::SelectList

Inherits:
UIElement show all
Defined in:
lib/testcentricity_web/elements/select_list.rb

Instance Attribute Summary

Attributes inherited from UIElement

#alt_locator, #context, #locator, #parent, #type

Instance Method Summary collapse

Methods inherited from UIElement

#clear_alt_locator, #click, #click_at, #disabled?, #double_click, #drag_by, #enabled?, #exists?, #get_attribute, #get_list_items, #get_locator, #get_native_attribute, #get_object_type, #get_siebel_object_type, #get_value, #hidden?, #hover, #invoke_siebel_dialog, #send_keys, #set, #set_alt_locator, #verify_value, #visible?, #wait_until_exists, #wait_until_gone, #wait_until_value_changes, #wait_until_value_is, #wait_until_visible

Constructor Details

#initialize(parent, locator, context) ⇒ SelectList

Returns a new instance of SelectList.



3
4
5
6
7
8
9
# File 'lib/testcentricity_web/elements/select_list.rb', line 3

def initialize(parent, locator, context)
  @parent  = parent
  @locator = locator
  @context = context
  @type    = :selectlist
  @alt_locator = nil
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.

Examples:

province_select.choose_option('Alberta')
province_select.choose_option(:value => 'AB')
state_select.choose_option(:index => 24)
state_select.choose_option(:text => 'Maryland')

Parameters:

  • option (String)

    text of option to select OR

  • option (Hash)

    :value, :index, or :text of option to select



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/testcentricity_web/elements/select_list.rb', line 24

def choose_option(option)
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  obj.click
  if first(:css, 'li.active-result')
    if option.is_a?(Array)
      option.each do |item|
        page.find(:css, 'li.active-result', text: item.strip).click
      end
    else
      first(:css, 'li.active-result', text: option).click
    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.

Examples:

country_select.choose_siebel_option('Cayman Islands')

Parameters:

  • option (String)

    text of option to select



94
95
96
97
98
# File 'lib/testcentricity_web/elements/select_list.rb', line 94

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

#get_optionsArray

Return array of strings of all options in a select box object. Supports standard HTML select objects and Chosen select objects.

Examples:

all_colors = color_select.get_options

Returns:

  • (Array)


54
55
56
57
58
59
60
61
62
# File 'lib/testcentricity_web/elements/select_list.rb', line 54

def get_options
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  if first(:css, 'li.active-result')
    obj.all('li.active-result').collect(&:text)
  else
    obj.all('option').collect(&:text)
  end
end

#get_selected_optionString

Return text of first selected option in a select box object. Supports standard HTML select objects and Chosen select objects.

Examples:

current_color = color_select.get_selected_option

Returns:



78
79
80
81
82
83
84
85
86
# File 'lib/testcentricity_web/elements/select_list.rb', line 78

def get_selected_option
  obj, _ = find_element
  object_not_found_exception(obj, nil)
  if first(:css, 'li.active-result')
    obj.first("//li[contains(@class, 'result-selected')]").text
  else
    obj.first('option[selected]').text
  end
end

#get_siebel_optionsArray

Return array of strings of all options in a Siebel OUI select box object.

Examples:

all_countries = country_select.get_siebel_options

Returns:

  • (Array)


106
107
108
109
110
111
112
113
# File 'lib/testcentricity_web/elements/select_list.rb', line 106

def get_siebel_options
  invoke_siebel_popup
  sleep(0.5)
  options = page.all(:xpath, "//li[@class='ui-menu-item']").collect(&:text)
  obj, _ = find_element
  obj.native.send_keys(:escape)
  options
end

#verify_options(expected, enqueue = false) ⇒ Object



64
65
66
67
68
69
# File 'lib/testcentricity_web/elements/select_list.rb', line 64

def verify_options(expected, enqueue = false)
  actual = get_options
  enqueue ?
      ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list of options in list #{@locator}") :
      assert_equal(expected, actual, "Expected list of options in list #{@locator} to be #{expected} but found #{actual}")
end

#verify_siebel_options(expected, enqueue = false) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'lib/testcentricity_web/elements/select_list.rb', line 115

def verify_siebel_options(expected, enqueue = false)
  invoke_siebel_popup
  sleep(0.5)
  actual = page.all(:xpath, "//li[@class='ui-menu-item']").collect(&:text)
  enqueue ?
      ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list of options in list #{@locator}") :
      assert_equal(expected, actual, "Expected list of options in list #{@locator} to be #{expected} but found #{actual}")
  obj, _ = find_element
  obj.native.send_keys(:escape)
end