Module: RWebUnit::RSpecHelper

Includes:
Assert, Driver, Utils
Defined in:
lib/rwebunit/rspec_helper.rb

Instance Method Summary collapse

Methods included from Assert

#assert_button_not_present, #assert_button_not_present_with_text, #assert_button_present, #assert_button_present_with_text, #assert_checkbox_not_selected, #assert_checkbox_selected, #assert_element_not_present, #assert_element_present, #assert_equals, #assert_link_not_present_with_exact, #assert_link_not_present_with_text, #assert_link_present_with_exact, #assert_link_present_with_text, #assert_nil, #assert_not_nil, #assert_option_equals, #assert_option_not_present, #assert_option_present, #assert_option_value_equals, #assert_option_value_not_present, #assert_option_value_present, #assert_radio_option_not_present, #assert_radio_option_not_selected, #assert_radio_option_present, #assert_radio_option_selected, #assert_text_in_element, #assert_text_in_table, #assert_text_not_in_table, #assert_text_not_present, #assert_text_present, #assert_text_present_in_text_field, #assert_title_equals, #fail

Methods included from Utils

#days_before, #days_from_now, #random_boolean, #random_char, #random_digit, #random_number, #random_str, #random_string_in, #today, #tomorrow, #yesterday

Methods included from Driver

#ajax_wait_for_element, #allow, #attach_browser, #begin_at, #click_button_with_image_src_contains, #click_popup_window, #close_browser, #contains_text, #context, #dump_response, #expect_page, #failsafe, #goto_page, #ie, #new_popup_window, #on, #operation_delay, #save_current_page, #shall_not_allow, #wait_for_element

Instance Method Details

#browserObject



24
25
26
# File 'lib/rwebunit/rspec_helper.rb', line 24

def browser
  @web_tester
end

#button_by_id(button_id) ⇒ Object



92
93
94
# File 'lib/rwebunit/rspec_helper.rb', line 92

def button_by_id(button_id)
  button(:id, button_id)
end

#buttons_by_caption(text) ⇒ Object Also known as: buttons_by_text



96
97
98
# File 'lib/rwebunit/rspec_helper.rb', line 96

def buttons_by_caption(text)
  button(:text, text)
end

#element_by_id(elem_id) ⇒ Object



88
89
90
# File 'lib/rwebunit/rspec_helper.rb', line 88

def element_by_id(elem_id)
  @web_tester.element_by_id(elem_id)
end

#element_source(elem_id) ⇒ Object

TODO: is it working?



84
85
86
# File 'lib/rwebunit/rspec_helper.rb', line 84

def element_source(elem_id)
  @web_tester.get_html_in_element(elem_id)
end

#element_text(elem_id) ⇒ Object Also known as: element_text_by_id



78
79
80
# File 'lib/rwebunit/rspec_helper.rb', line 78

def element_text(elem_id)
  @web_tester.element_value(elem_id)
end


101
102
103
# File 'lib/rwebunit/rspec_helper.rb', line 101

def link_by_id(link_id)
  link(:id, link_id)
end

default options: exact => true



106
107
108
109
110
111
112
113
# File 'lib/rwebunit/rspec_helper.rb', line 106

def links_by_text(link_text, options = {})
  options.merge!({:exact=> true})
  matching_links = []
  links.each { |link|
    matching_links << link if (options[:exact] ? link.text == link_text :  link.text.include?(link_text))
  }
  return matching_links
end

#open_browser(base_url = nil, options = {}) ⇒ Object Also known as: open_browser_with

open a browser, and set base_url via hash, but does not acually

example:

open_browser :base_url => http://localhost:8080


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rwebunit/rspec_helper.rb', line 32

def open_browser(base_url = nil, options = {})
  base_url ||= ENV['ITEST_PROJECT_BASE_URL']
  raise "base_url must be set" if base_url.nil?
  
  default_options = {:speed => "fast",
    :visible => true,
    :highlight_colour => 'yellow',
    :close_others => true,
    :start_new => false, 	# start a new browser always
    :go => true}

  options = default_options.merge options
  options[:firefox] = true if "Firefox" == ENV['ITEST_BROWSER']
  (ENV['ITEST_HIDE_BROWSER'] == "true") ? $HIDE_IE = true : $HIDE_IE = false

  uri = URI.parse(base_url)
  uri_base = "#{uri.scheme}://#{uri.host}:#{uri.port}"
  if options[:start_new] || @web_tester.nil?
    @web_tester = WebTester.new(uri_base, options)
  end

  if options[:go]
    (uri.path.length == 0) ?  begin_at("/") :  begin_at(uri.path)
  end
  return @web_tester
end

#page_sourceObject



67
68
69
# File 'lib/rwebunit/rspec_helper.rb', line 67

def page_source
  @web_tester.page_source
end

#page_titleObject

Content



63
64
65
# File 'lib/rwebunit/rspec_helper.rb', line 63

def page_title
  @web_tester.page_title
end

#save_content_to_file(content, file_name = nil) ⇒ Object



120
121
122
123
124
# File 'lib/rwebunit/rspec_helper.rb', line 120

def save_content_to_file(content, file_name = nil)      
  file_name ||= Time.now.strftime("%Y%m%d%H%M%S") + ".html"
  puts "about to save page: #{File.expand_path(file_name)}"
  File.open(file_name, "w").puts content
end

#save_page(file_name = nil) ⇒ Object



116
117
118
# File 'lib/rwebunit/rspec_helper.rb', line 116

def save_page(file_name = nil)
  @web_tester.save_page(file_name)
end

#table_source(table_id) ⇒ Object Also known as: table_source_by_id



71
72
73
74
75
# File 'lib/rwebunit/rspec_helper.rb', line 71

def table_source(table_id)
  elem = @@browser.document.getElementById(table_id)
  raise "The element '#{table_id}' is not a table or there are multple elements with same id" unless elem.name.uppercase == "TABLE"
  elem.innerHTML
end