taf 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8fce262beb8801e713c9bf2bba991657eed3e3660d5098b3905d27c16abbb2c9
4
- data.tar.gz: 9a98b39402e830e014216b8701082c89955556c90af42793ef7f797981c917c4
3
+ metadata.gz: c5a4ea4d70ac8bd18bd9e90fa0b0b1615e036669df29d789105cec6aa5d74e09
4
+ data.tar.gz: 4d62ee8db6590f1ed95be8dbabdb2db2e220d9e5f5bad68d73b1266eb8cf084b
5
5
  SHA512:
6
- metadata.gz: b93e27555e02b0478cbc0615a66812fe9c1621ccbebb0fbd452493fd5831b3d0ecf41af72275dffd39955eac8c06daae3b97a07d6eb9966e4c07faf7737df460
7
- data.tar.gz: cdbe883d6dbb0ab8bf43c273eb36ae2814eff4955ad351a04e5ab2224a3157f7ad54f1ac622fd9e01fac91140239f205866f2e7c2687f0f459e2016808b88e7c
6
+ metadata.gz: e7f1b953e22f15a8152110c5621c824535efb13e0921c6961a07e90cb1f3165a0ead74a87ccf8502c0c086a4c7899c74c55a4934cf2952d271f2045df28647d0
7
+ data.tar.gz: dddad76d0929978d394fa1e8639288b84ecf445fa4d79a03e81d34b7a1168445c08dbbdb82f2ab71168ca3324ff4702b5db2b0c3a9104e5aa88c37b9e8ce3d56
data/lib/main.rb CHANGED
@@ -28,25 +28,20 @@ module Main
28
28
 
29
29
  begin
30
30
  # check if the test suite file name exists on the command line
31
- # allow a user to input 1 or 2 arguments in to CMD line the 2 values are:
32
- # Testsuite File and Browser.
33
- if ARGV.length < 2
34
- $testSuiteFile = ARGV[0]
35
- MyLog.log.info 'Only one argument needed: {TestSuite File}'
36
- elsif ARGV.length < 3
37
- $testSuiteFile = ARGV[0]
31
+ # allow a user to input 2 arguments in to CMD line the 2 values are:
32
+ # Testcase Folder and Browser.
33
+ if ARGV.length < 3
34
+ $testcasesFolder = ARGV[0]
38
35
  $browserType = ARGV[1]
39
- MyLog.log.info 'Only 2 arguments needed: {TestSuite File} {Browser}'
36
+ MyLog.log.info '2 arguments are required: {Testcase folder} {Browser}'
40
37
  else
41
38
  # unable to open file as not supplied as command-line parameter
42
- $testSuiteFile = 'unknown'
43
- error_to_display = 'Test File has not been supplied as a command-line parameter as expected'
39
+ $testcasesFolder = 'unknown'
40
+ error_to_display = 'Test case location has not been supplied as a command-line parameter as expected'
41
+ $browserType = 'unknown'
42
+ error_to_display = 'Browser has not been supplied as a command-line parameter as expected'
44
43
  raise IOError, error_to_display
45
44
  end
46
-
47
- # Get the test suite data
48
- Parser.read_test_suite_data
49
-
50
45
  # unable to read the test file then handle the error and terminate
51
46
  rescue StandardError => error
52
47
  warn error
@@ -54,7 +49,7 @@ module Main
54
49
  abort
55
50
  end
56
51
 
57
- MyLog.log.info "There are: #{$numberOfTestSpecs} test files to process \n"
52
+ MyLog.log.info "There are: #{Parser.test_files.size} test files to process \n"
58
53
 
59
54
  # process the test files to execute the tests
60
55
  TestEngine.process_testfiles
data/lib/parser/parser.rb CHANGED
@@ -10,49 +10,10 @@ module Parser
10
10
  # variables:
11
11
  @XlsxFileNameType = '.xlsx'
12
12
 
