Module: Webrat::SaveAndOpenPage
- Included in:
- SeleniumSession, Session
- Defined in:
- lib/webrat/core/save_and_open_page.rb
Instance Method Summary collapse
-
#open_in_browser(path) ⇒ Object
:nodoc.
-
#save_and_open_page ⇒ Object
Saves the page out to Rails.root/tmp/ and opens it in the default web browser if on OS X.
Instance Method Details
#open_in_browser(path) ⇒ Object
:nodoc
20 21 22 23 24 25 |
# File 'lib/webrat/core/save_and_open_page.rb', line 20 def open_in_browser(path) # :nodoc require "launchy" Launchy.open(path) rescue LoadError warn "Sorry, you need to install launchy to open pages: `gem install launchy`" end |
#save_and_open_page ⇒ Object
Saves the page out to Rails.root/tmp/ and opens it in the default web browser if on OS X. Useful for debugging.
Example:
save_and_open_page
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/webrat/core/save_and_open_page.rb', line 8 def save_and_open_page return unless File.exist?(Webrat.configuration.saved_pages_dir) filename = "#{Webrat.configuration.saved_pages_dir}/webrat-#{Time.now.to_i}.html" File.open(filename, "w") do |f| f.write response_body end open_in_browser(filename) end |