taf 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/bin/taf +4 -0
  3. data/lib/functions/handlers.rb +4 -0
  4. data/lib/functions/handlers/base_handler.rb +89 -0
  5. data/lib/functions/handlers/browser_back.rb +19 -0
  6. data/lib/functions/handlers/browser_forward.rb +19 -0
  7. data/lib/functions/handlers/browser_quit.rb +19 -0
  8. data/lib/functions/handlers/browser_refresh.rb +19 -0
  9. data/lib/functions/handlers/capture_alert.rb +20 -0
  10. data/lib/functions/handlers/check_box.rb +22 -0
  11. data/lib/functions/handlers/check_boxdata.rb +40 -0
  12. data/lib/functions/handlers/check_browser_title.rb +23 -0
  13. data/lib/functions/handlers/check_logs.rb +24 -0
  14. data/lib/functions/handlers/check_screendata.rb +23 -0
  15. data/lib/functions/handlers/check_url.rb +22 -0
  16. data/lib/functions/handlers/click_button.rb +53 -0
  17. data/lib/functions/handlers/execute_system_command.rb +23 -0
  18. data/lib/functions/handlers/handle_browser_window.rb +23 -0
  19. data/lib/functions/handlers/insert_value_config.rb +28 -0
  20. data/lib/functions/handlers/ipause.rb +21 -0
  21. data/lib/functions/handlers/list_all_dropdowns_values.rb +24 -0
  22. data/lib/functions/handlers/login.rb +25 -0
  23. data/lib/functions/handlers/open_portal_url.rb +25 -0
  24. data/lib/functions/handlers/open_url.rb +26 -0
  25. data/lib/functions/handlers/ping_test.rb +28 -0
  26. data/lib/functions/handlers/radio_button.rb +25 -0
  27. data/lib/functions/handlers/select_dropdown.rb +28 -0
  28. data/lib/functions/handlers/send_special_keys.rb +22 -0
  29. data/lib/functions/handlers/write_box_data.rb +40 -0
  30. data/lib/functions/handlers/write_to_editor.rb +27 -0
  31. data/lib/main.rb +74 -0
  32. data/lib/parser/parser.rb +87 -0
  33. data/lib/parser/xlsx_parser.rb +126 -0
  34. data/lib/report/junit_report.rb +68 -0
  35. data/lib/report/report.rb +155 -0
  36. data/lib/report/report_summary.rb +78 -0
  37. data/lib/taf_config.rb +37 -0
  38. data/lib/utils/browser.rb +140 -0
  39. data/lib/utils/create_directories.rb +94 -0
  40. data/lib/utils/exceptions.rb +7 -0
  41. data/lib/utils/test_engine.rb +164 -0
  42. data/lib/utils/test_steps.rb +39 -0
  43. data/lib/utils/zap.rb +131 -0
  44. data/lib/version.rb +21 -0
  45. metadata +301 -0
