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,23 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class HandleBrowserWindow < Base
7
+ register :handle_browser_window
8
+
9
+ def perform(step_attributes)
10
+ text_check = step_attributes[:testvalue]
11
+
12
+ Browser.b.window(title: text_check.to_s).use
13
+ sleep 3
14
+ Browser.b.title.eql?(text_check.to_s)
15
+ Report.results.puts("Window title: #{text_check} is correct")
16
+ true
17
+ rescue StandardError
18
+ Report.results.puts("Window not found: #{text_check}")
19
+ false
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class InsertValueConfig < Base
7
+ register :insert_value_config
8
+
9
+ def perform(step_attributes)
10
+ box = step_attributes[:testvalue]
11
+ locate = step_attributes[:locate]
12
+ value = step_attributes[:testvalue2]
13
+ value = ENV[value.to_s]
14
+
15
+ Browser.b.text_field(:"#{locate}" => box).wait_until_present.set value
16
+ (Browser.b.text_field(:"#{locate}" => box).value == value)
17
+ Report.results.puts("Textbox: #{box} has correct value: #{value}")
18
+ true
19
+ rescue StandardError
20
+ Report.results.puts("Textbox: #{box} has the incorrect value: #{value}")
21
+ false
22
+ rescue StandardError
23
+ Report.results.puts("Textbox: #{box} does not exist")
24
+ false
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class Ipause < Base
7
+ register :ipause
8
+
9
+ def perform(step_attributes)
10
+ wait_time = step_attributes[:testvalue]
11
+
12
+ sleep(wait_time.to_i)
13
+ Report.results.puts('Wait completed for seconds: ' + wait_time.to_s)
14
+ true
15
+ rescue StandardError
16
+ Report.results.puts('Wait failed for seconds: ' + wait_time.to_s)
17
+ false
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class ListAllDropdownValues < Base
7
+ register :list_all_dropdown_values
8
+
9
+ def perform(step_attributes)
10
+ dropdown = step_attributes[:testvalue]
11
+ locate = step_attributes[:locate]
12
+
13
+ Browser.b.element(:"#{locate}" => dropdown).wait_until_present
14
+ Browser.b.select_list(:"#{locate}" => dropdown).options.each do |i|
15
+ Report.results.puts("List of dropdown for #{dropdown} are: #{i.text}")
16
+ return true
17
+ end
18
+ rescue StandardError
19
+ Report.results.puts("List dropdown: #{dropdown} does not exist")
20
+ false
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'base_handler'
2
+
3
+ module TestSteps
4
+ module Handlers
5
+ class PortalLogin < Base
6
+ register :portal_login
7
+
8
+ def perform(step_attributes)
9
+ value = step_attributes[:testvalue]
10
+
11
+ url = ENV['URL']
12
+ user = ENV[value.to_s]
13
+ pass = ENV['USER_PASS']
14
+ b_title = 'Log in'
15
+ b_title_sucess = 'Home'
16
+ user_elm = 'user_email'
17
+ pass_elm = 'user_password'
18
+
19
+ open_url_process(url)
20
+ login_process(b_title, user_elm, pass_elm, user, pass)
21
+ mem_word_check(user, b_title_sucess)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class OpenPortalUrl < Base
7
+ register :open_portal_url
8
+
9
+ def perform(step_attributes)
10
+ value = step_attributes[:testvalue]
11
+ url = ENV[value.to_s]
12
+ Browser.open_browser
13
+ Browser.b.goto(url)
14
+ url_nme = Browser.b.url
15
+ if url_nme == url
16
+ Report.results.puts("opened URL: #{url}")
17
+ return true
18
+ else
19
+ Report.results.puts("URL not open: #{url} - opened #{url_nme} instead")
20
+ return false
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class OpenUrl < Base
7
+ register :open_url
8
+
9
+ def perform(step_attributes)
10
+ url = step_attributes[:testvalue]
11
+
12
+ Browser.open_browser
13
+ Browser.b.goto(url)
14
+ sleep 2
15
+ url_nme = Browser.b.url
16
+ if url_nme == url
17
+ Report.results.puts("opened URL: #{url}")
18
+ return true
19
+ else
20
+ Report.results.puts("URL not open: #{url} - opened #{url_nme} instead")
21
+ return false
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class PingTest < Base
7
+ register :ping_test
8
+
9
+ def perform(step_attributes)
10
+ url = step_attributes[:testvalue]
11
+
12
+ while check = Net::Ping::HTTP.new(url)
13
+ check.ping?
14
+ sleep 5
15
+ if check.ping? == true
16
+ # website alive
17
+ Report.results.puts("pinged: #{url}")
18
+ return true
19
+ else
20
+ # website not responding
21
+ Report.results.puts("Failed to ping: #{url}")
22
+ return false
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class RadioButton < Base
7
+ register :radio_button
8
+
9
+ def perform(step_attributes)
10
+ radio = step_attributes[:testvalue]
11
+ value2 = step_attributes[:testvalue2]
12
+ locate = step_attributes[:locate]
13
+ locate2 = step_attributes[:locate2]
14
+
15
+ Browser.b.radio(:"#{locate}" => radio).wait_until_present
16
+ Browser.b.radio(:"#{locate}" => radio, :"#{locate2}" => "#{value2}").set
17
+ Report.results.puts("Radio button: #{radio} has been selected")
18
+ true
19
+ rescue StandardError
20
+ Report.results.puts("Radio button: #{radio} does not exist")
21
+ false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class SelectDropdown < Base
7
+ register :select_dropdown
8
+
9
+ def perform(step_attributes)
10
+ dropdown = step_attributes[:testvalue]
11
+ value2 = step_attributes[:testvalue2]
12
+ locate = step_attributes[:locate]
13
+ locate2 = step_attributes[:locate2]
14
+
15
+ Browser.b.select_list(:"#{locate}" => dropdown).wait_until_present
16
+ Browser.b.select_list(:"#{locate}" => dropdown).option(:"#{locate2}" => "#{value2}").select
17
+ Report.results.puts("Dropdown item: #{value2} has been selected")
18
+ true
19
+ rescue StandardError
20
+ Report.results.puts("Dropdown item: #{value2} has NOT been selected")
21
+ false
22
+ rescue StandardError
23
+ Report.results.puts("the dropdown: #{dropdown} does not exist")
24
+ false
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class SendSpecialKeys < Base
7
+ register :send_special_keys
8
+
9
+ def perform(step_attributes)
10
+ special_key = step_attributes[:testvalue]
11
+
12
+ Browser.b.send_keys :"#{special_key}"
13
+ sleep 1
14
+ Report.results.puts("Browser Sent key: :#{special_key} successfully")
15
+ true
16
+ rescue StandardError
17
+ Report.results.puts("Browser Failed to Send key: :#{special_key}")
18
+ false
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,40 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class WriteBoxdata < Base
7
+ register :write_box_data
8
+
9
+ def perform(step_attributes)
10
+ box = step_attributes[:testvalue]
11
+ value = step_attributes[:testvalue2]
12
+ locate = step_attributes[:locate]
13
+
14
+ found_box = [
15
+ Browser.b.textarea(:"#{locate}" => box).exist?,
16
+ Browser.b.text_field(:"#{locate}" => box).exist?
17
+ ]
18
+
19
+ raise 'Multiple matches' if found_box.select { |i| i }.empty?
20
+ index = found_box.index(true)
21
+ return unless index
22
+ if index.zero?
23
+ Browser.b.textarea(:"#{locate}" => box).wait_until_present.set value
24
+ (Browser.b.textarea(:"#{locate}" => box).value == value)
25
+ elsif index == 1
26
+ Browser.b.text_field(:"#{locate}" => box).wait_until_present.set value
27
+ (Browser.b.text_field(:"#{locate}" => box).value == value)
28
+ end
29
+ Report.results.puts("Textbox: #{box} has correct value: #{value}")
30
+ true
31
+ rescue StandardError
32
+ Report.results.puts("Textbox: #{box} has the incorrect value: #{value}")
33
+ false
34
+ rescue StandardError
35
+ Report.results.puts("Textbox: #{box} does not exist")
36
+ false
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'base_handler'
2
+ # require './taf_config.rb'
3
+
4
+ module TestSteps
5
+ module Handlers
6
+ class WriteToEditor < Base
7
+ register :write_to_editor
8
+
9
+ def perform(step_attributes)
10
+ iframe = step_attributes[:testvalue]
11
+ value = step_attributes[:testvalue2]
12
+ locate = step_attributes[:locate]
13
+
14
+ Browser.b.iframe(:"#{locate}" => iframe).wait_until_present
15
+ Browser.b.iframe(:"#{locate}" => iframe).send_keys value
16
+ Report.results.puts("Editor box: #{iframe} has correct value: #{value}")
17
+ true
18
+ rescue StandardError
19
+ Report.results.puts("Editor box: #{iframe} has wrong value: #{value}")
20
+ false
21
+ rescue StandardError
22
+ Report.results.puts("Editor box: #{iframe} does not exist")
23
+ false
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,74 @@
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
+ # main.rb - Framework Driver Script
10
+ module Main
11
+ require_relative './taf_config.rb'
12
+
13
+ begin
14
+ # holds list of test file names read from the input file
15
+ test_file_names = []
16
+
17
+ # variables to manage the failure reporting
18
+ $testStepPasses = 0
19
+ $testStepFailures = 0
20
+ $testStepNotrun = 0
21
+ $totalTestPasses = 0
22
+ $totalTestFailures = 0
23
+ $totalTestNotrun = 0
24
+ $previousTestFail = false
25
+ $currentTestFail = false
26
+ # initialised stores for the input xlsx test data
27
+ $XlsxDoc = ''
28
+
29
+ begin
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
+ puts 'Only one argument needed: {TestSuite File}'
36
+ elsif ARGV.length < 3
37
+ $testSuiteFile = ARGV[0]
38
+ $browserType = ARGV[1]
39
+ puts 'Only 2 arguments needed: {TestSuite File} {Browser}'
40
+ elsif ARGV.length < 4
41
+ $testSuiteFile = ARGV[0]
42
+ $browserType = ARGV[1]
43
+ $securityTest = ARGV[2]
44
+ puts 'Only 3 arguments needed: {TestSuite File} {Browser} {Security test}'
45
+ else
46
+ # unable to open file as not supplied as command-line parameter
47
+ $testSuiteFile = 'unknown'
48
+ error_to_display = 'Test File has not been supplied as a command-line parameter as expected'
49
+ raise IOError, error_to_display
50
+ end
51
+
52
+ # Get the test suite data
53
+ Parser.read_test_suite_data
54
+
55
+ # unable to read the test file then handle the error and terminate
56
+ rescue StandardError => error
57
+ warn error
58
+ $stdout.puts error
59
+ abort
60
+ end
61
+
62
+ puts "There are: #{$numberOfTestSpecs} test files to process \n"
63
+
64
+ # process the test files to execute the tests
65
+ TestEngine.process_testfiles
66
+
67
+ # get the overall test end time
68
+ $test_end_time = Report.current_time
69
+
70
+ # output the overall test summary
71
+ ReportSummary.print_overall_test_summary
72
+ JunitReport.test_summary_junit
73
+ end
74
+ end
@@ -0,0 +1,87 @@
1
+ # Created on 02 Aug 2018
2
+ # @author: Andy Perrett
3
+ #
4
+ # Versions:
5
+ # 1.0 - Baseline
6
+ #
7
+ # parser.rb - basic parser functions
8
+ module Parser
9
+ require_relative '../taf_config.rb'
10
+ # variables:
11
+ @XlsxFileNameType = '.xlsx'
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
+ puts "\nProcessing 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
56
+ end
57
+
58
+ # readTestData
59
+ def self.read_test_data(testFileName)
60
+ # get the file type
61
+ fileType = File.extname(testFileName)
62
+ if (fileType.casecmp(@XlsxFileNameType) == 0)
63
+ puts "Processing test file: #{testFileName}"
64
+ puts "Browser Type: #{$browserType}"
65
+ puts "Security Test: #{$securityTest}"
66
+ $xlsxDoc = RubyXL::Parser.parse(testFileName)
67
+ XlsxParser.parse_xlxs_test_header_data
68
+ return 'XLSX'
69
+ else
70
+ # if unable to read the test file list then construct a custom error
71
+ # message and raise an exception.
72
+ error_to_display = "Test File Name: '#{testFileName}' " \
73
+ "type not recognised (must be .xslx)"
74
+ raise IOError, error_to_display
75
+ end
76
+
77
+ # if an error occurred reading the test file list then
78
+ # re-raise the exception.
79
+ rescue StandardError => error
80
+ raise IOError, error
81
+ end
82
+
83
+ # parseTestStepData
84
+ def self.parse_test_step_data(testFileType)
85
+ XlsxParser.parse_test_step_data(testFileType)
86
+ end
87
+ end