Module: Steam::Browser::HtmlUnit::Actions
- Included in:
- Steam::Browser::HtmlUnit
- Defined in:
- lib/steam/browser/html_unit/actions.rb
Constant Summary collapse
- DATE_TIME_CODE =
Rails specific respond_tos
{ :year => '1i', :month => '2i', :day => '3i', :hour => '4i', :minute => '5i', :second => '6i' }
Instance Method Summary collapse
-
#attach_file(element, path, options = {}) ⇒ Object
TODO implement a way to supply content_type.
- #blur(element, options = {}) ⇒ Object
- #check(element, options = {}) ⇒ Object
- #choose(element, options = {}) ⇒ Object
- #click_area(element, options = {}) ⇒ Object
- #click_button(element, options = {}) ⇒ Object
- #click_link(element, options = {}) ⇒ Object
- #click_on(*args) ⇒ Object
- #double_click(element, options = {}) ⇒ Object
- #drag(element, options = {}) ⇒ Object
- #drag_and_drop(element, options = {}) ⇒ Object
- #drop(element = nil, options = {}) ⇒ Object
- #fill_in(element, options = {}) ⇒ Object
- #focus(element, options = {}) ⇒ Object
- #hover(element, options = {}) ⇒ Object
- #select(element, options = {}) ⇒ Object
- #select_date(date, options = {}) ⇒ Object
- #select_datetime(datetime, options = {}) ⇒ Object
- #select_time(time, options = {}) ⇒ Object
- #set_hidden_field(element, options = {}) ⇒ Object
- #submit_form(element, options = {}) ⇒ Object
- #uncheck(element, options = {}) ⇒ Object
Instance Method Details
#attach_file(element, path, options = {}) ⇒ Object
TODO implement a way to supply content_type
61 62 63 64 65 66 |
# File 'lib/steam/browser/html_unit/actions.rb', line 61 def attach_file(element, path, = {}) respond_to do element = locate_in_browser(:file, element, ) element.setValueAttribute(path) end end |
#blur(element, options = {}) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/steam/browser/html_unit/actions.rb', line 107 def blur(element, = {}) respond_to do locate_in_browser(element, ).blur @page # blur seems to return nil end end |
#check(element, options = {}) ⇒ Object
36 37 38 |
# File 'lib/steam/browser/html_unit/actions.rb', line 36 def check(element, = {}) respond_to { locate_in_browser(:check_box, element, ).setChecked(true) } end |
#choose(element, options = {}) ⇒ Object
44 45 46 |
# File 'lib/steam/browser/html_unit/actions.rb', line 44 def choose(element, = {}) respond_to { locate_in_browser(:radio_button, element, ).setChecked(true) } end |
#click_area(element, options = {}) ⇒ Object
22 23 24 |
# File 'lib/steam/browser/html_unit/actions.rb', line 22 def click_area(element, = {}) respond_to { locate_in_browser(:area, element, ).click } end |
#click_button(element, options = {}) ⇒ Object
18 19 20 |
# File 'lib/steam/browser/html_unit/actions.rb', line 18 def (element, = {}) respond_to { locate_in_browser(:button, element, ).click } end |
#click_link(element, options = {}) ⇒ Object
14 15 16 |
# File 'lib/steam/browser/html_unit/actions.rb', line 14 def click_link(element, = {}) respond_to { locate_in_browser(:link, element, ).click } end |
#click_on(*args) ⇒ Object
10 11 12 |
# File 'lib/steam/browser/html_unit/actions.rb', line 10 def click_on(*args) respond_to { locate_in_browser(*args).click } end |
#double_click(element, options = {}) ⇒ Object
121 122 123 |
# File 'lib/steam/browser/html_unit/actions.rb', line 121 def double_click(element, = {}) respond_to { locate_in_browser(element, ).dblClick } end |
#drag(element, options = {}) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/steam/browser/html_unit/actions.rb', line 80 def drag(element, = {}) respond_to do target = extract_drop_target!(, [:to, :onto, :over, :target]) element = locate_in_browser(element, ) if target element.mouseDown @_drop_target = locate_in_browser(target) @_drop_target.mouseMove else element.mouseDown end end end |
#drag_and_drop(element, options = {}) ⇒ Object
75 76 77 78 |
# File 'lib/steam/browser/html_unit/actions.rb', line 75 def drag_and_drop(element, = {}) drag(element, ) drop end |
#drop(element = nil, options = {}) ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/steam/browser/html_unit/actions.rb', line 94 def drop(element = nil, = {}) respond_to do element = @_drop_target || locate_in_browser(element, ) element.mouseMove unless @_drop_target @_drop_target = nil element.mouseUp end end |
#fill_in(element, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/steam/browser/html_unit/actions.rb', line 26 def fill_in(element, = {}) respond_to do value = .delete(:with) element = locate_in_browser(:field, element, ) result = element.setText(value) rescue element.setValueAttribute(value) # TODO - submit a bug: element.setText returns nil, textarea.setValueAttribute returns a page result || page end end |
#focus(element, options = {}) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/steam/browser/html_unit/actions.rb', line 114 def focus(element, = {}) respond_to do locate_in_browser(element, ).focus @page # focus seems to return nil end end |
#hover(element, options = {}) ⇒ Object
103 104 105 |
# File 'lib/steam/browser/html_unit/actions.rb', line 103 def hover(element, = {}) respond_to { locate_in_browser(element, ).mouseOver } end |
#select(element, options = {}) ⇒ Object
48 49 50 51 |
# File 'lib/steam/browser/html_unit/actions.rb', line 48 def select(element, = {}) .update(:within => [:select, .delete(:from)]) respond_to { locate_in_browser(:select_option, element, ).setSelected(true) } end |
#select_date(date, options = {}) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/steam/browser/html_unit/actions.rb', line 135 def select_date(date, = {}) date = date.respond_to?(:strftime) ? date : Date.parse(date) prefix = locate_id_prefix() # FIXME .to_s chould be done somewhere inside the locator select(date.year.to_s, :from => "#{prefix}_#{DATE_TIME_CODE[:year]}") select(date.strftime('%B'), :from => "#{prefix}_#{DATE_TIME_CODE[:month]}") select(date.day.to_s, :from => "#{prefix}_#{DATE_TIME_CODE[:day]}") end |
#select_datetime(datetime, options = {}) ⇒ Object
145 146 147 148 |
# File 'lib/steam/browser/html_unit/actions.rb', line 145 def select_datetime(datetime, = {}) select_date(datetime) select_time(datetime) end |
#select_time(time, options = {}) ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/steam/browser/html_unit/actions.rb', line 150 def select_time(time, = {}) time = time.respond_to?(:strftime) ? time : DateTime.parse(time) prefix = locate_id_prefix() select(time.hour.to_s.rjust(2,'0'), :from => "#{prefix}_#{DATE_TIME_CODE[:hour]}") select(time.min.to_s.rjust(2,'0'), :from => "#{prefix}_#{DATE_TIME_CODE[:minute]}") # second? end |
#set_hidden_field(element, options = {}) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/steam/browser/html_unit/actions.rb', line 53 def set_hidden_field(element, = {}) respond_to do value = .delete(:to) locate_in_browser(:hidden_field, element, ).setValueAttribute(value) end end |
#submit_form(element, options = {}) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/steam/browser/html_unit/actions.rb', line 68 def submit_form(element, = {}) respond_to do scope = [:form, element, ] locate_in_browser(:input, :type => 'submit', :within => scope).click end end |
#uncheck(element, options = {}) ⇒ Object
40 41 42 |
# File 'lib/steam/browser/html_unit/actions.rb', line 40 def uncheck(element, = {}) respond_to { locate_in_browser(:check_box, element, ).setChecked(false) } end |