Class: TestCentricity::SelectList

Inherits:
UIElement show all
Defined in:
lib/testcentricity/web_elements/select_list.rb

Constant Summary

Constants inherited from UIElement

UIElement::CSS_SELECTORS, UIElement::XPATH_SELECTORS

Instance Attribute Summary collapse

Attributes inherited from UIElement

#alt_locator, #context, #locator, #locator_type, #name, #parent, #type

Instance Method Summary collapse

Methods inherited from UIElement

#clear_alt_locator, #click, #click_at, #disabled?, #displayed?, #double_click, #drag_and_drop, #drag_by, #enabled?, #exists?, #get_attribute, #get_locator, #get_name, #get_native_attribute, #get_object_type, #get_siebel_object_type, #get_value, #height, #hidden?, #hover, #invoke_siebel_dialog, #right_click, #send_keys, #set, #set_alt_locator, #set_locator_type, #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.



7
8
9
10
11
12
13
14
15
16
# File 'lib/testcentricity/web_elements/select_list.rb', line 7

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
  }
  define_list_elements(list_spec)
end

Instance Attribute Details

#list_itemObject

Returns the value of attribute list_item.



3
4
5
# File 'lib/testcentricity/web_elements/select_list.rb', line 3

def list_item
  @list_item
end

#list_triggerObject

Returns the value of attribute list_trigger.



5
6
7
# File 'lib/testcentricity/web_elements/select_list.rb', line 5

def list_trigger
  @list_trigger
end

#selected_itemObject

Returns the value of attribute selected_item.



4
5
6
# File 'lib/testcentricity/web_elements/select_list.rb', line 4

def selected_item
  @selected_item
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



46
47
48
49
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
# File 'lib/testcentricity/web_elements/select_list.rb', line 46

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)
    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.has_key?(:index)
        page.find(:css, "#{@list_item}:nth-of-type(#{option[:value]})").click if option.has_key?(:value)
        page.find(:css, "#{@list_item}:nth-of-type(#{option[:text]})").click if option.has_key?(:text)
      else
        options = obj.all(@list_item).collect(&:text)
        sleep(2) unless options.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.

Examples:

country_select.choose_siebel_option('Cayman Islands')

Parameters:

  • option (String)

    text of option to select



152
153
154
155
156
# File 'lib/testcentricity/web_elements/select_list.rb', line 152

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/testcentricity/web_elements/select_list.rb', line 18

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
      else
        raise "#{element} is not a recognized selectlist element"
    end
  end
end

#get_option_countInteger 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.

Examples:

num_colors = color_select.get_option_count

Returns:

  • (Integer)


108
109
110
111
112
113
114
115
116
# File 'lib/testcentricity/web_elements/select_list.rb', line 108

def get_option_count
  obj, = find_element
  object_not_found_exception(obj, nil)
  if first(:css, @list_item)
    obj.all(@list_item).count
  else
    obj.all('option').count
  end
end

#get_optionsArray 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.

Examples:

all_colors = color_select.get_options

Returns:

  • (Array)


89
90
91
92
93
94
95
96
97
# File 'lib/testcentricity/web_elements/select_list.rb', line 89

def get_options
  obj, = find_element
  object_not_found_exception(obj, nil)
  if first(:css, @list_item)
    obj.all(@list_item).collect(&:text)
  else
    obj.all('option').collect(&:text)
  end
end

#get_selected_optionString Also known as: selected?

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:



134
135
136
137
138
139
140
141
142
# File 'lib/testcentricity/web_elements/select_list.rb', line 134

def get_selected_option
  obj, = find_element
  object_not_found_exception(obj, nil)
  if first(:css, @list_item)
    obj.first(:css, @selected_item).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)


164
165
166
167
168
169
170
171
# File 'lib/testcentricity/web_elements/select_list.rb', line 164

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

#read_only?Boolean

Is Siebel JComboBox set to read-only?

Examples:

country_select.read_only?

Returns:

  • (Boolean)


190
191
192
193
194
# File 'lib/testcentricity/web_elements/select_list.rb', line 190

def read_only?
  obj, = find_element
  object_not_found_exception(obj, nil)
  !obj.native.attribute('readonly')
end

#verify_options(expected, enqueue = false) ⇒ Object



120
121
122
123
124
125
# File 'lib/testcentricity/web_elements/select_list.rb', line 120

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

#verify_siebel_options(expected, enqueue = false) ⇒ Object



173
174
175
176
177
178
179
180
181
182
# File 'lib/testcentricity/web_elements/select_list.rb', line 173

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 #{object_ref_message}") :
      assert_equal(expected, actual, "Expected list of options in list #{object_ref_message} to be #{expected} but found #{actual}")
  obj, = find_element
  obj.native.send_keys(:escape)
end