13
- # read in the data from the test suite file
14
- def self.read_test_suite_data
15
- # check if the file list exists and is readable
16
- if (File.file?($testSuiteFile) & File.readable?($testSuiteFile))
17
- MyLog.log.info "Processing test suite file: #{$testSuiteFile}"
18
- # get the file type
19
- fileType = File.extname($testSuiteFile)
20
- # extract the test data from the test suite
21
- if (fileType.casecmp(@XlsxFileNameType) == 0)
22
- # process as xlsx...
23
- $XlsxSuiteDoc = RubyXL::Parser.parse($testSuiteFile)
24
- # ...and parse...
25
- XlsxParser.parse_xlxs_test_suite_header_data
26
- else
27
- # the file type is not that expected so create
28
- # a error message and raise an exception
29
- error_to_display = "Test Suite file: '#{$testSuiteFile}' "\
30
- "type not recognised (must be .xlsx)"
31
- raise IOError, error_to_display
32
- end
33
- # if unable to read the test file list then construct
34
- # a custom error message and raise an exception
35
- elsif error_to_display = "Test Suite file: '#{$testSuiteFile}' "\
36
- "does not exist or is unreadable"
37
- raise IOError, error_to_display
38
- end
39
- end
40
-
41
- def self.parse_test_suite_data(testSpecIndex)
42
- begin
43
- # get the file type
44
- fileType = File.extname($testSuiteFile)
45
-
46
- if (fileType.casecmp(@XlsxFileNameType) == 0)
47
- XlsxParser.parse_xlxs_test_suite_data(testSpecIndex)
48
- else
49
- # the file type is not that expected so create a
50
- # error message and raise an exception
51
- error_to_display = "Test Suite file: '#{$testSuiteFile}' "\
52
- "type not recognised (must be .xlsx)"
53
- raise IOError, error_to_display
54
- end
55
- end
13
+ def self.test_files
14
+ @test_files ||= Dir.glob("#{$testcasesFolder}/*.xlsx").reject do |file|
15
+ File.basename(file).start_with?('~$')
16
+ end.sort
56
17
  end
57
18
 
58
19
  # readTestData
@@ -7,53 +7,18 @@
7
7
  # xlsx_parser.rb - xlsx parser functions
8
8
  module XlsxParser
9
9
  require_relative '../taf_config.rb'
10
- def self.parse_xlxs_test_suite_header_data
11
- begin
12
- # get the number of test specifications in the file (number of
13
- # occurences of "Test_Specification"
14
- $numberOfTestSpecs = $XlsxSuiteDoc[0].sheet_data.size - 7
15
-
16
- worksheet = $XlsxSuiteDoc[0]
17
- $projectName = worksheet.sheet_data[1][0].value
18
- $projectId = worksheet.sheet_data[1][1].value
19
- $sprint = worksheet.sheet_data[1][2].value
20
-
21
- $testSuiteId = worksheet.sheet_data[4][0].value
22
- $testSuiteDes = worksheet.sheet_data[4][1].value
23
- $tester = worksheet.sheet_data[4][2].value
24
- end
25
- end
26
-
27
- def self.parse_xlxs_test_suite_data(testSpecIndex)
28
- worksheet = $XlsxSuiteDoc[0]
29
-
30
- worksheet[7..$numberOfTestSpecs+7].map do |row|
31
- suite = {
32
- id: row[0].value,
33
- specdesc: row[1].value,
34
- env: row[3].value,
35
- }
36
-
37
- if ARGV.length < 2
38
- suite[:browser] = row[2].value
39
- elsif ARGV.length < 3
40
- suite[:browser] = ARGV[1]
41
- else
42
- raise IOError, 'Unable to open browser'
43
- end
44
-
45
- suite
46
- end
47
- end
48
10
 
49
11
  def self.parse_xlxs_test_header_data
50
12
  # get the number of test steps in the file
51
- $numberOfTestSteps = ($xlsxDoc[0].sheet_data.size) - 7
13
+ $numberOfTestSteps = ($xlsxDoc[0].sheet_data.size) - 4
52
14
  worksheet = $xlsxDoc[0]
53
15
  # get the remaining test data
54
- $testDes = worksheet.sheet_data[4][1].value
16
+ $testId = worksheet.sheet_data[1][0].value
17
+ $projectId = worksheet.sheet_data[1][1].value
18
+ $testDes = worksheet.sheet_data[1][2].value
55
19
  MyLog.log.info "Number of test steps: #{$numberOfTestSteps}"
56
20
  MyLog.log.info "Test Description: #{$testDes}"
21
+ MyLog.log.info "TestID: #{$testId} \n"
57
22
 
58
23
  end
59
24
 
@@ -61,7 +26,7 @@ module XlsxParser
61
26
  def self.parse_test_step_data(testFileType)