@@ -0,0 +1,126 @@
1
+ # Created on 02 Aug 2018
2
+ # @author: Andy Perrett
3
+ #
4
+ # Versions:
5
+ # 1.0 - Baseline
6
+ #
7
+ # xlsx_parser.rb - xlsx parser functions
8
+ module XlsxParser
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
+ suite[:securitytest] = row[4].value
40
+ elsif ARGV.length < 3
41
+ suite[:browser] = ARGV[1]
42
+ elsif ARGV.length < 4
43
+ suite[:browser] = ARGV[1]
44
+ suite[:securitytest] = ARGV[2]
45
+ else
46
+ raise IOError, 'Unable to open browser or Unable to run Securtiy Test.'
47
+ end
48
+
49
+ # if ARGV.length < 3
50
+ # suite[:securitytest] = row[4].value
51
+ # elsif ARGV.length < 4
52
+ # suite[:securitytest] = 'securtiy=' + ARGV[2]
53
+ # else
54
+ # raise IOError, 'Unable to run Securtiy Test.'
55
+ # end
56
+
57
+ suite
58
+ end
59
+ end
60
+
61
+ def self.parse_xlxs_test_header_data
62
+ # get the number of test steps in the file
63
+ $numberOfTestSteps = ($xlsxDoc[0].sheet_data.size) - 7
64
+ worksheet = $xlsxDoc[0]
65
+ # get the remaining test data
66
+ $testDes = worksheet.sheet_data[4][1].value
67
+ puts "Number of test steps: #{$numberOfTestSteps}"
68
+ puts "Test Description: #{$testDes}"
69
+
70
+ end
71
+
72
+ # parseTestStepData
73
+ def self.parse_test_step_data(testFileType)
74
+ begin
75
+ worksheet = $xlsxDoc[0]
76
+ worksheet[7..$numberOfTestSteps+7].map do |row|
77
+ test = {
78
+ testStep: row[0].value,
79
+ testdesc: row[1].value,
80
+ testFunction: row[2].value,
81
+ testvalue: row[3].value,
82
+ locate: row[4].value,
83
+ testvalue2: row[5].value,
84
+ locate2: row[6].value,
85
+ screenShotData: row[7].value,
86
+ skipTestCase: row[8].value,
87
+ }
88
+
89
+ # convert test step, screenshot and skip test case functions to lowercase.
90
+ test[:testFunction].downcase!
91
+
92
+ # get screenshot request, check for a null value and default to 'N'
93
+
94
+ if (test[:screenShotData] == 'Y')
95
+ test[:screenShotData] = true
96
+ elsif (test[:screenShotData] == 'N')
97
+ test[:screenShotData] = false
98
+ else
99
+ test[:screenShotData] = false
100
+ end
101
+
102
+ if (test[:skipTestCase] == 'Y')
103
+ test[:skipTestCase] = true
104
+ elsif(test[:skipTestCase] == 'N')
105
+ test[:skipTestCase] = false
106
+ else
107
+ test[:skipTestCase] = false
108
+ end
109
+
110
+ # if there is an element locator then use it, otherwise use an ID
111
+ if (test[:locate].to_s == '')
112
+ test[:locate] = 'id'
113
+ end
114
+
115
+ if (test[:locate2].to_s == '')
116
+ test[:locate2] = 'id'
117
+ end
118
+
119
+ test
120
+ # if an error reading the test step data then re-raise the exception
121
+ rescue StandardError => error
122
+ raise
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Created on 20 Sept 2017
4
+ # @author: Andy Perrett
5
+ #
6
+ # Versions:
7
+ # 1.0 - Baseline
8
+ #
9
+ # junit_report.rb - methods for writing to the summary xml junit report.
10
+ module JunitReport
11
+ require_relative '../taf_config.rb'
12
+ # holds printable test report summary for all the executed tests
13
+ @testStepReportSummary2 = []
14
+ # construct the test suite header for junit
15
+ def self.test_step_summary_xml(test_file_name, test_file_name_index)
16
+ @testStepReportSummary2[test_file_name_index] = {
17
+ 'classname' => test_file_name,
18
+ 'name' => test_file_name,
19
+ 'assertions' => $numberOfTestSteps,
20
+ 'failures' => $testStepFailures,
21
+ 'tests' => $testStepPasses,
22
+ 'skipped' => $testStepNotrun,
23
+ 'time' => TimeDifference.between($test_case_end_time, $test_case_start_time).in_seconds
24
+ }
25
+ end
26
+
27
+ def self.test_summary_junit
28
+ # output to XML file format for Junit for CI.
29
+ builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
30
+ testsuite_attrs = {
31
+ 'classname' => $testSuiteFile.to_s,
32
+ 'name' => $testSuiteFile.to_s,
33
+ 'tests' => $totalTests.to_s,
34
+ 'failures' => $totalTestFailures.to_s,
35
+ 'timestamp' => $test_start_time.to_s,
36
+ 'skipped' => $totalTestNotrun.to_s,
37
+ 'time' => TimeDifference.between($test_end_time, $test_start_time).in_seconds
38
+ }
39
+ xml.testsuites(testsuite_attrs) do |testsuites|
40
+ @testStepReportSummary2.each do |testStepReportSummary2|
41
+ testsuites.testsuite(testStepReportSummary2) do |testsuite|
42
+ $testStep_xml[testStepReportSummary2['name']].each do |testStepIndex, testStep_xml|
43
+ testsuite.testcase(testStep_xml) do |testcase|
44
+ failure = $failtestStep_xml&.[](testStepReportSummary2['name'])&.[](testStepIndex)
45
+ skipped = $skiptestStep_xml&.[](testStepReportSummary2['name'])&.[](testStepIndex)
46
+ testcase.failure(failure) if failure
47
+ testcase.skipped(skipped) if skipped
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ # output XML content to console for debug
56
+ # puts builder.to_xml
57
+
58
+ # open the suite summary file for writing if not already open
59
+ if !File.exist?($TestSuiteSummaryXML) || $TestSuiteSummaryXML.closed?
60
+ $testSuiteSummaryFile_xml = File.open($TestSuiteSummaryXML, 'w+')
61
+ $testSuiteSummaryFile_xml.write builder.to_xml
62
+ elsif $log.puts "test suite summary file xml name: #{$TestSuiteSummaryXML} is already open"
63
+ end
64
+
65
+ # if the file is open then close it
66
+ $testSuiteSummaryFile_xml.close unless $testSuiteSummaryFile_xml.closed?
67
+ end
68
+ end
@@ -0,0 +1,155 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Created on 20 Sept 2017
4
+ # @author: Andy Perrett
5
+ #
6
+ # Versions:
7
+ # 1.0 - Baseline
8
+ #
9
+ # report.rb - methods for accessing and writing to the test report file(s)
10
+ module Report
11
+ require_relative '../taf_config.rb'
12
+ # setup the test results output file
13
+ def self.open_test_report_file
14
+ # open a new file for writing
15
+ $log.puts("Opening Test Result file: #{$testResultFileName} \n")
16
+
17
+ # open test results file for writing if not already open
18
+ if !File.exist?($testResultFileName) || $testResultFileName.closed?
19
+ @results_file = File.open($testResultFileName, 'w')
20
+ elsif $log.puts "test results file name: #{$testResultFileName} is already open"
21
+ end
22
+ end
23
+
24
+ # close_testresults_file
25
+ def self.close_test_results_file
26
+ # if the file is open then close it
27
+ Report.results.close unless Report.results.closed?
28
+ end
29
+
30
+ # results file variable
31
+ def self.results
32
+ results_file = @results_file
33
+ end
34
+
35
+ def self.open_log_file
36
+ # open a new file for writing
37
+ $stdout.puts "Opening log file: #{$logFileName} \n"
38
+
39
+ # create a new log file and set the mode as 'append'
40
+ $log = File.open($logFileName, 'w+')
41
+ end
42
+
43
+ def self.close_log_file
44
+ # if the file is open then close it
45
+ $log.close unless $log.closed?
46
+ end
47
+
48
+ # print the main test header info to the test results file
49
+ def self.print_test_header
50
+ Report.results.puts("Project Name: #{$projectName} Project ID: #{$projectId} Sprint: #{$sprint}")
51
+ Report.results.puts("Test ID: #{$testId} Test Description: #{$testDes}")
52
+ Report.results.puts("Executed with browser: #{$browserType}")
53
+ Report.results.puts("Test suite: #{$testSuiteFile}")
54
+ Report.results.puts("Tester: #{$tester}", "\n \n")
55
+ end
56
+
57
+ # get the current time in the format Day - Month - Date - Time (HH:MM:SS)
58
+ def self.current_time
59
+ time = Time.new
60
+ f_time = time.strftime('%a %b %d %H:%M:%S %Z')
61
+ f_time
62
+ end
63
+
64
+ # print the test Step info to the test results file
65
+ def self.print_test_step_header(test_file_name, testStepIndex)
66
+ Report.results.puts("\n" + "Test start time: #{f_time = current_time}")
67
+ Report.results.puts("Test step: #{$testStep} : #{$testStepDes} \n")
68
+ puts "\nTest start time: #{f_time = current_time} \n"
69
+ puts "Test step: #{$testStep} : #{$testStepDes} "
70
+
71
+ step = {
72
+ 'id' => $testStep,
73
+ 'classname' => 'SuiteID: ' + $testId.to_s + ' Test Step: ' + $testStep.to_s + ' ' + $testStepDes.to_s,
74
+ 'name' => $testStepDes,
75
+ 'file' => test_file_name
76
+ }
77
+ # output to console to show test step
78
+ # puts step
79
+
80
+ return unless test_file_name
81
+ $testStep_xml ||= {}
82
+ $testStep_xml[test_file_name] ||= {}
83
+ $testStep_xml[test_file_name][testStepIndex] = step
84
+ end
85
+
86
+ # print the Pass / Fail status of a test to the test results file
87
+ def self.test_pass_fail(passFail, test_file_name, testStepIndex)
88
+ if passFail == true
89
+ $previousTestFail = $currentTestFail
90
+ $currentTestFail = false
91
+ $testStepPasses += 1
92
+ Report.results.puts("Test #{$testStep} has Passed")
93
+ puts "Test #{$testStep} has Passed ".green
94
+ elsif passFail == false
95
+ $previousTestFail = $currentTestFail
96
+ $currentTestFail = true
97
+ $testStepFailures += 1
98
+ Report.results.puts("Test #{$testStep} has FAILED")
99
+ puts "Test #{$testStep} has FAILED ".red
100
+ failstep = {
101
+ 'message' => 'SuiteID: ' + $testId.to_s + ' Test Step: ' + $testStep.to_s + ' Test has FAILED - Check logs',
102
+ 'type' => 'FAILURE',
103
+ 'file' => test_file_name
104
+ }
105
+ # output to console to show test step failure
106
+ # puts failstep
107
+
108
+ return unless test_file_name
109
+ $failtestStep_xml ||= {}
110
+ $failtestStep_xml[test_file_name] ||= []
111
+ $failtestStep_xml[test_file_name][testStepIndex] = failstep
112
+ else
113
+ $currentTestFail = false
114
+ $testStepNotrun += 1
115
+ Report.results.puts("Test #{$testStep} no checks performed")
116
+ puts "Test #{$testStep} no checks performed ".blue
117
+ skipstep = {
118
+ 'message' => 'SuiteID: ' + $testId.to_s + ' Test Step: ' + $testStep.to_s + ' No checks performed - Check logs',
119
+ 'type' => 'SKIPPED',
120
+ 'file' => test_file_name
121
+ }
122
+ # output to console to show test step failure
123
+ # puts skipstep
124
+
125
+ return unless test_file_name
126
+ $skiptestStep_xml ||= {}
127
+ $skiptestStep_xml[test_file_name] ||= []
128
+ $skiptestStep_xml[test_file_name][testStepIndex] = skipstep
129
+ end
130
+ Report.results.puts("Test end time: #{f_time = current_time}\n")
131
+ puts "Test end time: #{f_time = current_time} \n"
132
+ end
133
+
134
+ # check if the test failure threshold has been reached for total failures or consecutive failures.
135
+ # If a certain number of consecutive tests fail then throw an exception
136
+ def self.check_failure_threshold(test_file_name, testStepIndex)
137
+ consecutiveFailThreshold = 5
138
+ if $previousTestFail && $currentTestFail
139
+ @consecutiveTestFail += 1
140
+ else
141
+ @consecutiveTestFail = 0
142
+ end
143
+
144
+ if @consecutiveTestFail >= consecutiveFailThreshold
145
+ Report.results.puts("\nTerminating the current test case as the test failure threshold (#{consecutiveFailThreshold} ) has been reached")
146
+
147
+ # write info to $stderr
148
+ $stderr.puts "Terminating the current test case: #{test_file_name} as the test failure threshold (#{consecutiveFailThreshold}) has been reached."
149
+ $stderr.puts '...continuing with the next test case (if there is one)'
150
+
151
+ raise FailureThresholdExceeded,
152
+ "#{consecutiveFailThreshold} Test Steps Failed."
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Created on 20 Sept 2017
4
+ # @author: Andy Perrett
5
+ #
6
+ # Versions:
7
+ # 1.0 - Baseline
8
+ #
9
+ # report_summary.rb - methods for writing to the test summary report file
10
+ module ReportSummary
11
+ require_relative '../taf_config.rb'
12
+ # holds printable test report summary for all the executed tests
13
+ @testStepReportSummary = []
14
+ # output the test results summary for the current test case
15
+ def self.test_step_summary(test_file_name, test_file_name_index)
16
+ # construct the test step report summary
17
+ @testStepReportSummary[test_file_name_index] = "\n" 'Test file:', test_file_name,\
18
+ "\n" 'Browser type:', $browserType, \
19
+ "\n" 'Browser version:', Browser.browser_version.to_s, \
20
+ "\n" 'Environment:', $env_type, \
21
+ "\n" 'Started at:', $test_case_start_time, \
22
+ "\n" 'Finished at:', $test_case_end_time, \
23
+ "\n" 'There are:', $testStepPasses, 'Passes' \
24
+ "\n" 'There are:', $testStepFailures, 'Failures' \
25
+ "\n" 'There are:', $testStepNotrun, 'Skipped Tests' "\n"
26
+ # ... and save in a format that is printable
27
+ @testStepReportSummary[test_file_name_index] = @testStepReportSummary[test_file_name_index].join(' ')
28
+ Report.results.puts ''
29
+ Report.results.puts("Test Summary: #{@testStepReportSummary[test_file_name_index]}")
30
+ Report.results.puts("Test end time: #{$test_case_end_time} \n")
31
+ end
32
+
33
+ # output the overall test results summary
34
+ def self.print_overall_test_summary
35
+ # output to the console
36
+
37
+ puts "\nFinished processing all test files - executed via test suite: #{$testSuiteFile} by tester: #{$tester}"
38
+ puts "\nOverall Test Summary:"
39
+ @testStepReportSummary.each do |testStepReportSummary|
40
+ puts testStepReportSummary
41
+ end
42
+
43
+ puts "\nTotal Tests started at: #{$test_start_time}"
44
+ puts "Total Tests finished at: #{$test_end_time}"
45
+ puts ('Total Tests duration: ' + TimeDifference.between($test_end_time, $test_start_time).humanize)
46
+ puts "Total Tests Passed: #{$totalTestPasses}".green
47
+ puts "Total Tests Failed: #{$totalTestFailures}".red
48
+ puts "Total Tests Skipped: #{$totalTestNotrun}".blue
49
+ $totalTests = [$totalTestPasses, $totalTestFailures, $totalTestNotrun].sum
50
+ puts "Total Tests: #{$totalTests}\n"
51
+
52
+ # output to the suite summary file
53
+
54
+ # open the suite summary file for writing if not already open
55
+ if !File.exist?($testSuiteSummaryFileName) || $testSuiteSummaryFileName.closed?
56
+ testSuiteSummaryFile = File.open($testSuiteSummaryFileName, 'w')
57
+ puts "\nTest Suite Summary file located at:"
58
+ puts "#{$testSuiteSummaryFileName}\n"
59
+ elsif $log.puts "test suite summary file name: #{$testSuiteSummarylFileName} is already open"
60
+ end
61
+
62
+ testSuiteSummaryFile.puts "Finished processing all test files - executed via test suite: #{$testSuiteFile} by tester: #{$tester} \n"
63
+ testSuiteSummaryFile.puts "\nOverall Test Summary:"
64
+ @testStepReportSummary.each do |testStepReportSummary|
65
+ testSuiteSummaryFile.puts testStepReportSummary
66
+ end
67
+ testSuiteSummaryFile.puts("\nTotal Tests started at: #{$test_start_time}")
68
+ testSuiteSummaryFile.puts("Total Tests finished at: #{$test_end_time}")
69
+ testSuiteSummaryFile.puts('Total Tests duration: ' + TimeDifference.between($test_end_time, $test_start_time).humanize)
70
+ testSuiteSummaryFile.puts("Total Tests Passed: #{$totalTestPasses}")
71
+ testSuiteSummaryFile.puts("Total Tests Failed: #{$totalTestFailures}")
72
+ testSuiteSummaryFile.puts("Total Tests Skipped: #{$totalTestNotrun}")
73
+ testSuiteSummaryFile.puts("Total Tests: #{$totalTests} \n")
74
+
75
+ # if the file is open then close it
76
+ testSuiteSummaryFile.close unless testSuiteSummaryFile.closed?
77
+ end
78
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Created on 20 Sept 2017
4
+ # @author: Andy Perrett
5
+ #
6
+ # Versions:
7
+ # 1.0 - Baseline
8
+ #
9
+ # taf_config.rb - Framework Config file
10
+
11
+ # list of all the required gems.
12
+ require 'selenium-webdriver'
13
+ require 'watir'
14
+ require 'rubygems'
15
+ require 'fileutils'
16
+ require 'logger'
17
+ require 'net/ping'
18
+ require 'nokogiri'
19
+ require 'time_difference'
20
+ require 'colored'
21
+ require 'rubyXL'
22
+
23
+ # list of all the required files
24
+ require_relative './utils/test_steps'
25
+ require_relative './report/report'
26
+ require_relative './utils/browser'
27
+ require_relative './utils/create_directories'
28
+ require_relative './utils/test_engine'
29
+ require_relative './utils/exceptions'
30
+ require_relative './report/junit_report'
31
+ require_relative './report/report_summary'
32
+ require_relative './parser/parser'
33
+ require_relative './parser/xlsx_parser'
34
+
35
+ # Require all test step handlers, which register themselves with
36
+ # TestStep.handlers when the files are required.
37
+ require_relative './functions/handlers'