Class: JQueryUIWidgets::Autocomplete

Inherits:
PageObject::Elements::TextField
  • Object
show all
Defined in:
lib/jqueryui_widgets/autocomplete.rb

Overview

Class that wraps around the Autocomplete widget, allowing for the user to interact with the Autocomplete widget, as long as it is active.

NOTE: We’ve only kept to the basic functionality of the Autocmplete widget, allowing for extendability of the class, and to avoid any difficulty by focusing on minutiae.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.accessor_methods(accessor, name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jqueryui_widgets/autocomplete.rb', line 14

def self.accessor_methods(accessor, name)
  accessor.send :define_method, "#{name}=" do |text|
    self.send("#{name}_element").value = text
  end

  accessor.send :define_method, name do
    self.send("#{name}_element").value
  end

  def results
    autocomplete_div_element.list_item_elements.class('ui-menu-item').map(&:text)
  end

  def select(item)
    the_autocomplete = results
    index = the_autocomplete.find_index do |autocomplete|
      autocomplete.text == item
    end
    the_autocomplete[index].click
    wait_for_content(index)
  end

  accessor.send :define_method, "autocomplete_list" do
    self.send "unordered_list_element", :id => 'ui-id-1'
  end

  accessor.send :private, :autocomplete_list


end

Instance Method Details

#resultsObject



23
24
25
# File 'lib/jqueryui_widgets/autocomplete.rb', line 23

def results
  autocomplete_div_element.list_item_elements.class('ui-menu-item').map(&:text)
end

#select(item) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/jqueryui_widgets/autocomplete.rb', line 27

def select(item)
  the_autocomplete = results
  index = the_autocomplete.find_index do |autocomplete|
    autocomplete.text == item
  end
  the_autocomplete[index].click
  wait_for_content(index)
end