Module: Parser

Defined in:
lib/parser/parser.rb

Overview

Created on 02 Aug 2018 @author: Andy Perrett

Versions: 1.0 - Baseline

parser.rb - basic parser functions

Class Method Summary collapse

Class Method Details

.parse_test_step_data(testFileType) ⇒ Object

parseTestStepData



83
84
85
# File 'lib/parser/parser.rb', line 83

def self.parse_test_step_data(testFileType)
  XlsxParser.parse_test_step_data(testFileType)
end

.parse_test_suite_data(testSpecIndex) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/parser/parser.rb', line 41

def self.parse_test_suite_data(testSpecIndex)
  begin
    # get the file type
    fileType = File.extname($testSuiteFile)

    if (fileType.casecmp(@XlsxFileNameType) == 0)
      XlsxParser.parse_xlxs_test_suite_data(testSpecIndex)
    else
      # the file type is not that expected so create a
      # error message and raise an exception
      error_to_display = "Test Suite file: '#{$testSuiteFile}' "\
                         "type not recognised (must be .xlsx)"
      raise IOError, error_to_display
    end
  end
end

.read_test_data(testFileName) ⇒ Object

readTestData



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/parser/parser.rb', line 59

def self.read_test_data(testFileName)
  # get the file type
  fileType = File.extname(testFileName)
  if (fileType.casecmp(@XlsxFileNameType) == 0)
    MyLog.log.info "Processing test file: #{testFileName}"
    MyLog.log.info "Browser Type: #{$browserType}"
    $xlsxDoc = RubyXL::Parser.parse(testFileName)
    XlsxParser.parse_xlxs_test_header_data
    return 'XLSX'
  else
    # if unable to read the test file list then construct a custom error
    # message and raise an exception.
    error_to_display = "Test File Name: '#{testFileName}' " \
                       "type not recognised (must be .xslx)"
    raise IOError, error_to_display
  end

  # if an error occurred reading the test file list then
  # re-raise the exception.
rescue StandardError => error
  raise IOError, error
end

.read_test_suite_dataObject

read in the data from the test suite file



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
# File 'lib/parser/parser.rb', line 14

def self.read_test_suite_data
  # check if the file list exists and is readable
  if (File.file?($testSuiteFile) & File.readable?($testSuiteFile))
    MyLog.log.info "Processing test suite file: #{$testSuiteFile}"
    # get the file type
    fileType = File.extname($testSuiteFile)
    # extract the test data from the test suite
    if (fileType.casecmp(@XlsxFileNameType) == 0)
      # process as xlsx...
      $XlsxSuiteDoc = RubyXL::Parser.parse($testSuiteFile)
      # ...and parse...
      XlsxParser.parse_xlxs_test_suite_header_data
    else
      # the file type is not that expected so create
      # a error message and raise an exception
      error_to_display = "Test Suite file: '#{$testSuiteFile}' "\
                         "type not recognised (must be .xlsx)"
      raise IOError, error_to_display
    end
      # if unable to read the test file list then construct
      # a custom error message and raise an exception
  elsif error_to_display = "Test Suite file: '#{$testSuiteFile}' "\
                           "does not exist or is unreadable"
      raise IOError, error_to_display
  end
end