Module: TestEngine

Defined in:
lib/utils/test_engine.rb

Overview

Created on 20 Sept 2017 @author: Andy Perrett

Versions: 1.0 - Baseline

test_engine.rb - controls the iteration through the test suite and specs

Class Method Summary collapse

Class Method Details

.process_testfilesObject

process the test files to execute the tests



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
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
# File 'lib/utils/test_engine.rb', line 14

def self.process_testfiles
  test_file_name = ''

  # initialise the index for reading the list of test file names
  test_file_name_index = 0

  # get the overall test start time
  $test_start_time = Report.current_time

  # create project folders - these only need creating once per test suite
  CreateDirectories.construct_projectdirs

  # loop through all the available test files to execute the tests
  while test_file_name_index < $numberOfTestSpecs
    # get the next test spec data from the test suite doc
    test_suites = Parser.parse_test_suite_data(test_file_name_index)

    test_suites.each do |test_suite|
      $testId = test_suite[:id]
      $testSpecDesc = test_suite[:specdesc]
      $env_type = test_suite[:env]
      $browserType = test_suite[:browser]

      if ARGV.length < 2
        $browserType = test_suite[:browser]
        MyLog.log.info "Will use the following browser from Test Suite: #{$browserType}"
      elsif ARGV.length < 3
        $browserType = ARGV[1]
        MyLog.log.info "Will use the following browser from CMD line: " + ARGV[1]
      else
        raise IOError, 'Unable to open browser'  
      end

      # remove any unwanted end-of-line characters from the file name
      test_file_name = $testSpecDesc

      begin # start of rescue block for readTestData
        # read in the test data
        testFileType = Parser.read_test_data(test_file_name)
        # if unable to read the test data, show the error and move onto the
        # next file (if there is one)
      rescue StandardError => error
        MyLog.log.warn "Terminating the current test case: " \
                     "#{test_file_name} #{error}"
        MyLog.log.info '...continuing with the next test case (if there is one)'
      end # of rescue block for readTestData

      # create the project directories, returns the screenshot directory name
      begin # start of rescue block for construct_projectdirs
        # create test spec directories - these need creating once per testspec
        full_sc_dirname = CreateDirectories.construct_testspecdirs
        # if an error then show the error and terminate
      rescue StandardError => error
        warn error
        MyLog.log.warn error
        abort
      end

      # loop through the test file
      if testFileType != 'XLSX'
        MyLog.log.info 'Not a valid XLSX File Type'
      end

      # get the test case start time
      $test_case_start_time = Report.current_time
      # initialise the test end time
      $test_case_end_time = Report.current_time

      begin
        test_steps = Parser.parse_test_step_data(testFileType)

        test_steps.each_with_index do |test_step, index|
          $testStep         = test_step[:testStep]
          $testStepDes      = test_step[:testdesc]
          screen_shot       = test_step[:screenShotData]

          # process the test step data
          TestSteps.process_test_steps(test_file_name, index, test_step)
          # see if screenshot required
          Browser.check_save_screenshot(full_sc_dirname, screen_shot)
        end
      rescue TafError => error
        warn error
        MyLog.log.warn error
      end

      # get the test case end time
      $test_case_end_time = Report.current_time

      # output the test results summary for the current test case,
      # pass in the test file number to save the summary against it's testfile
      ReportSummary.test_step_summary(test_file_name, test_file_name_index)
      JunitReport.test_step_summary_xml(test_file_name, test_file_name_index)

      # close the browser if created
      Browser.b.quit

      # increment loop counter to move onto next test file
      test_file_name_index += 1

      # record total passes and failures and reset the failure counters for
      # the test steps
      $totalTestPasses   += $testStepPasses
      $totalTestFailures += $testStepFailures
      $totalTestNotrun   += $testStepNotrun
      $testStepPasses   = 0
      $testStepFailures = 0
      $testStepNotrun   = 0
    end
  end # while loop for test files
end