62
27
  begin
63
28
  worksheet = $xlsxDoc[0]
64
- worksheet[7..$numberOfTestSteps+7].map do |row|
29
+ worksheet[4..$numberOfTestSteps+4].map do |row|
65
30
  test = {
66
31
  testStep: row[0].value,
67
32
  testdesc: row[1].value,
@@ -28,8 +28,8 @@ module JunitReport
28
28
  # output to XML file format for Junit for CI.
29
29
  builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
30
30
  testsuite_attrs = {
31
- 'classname' => $testSuiteFile.to_s,
32
- 'name' => $testSuiteFile.to_s,
31
+ 'classname' => $testcasesFolder.to_s,
32
+ 'name' => $testcasesFolder.to_s,
33
33
  'tests' => $totalTests.to_s,
34
34
  'failures' => $totalTestFailures.to_s,
35
35
  'timestamp' => $test_start_time.to_s,
@@ -14,10 +14,9 @@ module ReportSummary
14
14
  # output the test results summary for the current test case
15
15
  def self.test_step_summary(test_file_name, test_file_name_index)
16
16
  @testStepReportSummary[test_file_name_index] = <<~TEXT
17
- Test file: #{test_file_name}
18
- Browser type: #{$browserType}
17
+ Test file executed: #{test_file_name}
18
+ Browser type used: #{$browserType}
19
19
  Browser version: #{Browser.browser_version}
20
- Environment: #{$env_type}
21
20
  Started at: #{$test_case_start_time}
22
21
  Finished at: #{$test_case_end_time}
23
22
  There are: #{$testStepPasses} Passes
@@ -30,7 +29,7 @@ module ReportSummary
30
29
  def self.print_overall_test_summary
31
30
  # output to the console
32
31
 
33
- MyLog.log.info "Finished processing all test files - executed via test suite: #{$testSuiteFile} by tester: #{$tester}"
32
+ MyLog.log.info "Finished processing all test files - executed via test suite: #{$testcasesFolder}"
34
33
  MyLog.log.info "Overall Test Summary:"
35
34
  @testStepReportSummary.each do |testStepReportSummary|
36
35
  testStepReportSummary.each_line do |line|
data/lib/utils/browser.rb CHANGED
@@ -113,14 +113,16 @@ module Browser
113
113
 
114
114
  # create screenshot filename and save the screenshot if the test has failed or
115
115
  # if explictly required
116
- def self.check_save_screenshot(full_sc_dirname, screen_shot)
116
+ def self.check_save_screenshot(screen_shot)
117
117
  if ($currentTestFail || screen_shot)
118
118
  time = Time.now.strftime('%H%M')
119
119
  if ($currentTestFail)
120
+ full_sc_dirname = CreateDirectories.construct_testspecdirs
120
121
  scFileName = full_sc_dirname + "/Test_step-#{$testStep}_Failed_"\
121
122
  "#{time}.png"
122
123
  else
123
124
  # file name will be teststep.png
125
+ full_sc_dirname = CreateDirectories.construct_testspecdirs
124
126
  scFileName = full_sc_dirname + "/Test_step-#{$testStep}_#{time}.png"
125
127
  end
126
128
 
@@ -29,18 +29,25 @@ module CreateDirectories
29
29
 
30
30
  # create the 'Project' directory if it doesn't already exist
31
31
  project_id = $projectId.delete(' ')
32
- project_iddir = result_home + '/' + project_id
33
- Dir.mkdir(project_iddir) unless File.directory? project_iddir
32
+ $project_iddir = result_home + '/' + project_id
33
+ Dir.mkdir($project_iddir) unless File.directory? $project_iddir
34
34
 
35
- # Creates a folder Ran_on_Time with the time as of now.
35
+ # the test suite summary is a XML report generated will be called 'suite_summary.xml'
36
36
  time = Time.new
37
37
  f_date = time.strftime('%d-%b-%Y')
38
38
  f_time = time.strftime('%H_%M_%S')
39
- $runNoDir = project_iddir + '/' + 'Ran_on_' + f_date + '_' + f_time
40
- Dir.mkdir($runNoDir)
39
+
40
+ $TestSuiteSummaryXML = 'Results/' + $projectId + '/' + f_date + '_' + f_time + '_test_result.xml'
41
41
  end
42
42
 
43
43
  def self.construct_testspecdirs
44
+
45
+ time = Time.new
46
+ f_date = time.strftime('%d-%b-%Y')
47
+ f_time = time.strftime('%H_%M_%S')
48
+ $runNoDir = $project_iddir + '/' + 'Ran_on_' + f_date + '_' + f_time
49
+ Dir.mkdir($runNoDir)
50
+
44
51
  # create directories for each test spec
45
52
  # create a sub-directory named from the 'testId' (with any spaces taken out)
46
53
  # if it doesn't already exist plus the browser type
@@ -55,18 +62,6 @@ module CreateDirectories
55
62
  abs_path_screenshot_dir = File.absolute_path(screenshot_dir)
56
63
  abs_path_run_no_dir = File.absolute_path($runNoDir)
57
64
 
58
- # the test suite summary is a XML report generated will be called 'suite_summary.xml'
59
- time = Time.new
60
- f_date = time.strftime('%d-%b-%Y')
61
- f_time = time.strftime('%H_%M_%S')
62
-
63
- $TestSuiteSummaryXML = 'Results/' + $projectId + '/' + f_date + '_' + f_time + '_test_result.xml'
64
-
65
- # the log file name will be under the test ID directory
66
-
67
- MyLog.log.info "TestId: #{$testId}"
68
- MyLog.log.info "Screenshot directory: #{abs_path_screenshot_dir} \n"
69
-
70
65
  # if any issues then set error message and re-raise the exception
71
66
  rescue Exception => error
72
67
  # construct the error message from custom text and the actual system error message (converted to a string)
@@ -12,114 +12,70 @@ module TestEngine
12
12
 
13
13
  # process the test files to execute the tests
14
14
  def self.process_testfiles
15
- test_file_name = ''
16
-
17
- # initialise the index for reading the list of test file names
18
- test_file_name_index = 0
19
-
20
15
  # get the overall test start time
21
16
  $test_start_time = Report.current_time
22
17
 
23
- # create project folders - these only need creating once per test suite
24
- CreateDirectories.construct_projectdirs
25
-
26
18
  # loop through all the available test files to execute the tests
27
- while test_file_name_index < $numberOfTestSpecs
28
- # get the next test spec data from the test suite doc
29
- test_suites = Parser.parse_test_suite_data(test_file_name_index)
30
-
31
- test_suites.each do |test_suite|
32
- $testId = test_suite[:id]
33
- $testSpecDesc = test_suite[:specdesc]
34
- $env_type = test_suite[:env]
35
- $browserType = test_suite[:browser]
36
-
37
- if ARGV.length < 2
38
- $browserType = test_suite[:browser]
39
- MyLog.log.info "Will use the following browser from Test Suite: #{$browserType}"
40
- elsif ARGV.length < 3
41
- $browserType = ARGV[1]
42
- MyLog.log.info "Will use the following browser from CMD line: " + ARGV[1]
43
- else
44
- raise IOError, 'Unable to open browser'
45
- end
46
-
47
- # remove any unwanted end-of-line characters from the file name
48
- test_file_name = $testSpecDesc
49
-
50
- begin # start of rescue block for readTestData
51
- # read in the test data
52
- testFileType = Parser.read_test_data(test_file_name)
53
- # if unable to read the test data, show the error and move onto the
54
- # next file (if there is one)
55
- rescue StandardError => error
56
- MyLog.log.warn "Terminating the current test case: " \
57
- "#{test_file_name} #{error}"
58
- MyLog.log.info '...continuing with the next test case (if there is one)'
59
- end # of rescue block for readTestData
60
-
61
- # create the project directories, returns the screenshot directory name
62
- begin # start of rescue block for construct_projectdirs
63
- # create test spec directories - these need creating once per testspec
64
- full_sc_dirname = CreateDirectories.construct_testspecdirs
65
- # if an error then show the error and terminate
66
- rescue StandardError => error
67
- warn error
68
- MyLog.log.warn error
69
- abort
70
- end
71
-
72
- # loop through the test file
73
- if testFileType != 'XLSX'
74
- MyLog.log.info 'Not a valid XLSX File Type'
19
+ Parser.test_files.each_with_index do |test_file_name, test_file_index|
20
+ begin # start of rescue block for readTestData
21
+ # read in the test data
22
+ testFileType = Parser.read_test_data(test_file_name)
23
+ # if unable to read the test data, show the error and move onto the
24
+ # next file (if there is one)
25
+ rescue StandardError => error
26
+ MyLog.log.warn 'Terminating the current test case: ' \
27
+ "#{test_file_name} #{error}"
28
+ MyLog.log.info '...continuing with the next test case (if there is one)'
29
+ end # of rescue block for readTestData
30
+
31
+ # create project folders - these only need creating once per test suite
32
+ CreateDirectories.construct_projectdirs
33
+
34
+ # loop through the test file
35
+ MyLog.log.info 'Not a valid XLSX File Type' if testFileType != 'XLSX'
36
+
37
+ # get the test case start time
38
+ $test_case_start_time = Report.current_time
39
+ # initialise the test end time
40
+ $test_case_end_time = Report.current_time
41
+
42
+ begin
43
+ test_steps = Parser.parse_test_step_data(testFileType)
44
+
45
+ test_steps.each_with_index do |test_step, step_index|
46
+ $testStep = test_step[:testStep]
47
+ $testStepDes = test_step[:testdesc]
48
+ screen_shot = test_step[:screenShotData]
49
+
50
+ # process the test step data
51
+ TestSteps.process_test_steps(test_file_name, step_index, test_step)
52
+ # see if screenshot required
53
+ Browser.check_save_screenshot(screen_shot)
75
54
  end
76
-
77
- # get the test case start time
78
- $test_case_start_time = Report.current_time
79
- # initialise the test end time
80
- $test_case_end_time = Report.current_time
81
-
82
- begin
83
- test_steps = Parser.parse_test_step_data(testFileType)
84
-
85
- test_steps.each_with_index do |test_step, index|
86
- $testStep = test_step[:testStep]
87
- $testStepDes = test_step[:testdesc]
88
- screen_shot = test_step[:screenShotData]
89
-
90
- # process the test step data
91
- TestSteps.process_test_steps(test_file_name, index, test_step)
92
- # see if screenshot required
93
- Browser.check_save_screenshot(full_sc_dirname, screen_shot)
94
- end
95
- rescue TafError => error
96
- warn error
97
- MyLog.log.warn error
98
- end
99
-
100
- # get the test case end time
101
- $test_case_end_time = Report.current_time
102
-
103
- # output the test results summary for the current test case,
104
- # pass in the test file number to save the summary against it's testfile
105
- ReportSummary.test_step_summary(test_file_name, test_file_name_index)
106
- JunitReport.test_step_summary_xml(test_file_name, test_file_name_index)
107
-
108
- # close the browser if created
109
- Browser.b.quit
110
-
111
- # increment loop counter to move onto next test file
112
- test_file_name_index += 1
113
-
114
- # record total passes and failures and reset the failure counters for
115
- # the test steps
116
- $totalTestPasses += $testStepPasses
117
- $totalTestFailures += $testStepFailures
118
- $totalTestNotrun += $testStepNotrun
119
- $testStepPasses = 0
120
- $testStepFailures = 0
121
- $testStepNotrun = 0
55
+ rescue TafError => error
56
+ warn error
57
+ MyLog.log.warn error
122
58
  end
123
- end # while loop for test files
124
- end
59
+
60
+ # get the test case end time
61
+ $test_case_end_time = Report.current_time
62
+
63
+ # output the test results summary for the current test case,
64
+ # pass in the test file number to save the summary against it's testfile
65
+ ReportSummary.test_step_summary(test_file_name, test_file_index)
66
+ JunitReport.test_step_summary_xml(test_file_name, test_file_index)
67
+
68
+ # close the browser if created
69
+ Browser.b.quit
70
+
71
+ # record total passes and failures and reset the failure counters for
72
+ # the test steps
73
+ $totalTestPasses += $testStepPasses
74
+ $totalTestFailures += $testStepFailures
75
+ $totalTestNotrun += $testStepNotrun
76
+ $testStepPasses = 0
77
+ $testStepFailures = 0
78
+ $testStepNotrun = 0
79
+ end
80
+ end # while loop for test files
125
81
  end
data/lib/version.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Taf
4
4
  # This module holds the TAF version information.
5
5
  module Version
6
- STRING = '0.1.9'.freeze
6
+ STRING = '0.2.0'.freeze
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, running on ' \
9
9
  '%<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'.freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Perrett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-08 00:00:00.000000000 Z
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler