Skip to content

Instantly share code, notes, and snippets.

@camiloribeiro
Created November 30, 2012 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camiloribeiro/4176128 to your computer and use it in GitHub Desktop.
Save camiloribeiro/4176128 to your computer and use it in GitHub Desktop.
require "rspec/core/formatters/base_text_formatter"
class WatirHtmlFormatter < RSpec::Core::Formatters::BaseTextFormatter
end
def extra_failure_content(failure)
content = []
content << "<span>"
file_name = save_html
content << link_for(file_name)
file_name = save_screenshot
content << link_for(file_name)
content << "</span>"
super + content.join($/)
end
def save_html
begin
html = $browser.html
file_name = file_path("browser.html")
File.open(file_name, 'w') {|f| f.puts html}
rescue => e
$stderr.puts "saving of html failed: #{e.message}"
$stderr.puts e.backtrace
end
file_name
end
def save_screenshot
begin
$browser.bring_to_front
width, height, blob = Win32::Screenshot.capture_hwnd($browser.hwnd)
file_name = file_path("screenshot.png")
img = Magick::ImageList.new
img.from_blob(blob)
img.write(file_name)
rescue => e
$stderr.puts "saving of screenshot failed: #{e.message}"
$stderr.puts e.backtrace
end
file_name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment