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 outputting console.
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.
-
.current_time ⇒ Object
get the current time in the format Day - Month - Date - Time (HH:MM:SS).
-
.print_test_step_header(test_file_name, testStepIndex) ⇒ Object
print the test Step info to the test results file.
-
.results ⇒ Object
setup the test results output file 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
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/report/report.rb', line 91 def self.check_failure_threshold(test_file_name, testStepIndex) consecutiveFailThreshold = 5 if $previousTestFail && $currentTestFail @consecutiveTestFail += 1 else @consecutiveTestFail = 0 end if @consecutiveTestFail >= consecutiveFailThreshold # write info to stdout MyLog.log.warn "Terminating the current test case: #{test_file_name} as the test failure threshold (#{consecutiveFailThreshold}) has been reached." MyLog.log.warn '...continuing with the next test case (if there is one)' raise FailureThresholdExceeded, "#{consecutiveFailThreshold} Test Steps Failed." end end |
.current_time ⇒ Object
get the current time in the format Day - Month - Date - Time (HH:MM:SS)
19 20 21 22 23 |
# File 'lib/report/report.rb', line 19 def self.current_time time = Time.new f_time = time.strftime('%a %b %d %H:%M:%S %Z') f_time end |
.print_test_step_header(test_file_name, testStepIndex) ⇒ Object
print the test Step info to the test results file
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/report/report.rb', line 26 def self.print_test_step_header(test_file_name, testStepIndex) MyLog.log.info "Test start time: #{f_time = current_time}" MyLog.log.info "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
setup the test results output file results file variable
14 15 16 |
# File 'lib/report/report.rb', line 14 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/report/report.rb', line 46 def self.test_pass_fail(passFail, test_file_name, testStepIndex) if passFail == true $previousTestFail = $currentTestFail $currentTestFail = false $testStepPasses += 1 MyLog.log.info "Test #{$testStep} has Passed ".green elsif passFail == false $previousTestFail = $currentTestFail $currentTestFail = true $testStepFailures += 1 MyLog.log.info "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 MyLog.log.info "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 MyLog.log.info "Test end time: #{f_time = current_time}" end |