2

I'm using the Headless gem to create a headless session using xvfb and to record the session using ffmpeg. I'm not able to save the video created by the headless gem. I'm including the relevant snippets of my code and the output.

Code
$LOGGER.info("----------Starting test: #{@test_name}----------")

if Utilities.linux? && ENV['DRIVER'] != 'sauce'
  @headless = Headless.new ({dimension: '1600x1200x16',
                    pid_file_path: "#{Utilities.get_root_directory}/tmp/headless_ffmpeg_#{@display}.pid",
                    tmp_file_path: "#{Utilities.get_root_directory}/tmp/headless_ffmpeg_#{@display}.mov",
                    log_file_path: "#{Utilities.get_root_directory}/tmp/headless_ffmpeg_#{@display}.txt"})
  @headless.start
  @headless.video.start_capture
  $LOGGER.info 'Creating headless session.'
end
$browser = DefaultWatir.initiate_browser(@test_name)

if Utilities.linux? && ENV['DRIVER'] != 'sauce'
  $LOGGER.info "Starting video recording"
  @headless.video.start_capture
end

.........          .........
......... TEST RUN .........
.........          .........

$LOGGER.info "----------Ending test: #{@test_name}----------"
 puts "\n\n"

$browser.close if $browser
save_video if @headless

def video_path
  return "#{Utilities.get_root_directory}/video/#{@test_name}_#{Time.now.to_s.gsub(' ', '-')}"
end

def save_video
  if Utilities.linux?  && ENV['DRIVER'] != 'sauce'
    unless self.instance_variable_get(:@exception).nil? && !$has_errors
      saved_video_path = video_path
      Dir.mkdir("#{Utilities.get_root_directory}/video") unless Dir.exists?("#{Utilities.get_root_directory}/video")
      $LOGGER.info "Video path = #{saved_video_path}"
      begin
        $LOGGER.info 'before save'
        @headless.video.stop_and_save(saved_video_path)
        $LOGGER.info 'after save'
      rescue ex
        $LOGGER.info 'Video save had exception.'
        puts ex.message
        puts ex.backtrace.join("\n\t")
      end
      $LOGGER.info "Video saved at: #{saved_video_path}"
    else
      @headless.video.stop_and_discard
    end
    @headless.destroy
  end
end
Output

[INFO - 2015-03-06 21:58:37 +0000] - ----------Starting test: Example Test----------

[INFO - 2015-03-06 21:58:37 +0000] - Creating headless session.

[INFO - 2015-03-06 21:58:40 +0000] - Starting video recording

[INFO - 2015-03-06 22:02:04 +0000] - ----------Ending test: Example Test----------

INFO - 2015-03-06 22:02:05 +0000] - Video path = /var/lib/jenkins/workspace/end_to_end_firefox/selenium-tests/video/PoolPlayToSingleEliminationOneDivision_2015-03-06-22:02:05-+0000

[INFO - 2015-03-06 22:02:05 +0000] - before save

[INFO - 2015-03-06 22:02:05 +0000] - after save

[INFO - 2015-03-06 22:02:05 +0000] - Video saved at: /var/lib/jenkins/workspace/end_to_end_firefox/selenium-tests/video/PoolPlayToSingleEliminationOneDivision_2015-03-06-22:02:05-+0000

Community
  • 1
  • 1
TIMBERings
  • 688
  • 1
  • 8
  • 28
  • You say you are not able to save the video, but the output indicates otherwise. Are you unable to *view* the video? Does the file get created? – javabrett May 12 '15 at 01:01
  • That's logging that I created. The file didn't actually save. This has unfortunately been long abandoned. – TIMBERings May 12 '15 at 18:08

0 Answers0