Module: XlsxParser

Defined in:
lib/parser/xlsx_parser.rb

Overview

Created on 02 Aug 2018 @author: Andy Perrett

Versions: 1.0 - Baseline

xlsx_parser.rb - xlsx parser functions

Class Method Summary collapse

Class Method Details

.parse_test_step_data(testFileType) ⇒ Object

parseTestStepData



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

def self.parse_test_step_data(testFileType)
    begin
    worksheet = $xlsxDoc[0]
    worksheet[7..$numberOfTestSteps+7].map do |row|
      test = {
        testStep: row[0].value,
        testdesc: row[1].value,
        testFunction: row[2].value,
        testvalue: row[3].value,
        locate: row[4].value,
        testvalue2: row[5].value,
        locate2: row[6].value,
        screenShotData: row[7].value,
        skipTestCase: row[8].value,
      }

      # convert test step, screenshot and skip test case functions to lowercase.
      test[:testFunction].downcase!

      # get screenshot request, check for a null value and default to 'N'

      if (test[:screenShotData] == 'Y')
        test[:screenShotData] = true
      elsif (test[:screenShotData] == 'N')
        test[:screenShotData] = false
      else
        test[:screenShotData] = false
      end

      if (test[:skipTestCase] == 'Y')
        test[:skipTestCase] = true
      elsif(test[:skipTestCase] == 'N')
        test[:skipTestCase] = false
      else
        test[:skipTestCase] = false
      end

      # if there is an element locator then use it, otherwise use an ID
      if (test[:locate].to_s == '')
        test[:locate] = 'id'
      end

      if (test[:locate2].to_s == '')
        test[:locate2] = 'id'
      end

      test
     # if an error reading the test step data then re-raise the exception
    rescue StandardError => error
      raise
    end
  end
end

.parse_xlxs_test_header_dataObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/parser/xlsx_parser.rb', line 49

def self.parse_xlxs_test_header_data
  # get the number of test steps in the file
  $numberOfTestSteps = ($xlsxDoc[0].sheet_data.size) - 7
  worksheet = $xlsxDoc[0]
  # get the remaining test data
  $testDes      = worksheet.sheet_data[4][1].value
  MyLog.log.info "Number of test steps: #{$numberOfTestSteps}"
  MyLog.log.info "Test Description: #{$testDes}"
  
end

.parse_xlxs_test_suite_data(testSpecIndex) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/parser/xlsx_parser.rb', line 27

def self.parse_xlxs_test_suite_data(testSpecIndex)
  worksheet = $XlsxSuiteDoc[0]

  worksheet[7..$numberOfTestSpecs+7].map do |row|
    suite = {
      id: row[0].value,
      specdesc: row[1].value,
      env: row[3].value,
    }

    if ARGV.length < 2
      suite[:browser] = row[2].value
    elsif ARGV.length < 3
      suite[:browser] = ARGV[1]
    else
      raise IOError, 'Unable to open browser'  
    end

    suite
  end
end

.parse_xlxs_test_suite_header_dataObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/parser/xlsx_parser.rb', line 10

def self.parse_xlxs_test_suite_header_data
   begin
     # get the number of test specifications in the file (number of
     # occurences of "Test_Specification"
     $numberOfTestSpecs = $XlsxSuiteDoc[0].sheet_data.size - 7

     worksheet = $XlsxSuiteDoc[0]
     $projectName = worksheet.sheet_data[1][0].value
     $projectId = worksheet.sheet_data[1][1].value
     $sprint = worksheet.sheet_data[1][2].value

     $testSuiteId = worksheet.sheet_data[4][0].value
     $testSuiteDes = worksheet.sheet_data[4][1].value
     $tester  = worksheet.sheet_data[4][2].value
   end
end