Permalink
Browse files

Merge remote branch 'gshakhn/master'

  • Loading branch information...
2 parents 8f85d2b + 9aa08c0 commit 5942e4acc452ad4028ea12492e3167a2e23dab7d @antifun antifun committed Feb 15, 2012
View
2 Gemfile
@@ -1,4 +1,4 @@
source "http://rubygems.org"
gem "rspec", "> 2"
gem "selenium-webdriver"
-
+gem "headless"
View
8 lib/rspec/reporting/file_path_strategy.rb
@@ -35,6 +35,10 @@ def relative_file_path_for_page_screenshot(example)
"#{relative_dir}/example_#{example.reporting_uid}_page_screenshot.png"
end
+ def relative_file_path_for_video(example)
+ "#{relative_dir}/example_#{example.reporting_uid}_video.webm"
+ end
+
def relative_file_path_for_remote_control_logs(example)
"#{relative_dir}/example_#{example.reporting_uid}_remote_control.log"
end
@@ -55,6 +59,10 @@ def file_path_for_page_screenshot(example)
file_path relative_file_path_for_page_screenshot(example)
end
+ def file_path_for_video(example)
+ file_path relative_file_path_for_video(example)
+ end
+
def file_path_for_remote_control_logs(example)
file_path relative_file_path_for_remote_control_logs(example)
end
View
19 lib/rspec/reporting/html_report.rb
@@ -22,6 +22,7 @@ def logs_and_screenshot_sections(example)
dom_id = "example_" + example.reporting_uid
system_screenshot_url = @file_path_strategy.relative_file_path_for_system_screenshot(example)
page_screenshot_url = @file_path_strategy.relative_file_path_for_page_screenshot(example)
+ video_url = @file_path_strategy.relative_file_path_for_video(example)
snapshot_url = @file_path_strategy.relative_file_path_for_html_capture(example)
remote_control_logs_url = @file_path_strategy.relative_file_path_for_remote_control_logs(example)
@@ -38,6 +39,9 @@ def logs_and_screenshot_sections(example)
if File.exists? @file_path_strategy.file_path_for_system_screenshot(example)
html << toggable_image_section(dom_id, :id => "system_screenshot", :name => "System Screenshot", :url => system_screenshot_url)
end
+ if File.exists? @file_path_strategy.file_path_for_video(example)
+ html << toggable_video_section(dom_id, :id => "video", :name => "Video", :url => video_url)
+ end
return html
end
@@ -111,6 +115,21 @@ def toggable_image_section(dom_id, options)
EOS
end
+
+ def toggable_video_section(dom_id, options)
+ <<-EOS
+
+ <div>[<a id="#{dom_id}_#{options[:id]}_link" href="javascript:toggleVisilibility('#{dom_id}_#{options[:id]}', '#{options[:name]}');">Show #{options[:name]}</a>]</div>
+ <br/>
+ <div id="#{dom_id}_#{options[:id]}" style="display: none">
+ <video src="#{options[:url]}" controls>
+ Your browser does not support the <code>video</code> element.
+ </video>
+ </div>
+ <br/>
+
+ EOS
+ end
def report_header
super + "\n<script type=\"text/javascript\">moveProgressBar('100.0');</script>"
View
4 lib/rspec/reporting/selenium_test_report_formatter.rb
@@ -57,8 +57,8 @@ def example_failed(example)
end
# Should be called from config.after(:each) in spec helper
- def self.capture_system_state(selenium_driver, example)
- system_capture = Selenium::RSpec::Reporting::SystemCapture.new(selenium_driver, example, file_path_strategy)
+ def self.capture_system_state(selenium_driver, headless, example)
+ system_capture = Selenium::RSpec::Reporting::SystemCapture.new(selenium_driver, headless, example, file_path_strategy)
system_capture.capture_system_state
end
View
12 lib/rspec/reporting/system_capture.rb
@@ -4,8 +4,9 @@ module Reporting
class SystemCapture
- def initialize(selenium_driver, example, file_path_strategy)
+ def initialize(selenium_driver, headless, example, file_path_strategy)
@webdriver = selenium_driver
+ @headless = headless
@example = example
@file_path_strategy = file_path_strategy
end
@@ -21,6 +22,11 @@ def capture_system_state
rescue Exception => e
STDERR.puts "WARNING: Could not capture page screenshot: #{e}"
end
+ begin
+ capture_video
+ rescue Exception => e
+ STDERR.puts "WARNING: Could not capture video: #{e}"
+ end
end
def capture_html_snapshot
@@ -32,6 +38,10 @@ def capture_page_screenshot
@webdriver.save_screenshot(@file_path_strategy.file_path_for_page_screenshot(@example))
end
+ def capture_video
+ @headless.video.stop_and_save(@file_path_strategy.file_path_for_video(@example))
+ end
+
end
end
View
9 lib/rspec/spec_helper.rb
@@ -2,14 +2,21 @@
require 'rspec/core'
require 'base64'
require 'fileutils'
+require 'headless'
require File.expand_path(File.dirname(__FILE__) + "/rspec_extensions")
require File.expand_path(File.dirname(__FILE__) + "/reporting/selenium_test_report_formatter")
RSpec.configure do |config|
+ config.before(:each) do
+ @headless.video.start_capture
+ end
+
config.after(:each) do
if actual_failure?
- SeleniumTestReportFormatter.capture_system_state(@driver, self.example)
+ SeleniumTestReportFormatter.capture_system_state(@driver, @headless, self.example)
+ else
+ @headless.video.stop_and_discard
end
end

0 comments on commit 5942e4a

Please sign in to comment.