Created
November 30, 2012 14:36
-
-
Save camiloribeiro/4176128 to your computer and use it in GitHub Desktop.
Gist updating source code for "http://itreallymatters.net/post/318516310/the-beginning-of-watirs-rspec-html-formatter#.ULi7DNPjkri" to help a girl on DFTests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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