Class: Watir::RSpec::HtmlFormatter

Inherits:
RSpec::Core::Formatters::HtmlFormatter
  • Object
show all
Defined in:
lib/watir/rspec/html_formatter.rb

Overview

Custom RSpec formatter

  • saves screenshot of the browser upon test failure

  • saves html of the browser upon test failure

  • saves all files generated/downloaded during the test and shows them in the report

Instance Method Summary collapse

Instance Method Details

#file_path(file_name, description = nil) ⇒ String

Generate unique file path for the current spec. If the file will be created during that spec and spec fails then it will be shown automatically in the html report.

Parameters:

  • file_name (String)

    File name to be used for file. Will be used as a part of the complete name.

Returns:

  • (String)

    Absolute path for the unique file name.



61
62
63
64
65
66
67
# File 'lib/watir/rspec/html_formatter.rb', line 61

def file_path(file_name, description=nil)
  extension = File.extname(file_name)
  basename = File.basename(file_name, extension)
  file_path = File.join(@files_dir, "#{basename}_#{::Time.now.strftime("%H%M%S")}_#{example_group_number}_#{example_number}#{extension}")
  @files_saved_during_example.unshift(:desc => description, :path => file_path)
  file_path
end