Module: Butternut::Helpers
- Defined in:
- lib/butternut/helpers.rb
Instance Method Summary collapse
- #browser ⇒ Object
- #click_button(button_value) ⇒ Object
- #current_page_source ⇒ Object
- #current_url ⇒ Object
-
#fill_in(label_or_name, options = {}) ⇒ Object
Fill in a text field with a value.
- #find_element_by_label_or_name(type, label_or_name) ⇒ Object
- #page_changed? ⇒ Boolean
- #select(option_text, options = {}) ⇒ Object
- #visit(url) ⇒ Object
Instance Method Details
#browser ⇒ Object
3 4 5 |
# File 'lib/butternut/helpers.rb', line 3 def browser @browser ||= Celerity::Browser.new end |
#click_button(button_value) ⇒ Object
45 46 47 48 |
# File 'lib/butternut/helpers.rb', line 45 def () browser.().click @page_changed = true end |
#current_page_source ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/butternut/helpers.rb', line 16 def current_page_source return nil unless browser.page string_writer = java.io.StringWriter.new print_writer = java.io.PrintWriter.new(string_writer) root = browser.page.document_element node_to_xml(root, print_writer) print_writer.close string_writer.to_string end |
#current_url ⇒ Object
12 13 14 |
# File 'lib/butternut/helpers.rb', line 12 def current_url browser.page.web_response.request_url.to_string end |
#fill_in(label_or_name, options = {}) ⇒ Object
Fill in a text field with a value
29 30 31 32 33 34 35 |
# File 'lib/butternut/helpers.rb', line 29 def fill_in(label_or_name, = {}) elt = find_element_by_label_or_name(:text_field, label_or_name) if elt.exist? elt.value = [:with] @page_changed = true end end |
#find_element_by_label_or_name(type, label_or_name) ⇒ Object
54 55 56 57 |
# File 'lib/butternut/helpers.rb', line 54 def find_element_by_label_or_name(type, label_or_name) elt = browser.send(type, :label, label_or_name) elt.exist? ? elt : browser.send(type, :name, label_or_name) end |
#page_changed? ⇒ Boolean
50 51 52 |
# File 'lib/butternut/helpers.rb', line 50 def page_changed? @page_changed end |
#select(option_text, options = {}) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/butternut/helpers.rb', line 37 def select(option_text, = {}) elt = find_element_by_label_or_name(:select_list, [:from]) if elt.exist? elt.select(option_text) @page_changed = true end end |
#visit(url) ⇒ Object
7 8 9 10 |
# File 'lib/butternut/helpers.rb', line 7 def visit(url) browser.goto(url) @page_changed = true end |