Module: Butternut::Helpers

Defined in:
lib/butternut/helpers.rb

Instance Method Summary collapse

Instance Method Details

#browserObject



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 click_button(button_value)
  browser.button(button_value).click
  @page_changed = true
end

#current_page_sourceObject



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_urlObject



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, options = {})
  elt = find_element_by_label_or_name(:text_field, label_or_name)
  if elt.exist?
    elt.value = options[: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

Returns:

  • (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, options = {})
  elt = find_element_by_label_or_name(:select_list, options[: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