Skip to content

Commit

Permalink
Consistently output the screenshot path when tests are run
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheworiordan committed Jul 22, 2014
1 parent 5936482 commit 4247c42
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion capybara-screenshot.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Gem::Specification.new do |s|
s.add_dependency 'capybara', ['>= 1.0', '< 3']
end
s.add_dependency 'launchy'

s.add_dependency 'colorize'

s.add_development_dependency 'rspec', '~> 2.7'
s.add_development_dependency 'timecop'

Expand Down
3 changes: 2 additions & 1 deletion lib/capybara-screenshot/cucumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
saver.save
saver.output_screenshot_path

# Trying to embed the screenshot into our output."
if File.exist?(saver.screenshot_path)
Expand All @@ -15,4 +16,4 @@
embed("data:image/png;base64,#{encoded_img}", 'image/png', "Screenshot of the error")
end
end
end
end
3 changes: 2 additions & 1 deletion lib/capybara-screenshot/minitest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
saver.save
saver.output_screenshot_path
end
end
rescue NoMethodError
# do nothing, teardown for minitest not available
end
end
end
5 changes: 2 additions & 3 deletions lib/capybara-screenshot/rspec/text_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ def dump_failure_info_with_screenshot(example)
dump_failure_info_without_screenshot(example)
return unless (screenshot = example.metadata[:screenshot])

colorize = lambda { |str| respond_to?(:failure_color, true) ? failure_color(str) : red(str) }
output.puts(long_padding + colorize["HTML page: #{screenshot[:html]}"]) if screenshot[:html]
output.puts(long_padding + colorize["Screenshot: #{screenshot[:image]}"]) if screenshot[:image]
output.puts(long_padding + "HTML screenshot: #{screenshot[:html]}".colorize(:yellow)) if screenshot[:html]
output.puts(long_padding + "Image screenshot: #{screenshot[:image]}".colorize(:yellow)) if screenshot[:image]
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/capybara-screenshot/saver.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'colorize'

module Capybara
module Screenshot
class Saver
Expand Down Expand Up @@ -67,6 +69,11 @@ def clear_save_and_open_page_path
yield
Capybara.save_and_open_page_path = old_path
end

def output_screenshot_path
puts " #{"HTML screenshot: #{html_path}".colorize(:yellow)}" if html_saved?
puts " #{"Image screenshot: #{screenshot_path}".colorize(:yellow)}" if screenshot_saved?
end
end
end
end
3 changes: 2 additions & 1 deletion lib/capybara-screenshot/spinach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
filename_prefix = Capybara::Screenshot.filename_prefix_for(:spinach, step_data)
saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
saver.save
saver.output_screenshot_path
end
end
end
1 change: 1 addition & 0 deletions lib/capybara-screenshot/testunit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def notify_fault_with_screenshot(fault, *args)

saver = Capybara::Screenshot::Saver.new(Capybara, Capybara.page, true, filename_prefix)
saver.save
saver.output_screenshot_path
end
end
end
Expand Down

0 comments on commit 4247c42

Please sign in to comment.