Module: Report
- Defined in:
- lib/report/report.rb
Overview
Created on 20 Sept 2017 @author: Andy Perrett
Versions: 1.0 - Baseline
report.rb - methods for accessing and writing to the test report file(s)
Class Method Summary collapse
-
.check_failure_threshold(test_file_name, testStepIndex) ⇒ Object
check if the test failure threshold has been reached for total failures or consecutive failures.
- .close_log_file ⇒ Object
-
.close_test_results_file ⇒ Object
close_testresults_file.
-
.current_time ⇒ Object
get the current time in the format Day - Month - Date - Time (HH:MM:SS).
- .open_log_file ⇒ Object
-
.open_test_report_file ⇒ Object
setup the test results output file.
-
.print_test_header ⇒ Object
print the main test header info to the test results file.
-
.print_test_step_header(test_file_name, testStepIndex) ⇒ Object
print the test Step info to the test results file.
-
.results ⇒ Object
results file variable.
-
.test_pass_fail(passFail, test_file_name, testStepIndex) ⇒ Object
print the Pass / Fail status of a test to the test results file.
Class Method Details
.check_failure_threshold(test_file_name, testStepIndex) ⇒ Object
check if the test failure threshold has been reached for total failures or consecutive failures. If a certain number of consecutive tests fail then throw an exception
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/report/report.rb', line 136 def self.check_failure_threshold(test_file_name, testStepIndex) consecutiveFailThreshold = 5 if $previousTestFail && $currentTestFail @consecutiveTestFail += 1 else @consecutiveTestFail = 0 end if @consecutiveTestFail >= consecutiveFailThreshold Report.results.puts("\nTerminating the current test case as the test failure threshold (#{consecutiveFailThreshold} ) has been reached") # write info to $stderr $stderr.puts "Terminating the current test case: #{test_file_name} as the test failure threshold (#{consecutiveFailThreshold}) has been reached." $stderr.puts '...continuing with the next test case (if there is one)' raise FailureThresholdExceeded, "#{consecutiveFailThreshold} Test Steps Failed." end end |
.close_log_file ⇒ Object
43 44 45 46 |
# File 'lib/report/report.rb', line 43 def self.close_log_file # if the file is open then close it $log.close unless $log.closed? end |
.close_test_results_file ⇒ Object
close_testresults_file
25 26 27 28 |
# File 'lib/report/report.rb', line 25 def self.close_test_results_file # if the file is open then close it Report.results.close unless Report.results.closed? end |
.current_time ⇒ Object
get the current time in the format Day - Month - Date - Time (HH:MM:SS)
58 59 60 61 62 |
# File 'lib/report/report.rb', line 58 def self.current_time time = Time.new f_time = time.strftime('%a %b %d %H:%M:%S %Z') f_time end |
.open_log_file ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/report/report.rb', line 35 def self.open_log_file # open a new file for writing $stdout.puts "Opening log file: #{$logFileName} \n" # create a new log file and set the mode as 'append' $log = File.open($logFileName, 'w+') end |
.open_test_report_file ⇒ Object
setup the test results output file
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/report/report.rb', line 13 def self.open_test_report_file # open a new file for writing $log.puts("Opening Test Result file: #{$testResultFileName} \n") # open test results file for writing if not already open if !File.exist?($testResultFileName) || $testResultFileName.closed? @results_file = File.open($testResultFileName, 'w') elsif $log.puts "test results file name: #{$testResultFileName} is already open" end end |
.print_test_header ⇒ Object
print the main test header info to the test results file
49 50 51 52 53 54 55 |
# File 'lib/report/report.rb', line 49 def self.print_test_header Report.results.puts("Project Name: #{$projectName} Project ID: #{$projectId} Sprint: #{$sprint}") Report.results.puts("Test ID: #{$testId} Test Description: #{$testDes}") Report.results.puts("Executed with browser: #{$browserType}") Report.results.puts("Test suite: #{$testSuiteFile}") Report.results.puts("Tester: #{$tester}", "\n \n") end |
.print_test_step_header(test_file_name, testStepIndex) ⇒ Object
print the test Step info to the test results file
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/report/report.rb', line 65 def self.print_test_step_header(test_file_name, testStepIndex) Report.results.puts("\n" + "Test start time: #{f_time = current_time}") Report.results.puts("Test step: #{$testStep} : #{$testStepDes} \n") puts "\nTest start time: #{f_time = current_time} \n" puts "Test step: #{$testStep} : #{$testStepDes} " step = { 'id' => $testStep, 'classname' => 'SuiteID: ' + $testId.to_s + ' Test Step: ' + $testStep.to_s + ' ' + $testStepDes.to_s, 'name' => $testStepDes, 'file' => test_file_name } # output to console to show test step # puts step return unless test_file_name $testStep_xml ||= {} $testStep_xml[test_file_name] ||= {} $testStep_xml[test_file_name][testStepIndex] = step end |
.results ⇒ Object
results file variable
31 32 33 |
# File 'lib/report/report.rb', line 31 def self.results results_file = @results_file end |
.test_pass_fail(passFail, test_file_name, testStepIndex) ⇒ Object
print the Pass / Fail status of a test to the test results file
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/report/report.rb', line 87 def self.test_pass_fail(passFail, test_file_name, testStepIndex) if passFail == true $previousTestFail = $currentTestFail $currentTestFail = false $testStepPasses += 1 Report.results.puts("Test #{$testStep} has Passed") puts "Test #{$testStep} has Passed ".green elsif passFail == false $previousTestFail = $currentTestFail $currentTestFail = true $testStepFailures += 1 Report.results.puts("Test #{$testStep} has FAILED") puts "Test #{$testStep} has FAILED ".red failstep = { 'message' => 'SuiteID: ' + $testId.to_s + ' Test Step: ' + $testStep.to_s + ' Test has FAILED - Check logs', 'type' => 'FAILURE', 'file' => test_file_name } # output to console to show test step failure # puts failstep return unless test_file_name $failtestStep_xml ||= {} $failtestStep_xml[test_file_name] ||= [] $failtestStep_xml[test_file_name][testStepIndex] = failstep else $currentTestFail = false $testStepNotrun += 1 Report.results.puts("Test #{$testStep} no checks performed") puts "Test #{$testStep} no checks performed ".blue skipstep = { 'message' => 'SuiteID: ' + $testId.to_s + ' Test Step: ' + $testStep.to_s + ' No checks performed - Check logs', 'type' => 'SKIPPED', 'file' => test_file_name } # output to console to show test step failure # puts skipstep return unless test_file_name $skiptestStep_xml ||= {} $skiptestStep_xml[test_file_name] ||= [] $skiptestStep_xml[test_file_name][testStepIndex] = skipstep end Report.results.puts("Test end time: #{f_time = current_time}\n") puts "Test end time: #{f_time = current_time} \n" end |