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

Class Method Details

.check_failure_threshold(test_file_name) ⇒ 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



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/report/report.rb', line 97

def self.check_failure_threshold(test_file_name)
  consecutive_fail_threshold = 5
  if @current_test_fail
    @consecutive_test_fail += 1
  else
    @consecutive_test_fail = 0
  end

  return if @consecutive_test_fail < consecutive_fail_threshold

  # write info to stdout
  MyLog.log.warn "Terminating the current test file: #{test_file_name} as" \
    " the test failure threshold (#{@consecutive_test_fail}) has been" \
    ' reached.'
  MyLog.log.warn '...continuing with the next test file (if there is one)'

  raise FailureThresholdExceeded,
        "test failure threshold (#{@consecutive_test_fail}) has been reached"
end

.current_timeObject

get the current time in the format Day - Month - Date - Time (HH:MM:SS)



14
15
16
# File 'lib/report/report.rb', line 14

def self.current_time
  Time.new.strftime('%a %b %d %H:%M:%S %Z')
end

print the test Step info to the test results file



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/report/report.rb', line 19

def self.print_test_step_header(test_file_name, test_step_idx, test_desc)
  @test_start_time = current_time
  MyLog.log.info "Test step: #{test_step_idx} : #{test_desc}"

  step = {
    'id' => test_step_idx,
    'classname' => "SuiteID: #{JsonParser.test_id}" \
    " Test Step: #{test_step_idx} #{test_desc}",
    'name' => test_desc,
    '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][test_step_idx] = step
end

.test_pass_fail(pass_fail, test_file_name, test_step_idx, metrics) ⇒ Object

print the Pass / Fail status of a test to the test results file



41
42
43
44
45
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
88
89
90
91
92
# File 'lib/report/report.rb', line 41

def self.test_pass_fail(pass_fail, test_file_name, test_step_idx, metrics)
  if pass_fail == true
    @current_test_fail = false
    metrics.stepPasses += 1
    MyLog.log.info "Test #{test_step_idx} has Passed ".green
  elsif pass_fail == false
    @current_test_fail = true
    metrics.stepFailures += 1
    MyLog.log.info "Test #{test_step_idx} has FAILED ".red
    sc_file_name = Screenshot.save_screenshot(test_step_idx)
    failstep = {
      'message' => "SuiteID: #{JsonParser.test_id}" \
      " Test Step: #{test_step_idx} Test has" \
       " FAILED - Check logs, see Screenshot: #{sc_file_name}",
      '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][test_step_idx] = failstep
  else
    @current_test_fail = false
    metrics.stepSkipped += 1
    MyLog.log.info "Test #{test_step_idx} no checks performed ".blue
    skipstep = {
      'message' => "SuiteID: #{JsonParser.test_id}" \
      " Test Step: #{test_step_idx} 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][test_step_idx] = skipstep
  end
  test_end_time = current_time

  test_duration = TimeDifference.between(
    test_end_time, @test_start_time
  ).humanize || 0
  MyLog.log.info "Test step duration: #{test_duration} \n"
end