Class: Selenium::RSpec::SeleniumTestReportFormatter

Inherits:
Spec::Runner::Formatter::HtmlFormatter
  • Object
show all
Defined in:
lib/selenium/rspec/reporting/selenium_test_report_formatter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, output) ⇒ SeleniumTestReportFormatter

Returns a new instance of SeleniumTestReportFormatter.



22
23
24
25
26
# File 'lib/selenium/rspec/reporting/selenium_test_report_formatter.rb', line 22

def initialize(options, output)
  super
  raise "Unexpected output type #{output.inspect}" unless output.kind_of?(String)
  @@file_path_strategy = Selenium::RSpec::Reporting::FilePathStrategy.new(output)
end

Class Method Details

.capture_system_state(selenium_driver, example) ⇒ Object

Should be called from config.after(:each) in spec helper



64
65
66
67
# File 'lib/selenium/rspec/reporting/selenium_test_report_formatter.rb', line 64

def self.capture_system_state(selenium_driver, example)
  system_capture = Selenium::RSpec::Reporting::SystemCapture.new(selenium_driver, example, file_path_strategy)
  system_capture.capture_system_state                      
end

.file_path_strategyObject



77
78
79
80
81
82
83
# File 'lib/selenium/rspec/reporting/selenium_test_report_formatter.rb', line 77

def self.file_path_strategy
  ### HACK ####
  # When running with DeepTest the class instance variable could not have been set
  # For now you must set the env variable before launching the tests. We need to revisit the way DeepTest
  # and RSpec reporting work for a proper fix.
  @@file_path_strategy ||= Selenium::RSpec::Reporting::FilePathStrategy.new(ENV["SELENIUM_TEST_REPORT_FILE"])
end

Instance Method Details

#example_failed(example, counter, failure) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/selenium/rspec/reporting/selenium_test_report_formatter.rb', line 49

def example_failed(example, counter, failure)        
  old_output = @output
  @output = StringIO.new
  super
  
  result = @output.string
  report = Selenium::RSpec::Reporting::HtmlReport.new(@@file_path_strategy)
  report.replace_placeholder_with_system_state_content(result, example)
  old_output.puts result
  old_output.flush
ensure
  @output = old_output
end

#example_pending(example_proxy, message, deprecated_pending_location = nil) ⇒ Object



45
46
47
# File 'lib/selenium/rspec/reporting/selenium_test_report_formatter.rb', line 45

def example_pending(example_proxy, message, deprecated_pending_location=nil)
  super
end

#extra_failure_content(failure) ⇒ Object



41
42
43
# File 'lib/selenium/rspec/reporting/selenium_test_report_formatter.rb', line 41

def extra_failure_content(failure)
  Selenium::RSpec::Reporting::HtmlReport.inject_placeholder(super)
end

#global_scriptsObject



69
70
71
# File 'lib/selenium/rspec/reporting/selenium_test_report_formatter.rb', line 69

def global_scripts
  Selenium::RSpec::Reporting::HtmlReport.append_javascript(super)
end

#global_stylesObject



73
74
75
# File 'lib/selenium/rspec/reporting/selenium_test_report_formatter.rb', line 73

def global_styles
  Selenium::RSpec::Reporting::HtmlReport.append_css(super)
end

#move_progressObject



37
38
39
# File 'lib/selenium/rspec/reporting/selenium_test_report_formatter.rb', line 37

def move_progress
  # we don't have current_example_number, and we don't really care about the progress bar
end

#start(example_count) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/selenium/rspec/reporting/selenium_test_report_formatter.rb', line 28

def start(example_count)
  super
  # ensure there's at least 1 example group header (normally 0 with deep_test)
  # prevents js and html validity errors
  example_group = Object.new
  def example_group.description; ""; end
  example_group_started example_group
end