Class: TestCentricity::AppSelectList

Inherits:
UIElement
  • Object
show all
Defined in:
lib/testcentricity/app_elements/select_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent, locator, context) ⇒ AppSelectList

Returns a new instance of AppSelectList.



6
7
8
9
10
11
12
13
14
# 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

Instance Attribute Details

#list_itemObject

Returns the value of attribute list_item.



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

def list_item
  @list_item
end

#selected_itemObject

Returns the value of attribute selected_item.



4
5
6
# File 'lib/testcentricity/app_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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# 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_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)


97
98
99
100
101
102
103
104
105
# 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

#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)


78
79
80
81
82
83
84
85
86
# 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

#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:

  • (String)


123
124
125
126
127
128
129
130
131
# 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

#verify_options(expected, enqueue = false) ⇒ Object



109
110
111
112
113
114
# 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