taf 0.3.7 → 0.3.8

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 (83) hide show
  1. checksums.yaml +4 -4
  2. data/bin/taf +23 -2
  3. data/lib/taf.rb +48 -0
  4. data/lib/taf/browser.rb +103 -0
  5. data/lib/taf/cmd_line.rb +74 -0
  6. data/lib/taf/create_directories.rb +53 -0
  7. data/lib/taf/json_parser.rb +48 -0
  8. data/lib/taf/junit_report.rb +73 -0
  9. data/lib/taf/my_log.rb +21 -0
  10. data/lib/taf/parser.rb +37 -0
  11. data/lib/taf/report.rb +110 -0
  12. data/lib/taf/report_summary.rb +56 -0
  13. data/lib/taf/screenshot.rb +30 -0
  14. data/lib/taf/test_engine.rb +82 -0
  15. data/lib/taf/test_steps.rb +38 -0
  16. data/lib/taf/test_steps/handlers/base.rb +90 -0
  17. data/lib/taf/test_steps/handlers/base/browser_back.rb +21 -0
  18. data/lib/taf/test_steps/handlers/base/browser_forward.rb +21 -0
  19. data/lib/taf/test_steps/handlers/base/browser_open.rb +21 -0
  20. data/lib/taf/test_steps/handlers/base/browser_quit.rb +21 -0
  21. data/lib/taf/test_steps/handlers/base/browser_refresh.rb +21 -0
  22. data/lib/taf/test_steps/handlers/base/capture_alert.rb +22 -0
  23. data/lib/taf/test_steps/handlers/base/check_box.rb +22 -0
  24. data/lib/taf/test_steps/handlers/base/check_boxdata.rb +35 -0
  25. data/lib/taf/test_steps/handlers/base/check_browser_title.rb +21 -0
  26. data/lib/taf/test_steps/handlers/base/check_logs.rb +25 -0
  27. data/lib/taf/test_steps/handlers/base/check_screendata.rb +23 -0
  28. data/lib/taf/test_steps/handlers/base/check_url.rb +22 -0
  29. data/lib/taf/test_steps/handlers/base/click_button.rb +33 -0
  30. data/lib/taf/test_steps/handlers/base/execute_system_command.rb +23 -0
  31. data/lib/taf/test_steps/handlers/base/handle_browser_window.rb +23 -0
  32. data/lib/taf/test_steps/handlers/base/ipause.rb +21 -0
  33. data/lib/taf/test_steps/handlers/base/list_all_dropdowns_values.rb +23 -0
  34. data/lib/taf/test_steps/handlers/base/login.rb +59 -0
  35. data/lib/taf/test_steps/handlers/base/open_url.rb +22 -0
  36. data/lib/taf/test_steps/handlers/base/ping_test.rb +27 -0
  37. data/lib/taf/test_steps/handlers/base/radio_button.rb +24 -0
  38. data/lib/taf/test_steps/handlers/base/select_dropdown.rb +24 -0
  39. data/lib/taf/test_steps/handlers/base/send_special_keys.rb +22 -0
  40. data/lib/taf/test_steps/handlers/base/write_box_data.rb +35 -0
  41. data/lib/taf/version.rb +5 -0
  42. metadata +41 -43
  43. data/lib/functions/handlers.rb +0 -6
  44. data/lib/functions/handlers/base_handler.rb +0 -91
  45. data/lib/functions/handlers/browser_back.rb +0 -21
  46. data/lib/functions/handlers/browser_forward.rb +0 -21
  47. data/lib/functions/handlers/browser_quit.rb +0 -21
  48. data/lib/functions/handlers/browser_refresh.rb +0 -21
  49. data/lib/functions/handlers/capture_alert.rb +0 -22
  50. data/lib/functions/handlers/check_box.rb +0 -21
  51. data/lib/functions/handlers/check_boxdata.rb +0 -35
  52. data/lib/functions/handlers/check_browser_title.rb +0 -21
  53. data/lib/functions/handlers/check_logs.rb +0 -23
  54. data/lib/functions/handlers/check_screendata.rb +0 -21
  55. data/lib/functions/handlers/check_url.rb +0 -22
  56. data/lib/functions/handlers/click_button.rb +0 -33
  57. data/lib/functions/handlers/execute_system_command.rb +0 -23
  58. data/lib/functions/handlers/handle_browser_window.rb +0 -23
  59. data/lib/functions/handlers/ipause.rb +0 -21
  60. data/lib/functions/handlers/list_all_dropdowns_values.rb +0 -23
  61. data/lib/functions/handlers/login.rb +0 -59
  62. data/lib/functions/handlers/open_url.rb +0 -35
  63. data/lib/functions/handlers/ping_test.rb +0 -27
  64. data/lib/functions/handlers/radio_button.rb +0 -22
  65. data/lib/functions/handlers/select_dropdown.rb +0 -24
  66. data/lib/functions/handlers/send_special_keys.rb +0 -22
  67. data/lib/functions/handlers/write_box_data.rb +0 -35
  68. data/lib/main.rb +0 -31
  69. data/lib/parser/json_parser.rb +0 -50
  70. data/lib/parser/parser.rb +0 -49
  71. data/lib/report/junit_report.rb +0 -74
  72. data/lib/report/report.rb +0 -116
  73. data/lib/report/report_summary.rb +0 -53
  74. data/lib/taf_config.rb +0 -46
  75. data/lib/utils/browser.rb +0 -98
  76. data/lib/utils/cmd_line.rb +0 -71
  77. data/lib/utils/create_directories.rb +0 -50
  78. data/lib/utils/exceptions.rb +0 -7
  79. data/lib/utils/logger.rb +0 -21
  80. data/lib/utils/screenshot.rb +0 -30
  81. data/lib/utils/test_engine.rb +0 -77
  82. data/lib/utils/test_steps.rb +0 -38
  83. data/lib/version.rb +0 -21
data/lib/taf/my_log.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Created on 04 Feb 2019
4
+ # @author: Andy Perrett
5
+ #
6
+ # Versions:
7
+ # 1.0 - Baseline
8
+ module Taf
9
+ # logger.rb - logger file
10
+ # Logger function.
11
+ module MyLog
12
+ def self.log
13
+ if @logger.nil?
14
+ @logger = Logger.new STDOUT
15
+ @logger.level = Logger::DEBUG
16
+ @logger.datetime_format = '%Y-%m-%d %H:%M:%S '
17
+ end
18
+ @logger
19
+ end
20
+ end
21
+ end
data/lib/taf/parser.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Created on 02 Aug 2018
4
+ # @author: Andy Perrett
5
+ #
6
+ # Versions:
7
+ # 1.0 - Baseline
8
+ #
9
+ module Taf
10
+ # parser.rb - basic parser functions
11
+ module Parser
12
+ def self.test_files
13
+ @test_files ||= Dir.glob("#{Taf::CMDLine.tests_folder}/*.json")
14
+ .reject do |file|
15
+ File.basename(file).start_with?('~$')
16
+ end.sort
17
+ end
18
+
19
+ # readTestData
20
+ def self.read_test_data(test_file_name)
21
+ # get the file type
22
+ file_type = File.extname(test_file_name)
23
+ file_type.casecmp('.json').zero?
24
+ Taf::MyLog.log.info "Processing test file: #{test_file_name}"
25
+ json = File.read(test_file_name)
26
+ parse_json = JSON.parse(json)
27
+
28
+ Taf::JSONParser.parse_test_header_data(parse_json)
29
+ parse_json
30
+ end
31
+
32
+ # parseTestStepData
33
+ def self.parse_test_step_data(parse_json)
34
+ Taf::JSONParser.parse_test_step_data(parse_json)
35
+ end
36
+ end
37
+ end
data/lib/taf/report.rb ADDED
@@ -0,0 +1,110 @@
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
+ module Taf
10
+ # report.rb - methods for outputting console.
11
+ module Report
12
+ # get the current time in the format Day - Month - Date - Time (HH:MM:SS)
13
+ def self.current_time
14
+ Time.new.strftime('%a %b %d %H:%M:%S %Z')
15
+ end
16
+
17
+ # print the test Step info to the test results file
18
+ def self.print_test_step_header(test_file_name, test_step_idx, test_desc)
19
+ @test_start_time = current_time
20
+ Taf::MyLog.log.info "Test step: #{test_step_idx} : #{test_desc}"
21
+
22
+ step = { 'id' => test_step_idx,
23
+ 'classname' => "SuiteID: #{Taf::JSONParser.test_id}" \
24
+ " Test Step: #{test_step_idx} #{test_desc}",
25
+ 'name' => test_desc,
26
+ 'file' => test_file_name }
27
+
28
+ # output to console to show test step
29
+ # puts step
30
+
31
+ return unless test_file_name
32
+
33
+ $testStep_xml ||= {}
34
+ $testStep_xml[test_file_name] ||= {}
35
+ $testStep_xml[test_file_name][test_step_idx] = step
36
+ end
37
+
38
+ # print the Pass / Fail status of a test to the test results file
39
+ def self.test_pass_fail(pass_fail, test_file_name, test_step_idx, metrics)
40
+ if pass_fail == true
41
+ @current_test_fail = false
42
+ metrics.stepPasses += 1
43
+ Taf::MyLog.log.info "Test #{test_step_idx} has Passed ".green
44
+ elsif pass_fail == false
45
+ @current_test_fail = true
46
+ metrics.stepFailures += 1
47
+ Taf::MyLog.log.warn "Test #{test_step_idx} has FAILED ".red
48
+ sc_file_name = Taf::Screenshot.save_screenshot(test_step_idx)
49
+ failstep = {
50
+ 'message' => "SuiteID: #{Taf::JSONParser.test_id}" \
51
+ " Test Step: #{test_step_idx} Test has" \
52
+ " FAILED - Check logs, see Screenshot: #{sc_file_name}",
53
+ 'type' => 'FAILURE',
54
+ 'file' => test_file_name
55
+ }
56
+ # output to console to show test step failure
57
+ # puts failstep
58
+
59
+ return unless test_file_name
60
+
61
+ $failtestStep_xml ||= {}
62
+ $failtestStep_xml[test_file_name] ||= []
63
+ $failtestStep_xml[test_file_name][test_step_idx] = failstep
64
+ else
65
+ @current_test_fail = false
66
+ metrics.stepSkipped += 1
67
+ Taf::MyLog.log.info "Test #{test_step_idx} no checks performed ".blue
68
+ skipstep = {
69
+ 'message' => "SuiteID: #{Taf::JSONParser.test_id}" \
70
+ " Test Step: #{test_step_idx} No" \
71
+ ' checks performed - Check logs',
72
+ 'type' => 'SKIPPED',
73
+ 'file' => test_file_name
74
+ }
75
+ # output to console to show test step failure
76
+ # puts skipstep
77
+
78
+ return unless test_file_name
79
+
80
+ $skiptestStep_xml ||= {}
81
+ $skiptestStep_xml[test_file_name] ||= []
82
+ $skiptestStep_xml[test_file_name][test_step_idx] = skipstep
83
+ end
84
+ test_end_time = current_time
85
+
86
+ test_duration = TimeDifference.between(
87
+ test_end_time, @test_start_time
88
+ ).humanize || 0
89
+ Taf::MyLog.log.info "Test step duration: #{test_duration} \n"
90
+ end
91
+
92
+ # check if the test failure threshold has been reached for total failures
93
+ # or consecutive failures.
94
+ # If a certain number of consecutive tests fail then throw an exception
95
+ def self.check_failure_threshold(test_file_name)
96
+ consecutive_fail_threshold = 3
97
+ if @current_test_fail
98
+ @consecutive_test_fail += 1
99
+ else
100
+ @consecutive_test_fail = 0
101
+ end
102
+
103
+ return if @consecutive_test_fail < consecutive_fail_threshold
104
+
105
+ raise Taf::FailureThresholdExceeded,
106
+ "Terminating the current test file: #{test_file_name} as the test" \
107
+ " failure threshold (#{@consecutive_test_fail}) has been reached."
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,56 @@
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
+ module Taf
10
+ # report_summary.rb - methods for writing to the test summary report file
11
+ module ReportSummary
12
+ # holds printable test report summary for all the executed tests
13
+ @test_step_report_summary = []
14
+ # output the test results summary for the current test case
15
+ def self.test_step_summary(test_file_name, test_file_name_index, metrics)
16
+ @test_step_report_summary[test_file_name_index] = <<~TEXT
17
+ Test file executed: #{test_file_name}
18
+ Browser Type: #{Taf::CMDLine.browser_type}
19
+ Browser Version: #{Taf::Browser.browser_version}
20
+ Browser Platform: #{Taf::Browser.browser_platform}
21
+ There are: #{metrics.stepPasses} Passes
22
+ There are: #{metrics.stepFailures} Failures
23
+ There are: #{metrics.stepSkipped} Skipped Tests \n
24
+ TEXT
25
+ end
26
+
27
+ # output the overall test results summary
28
+ def self.print_test_summary
29
+ # output to the console
30
+
31
+ Taf::MyLog.log.info 'Finished processing all test files ' \
32
+ "from the following test folder: #{Taf::CMDLine.tests_folder}"
33
+ Taf::MyLog.log.info "Overall Test Summary: \n"
34
+ @test_step_report_summary.each do |test_step_report_summary|
35
+ test_step_report_summary.each_line do |line|
36
+ Taf::MyLog.log.info(line.strip)
37
+ end
38
+ end
39
+ end
40
+
41
+ # output the overall test results summary
42
+ def self.overall_test_summary(ts_start_time, ts_end_time, total_metrics)
43
+ print_test_summary
44
+ t_time = TimeDifference.between(ts_end_time, ts_start_time).humanize || 0
45
+
46
+ Taf::MyLog.log.info "Total Tests started at: #{ts_start_time}"
47
+ Taf::MyLog.log.info "Total Tests finished at: #{ts_end_time}"
48
+ Taf::MyLog.log.info "Total Tests duration: #{t_time}"
49
+ Taf::MyLog.log.info "Total Tests Passed: #{total_metrics[0]}".green
50
+ Taf::MyLog.log.info "Total Tests Failed: #{total_metrics[1]}".red
51
+ Taf::MyLog.log.info "Total Tests Skipped: #{total_metrics[2]}".blue
52
+ total_tests = [total_metrics[0], total_metrics[1], total_metrics[2]].sum
53
+ Taf::MyLog.log.info "Total Tests: #{total_tests}\n"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Created on 07 May 2019
4
+ # @author: Andy Perrett
5
+ #
6
+ # Versions:
7
+ # 1.0 - Baseline
8
+ #
9
+ module Taf
10
+ # screenshot.rb - a screenshot save function
11
+ module Screenshot
12
+ # create screenshot filename and save the screenshot if the test has failed.
13
+ def self.save_screenshot(test_step_idx)
14
+ time = Time.now.strftime('%H%M')
15
+ sc_dir = Taf::CreateDirectories.construct_testspecdirs
16
+
17
+ sc_file_name = "#{sc_dir}/Test_ID-#{Taf::JSONParser.test_id.delete(' ')}"\
18
+ "_Test_step-#{test_step_idx}_Failed_#{time}.png"
19
+
20
+ # Screenshot capture for websites
21
+ Taf::Browser.b.screenshot.save sc_file_name
22
+ Taf::MyLog.log.info("Screenshot saved to: #{sc_file_name} \n")
23
+ sc_file_name
24
+ rescue StandardError => e
25
+ # construct the error message from custom text and the actual system
26
+ # error message (converted to a string).
27
+ Taf::MyLog.log.warn("Error saving the screenshot: #{sc_file_name} #{e}")
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,82 @@
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
+ module Taf
10
+ # test_engine.rb - controls the iteration through the test suite and specs
11
+ module TestEngine
12
+ # process the test files to execute the tests
13
+ def self.process_testfiles
14
+ total_passes = 0
15
+ total_failures = 0
16
+ total_skipped = 0
17
+
18
+ # loop through all the available test files to execute the tests
19
+ Taf::Parser.test_files.each_with_index do |test_file_name, test_file_idx|
20
+ metrics = Struct.new(:stepPasses, :stepFailures, :stepSkipped)
21
+ .new(0, 0, 0)
22
+
23
+ begin
24
+ # read in the test data
25
+ tests = Taf::Parser.read_test_data(test_file_name)
26
+ # if unable to read the test data, show the error and move onto the
27
+ # next file (if there is one)
28
+ rescue StandardError => e
29
+ Taf::MyLog.log.warn 'Terminating the current test spec: ' \
30
+ "#{test_file_name} #{e}"
31
+ Taf::MyLog.log.info
32
+ '...continuing with the next test file (if there is one)'
33
+ end
34
+
35
+ # create project folders - these only need creating once per test suite
36
+ Taf::CreateDirectories.construct_projectdirs
37
+
38
+ # get the test case start time
39
+ tc_start = Taf::Report.current_time
40
+
41
+ Taf::Browser.open_browser
42
+
43
+ begin
44
+ tests['steps'].each_with_index do |test_step, test_step_idx|
45
+ test_step_idx += 1
46
+
47
+ parsed_steps = Taf::Parser.parse_test_step_data(test_step)
48
+
49
+ # process the test step data
50
+ Taf::TestSteps.process_test_steps(test_file_name, test_step_idx,
51
+ parsed_steps, metrics)
52
+ end
53
+ rescue Taf::TafError => e
54
+ warn e
55
+ Taf::MyLog.log.warn e
56
+ end
57
+
58
+ # get the test case end time
59
+ tc_end = Taf::Report.current_time
60
+
61
+ # output the test results summary for the current test case,
62
+ # pass in the test file number to save the summary against it's
63
+ # testfile
64
+ Taf::ReportSummary.test_step_summary(test_file_name, test_file_idx,
65
+ metrics)
66
+ Taf::JUnitReport.test_step_summary_xml(test_file_name, test_file_idx,
67
+ tc_start, tc_end, metrics)
68
+
69
+ # close the browser if created
70
+ Taf::Browser.b.quit
71
+
72
+ # record total passes and failures and reset the failure counters for
73
+ # the test steps
74
+ total_passes += metrics.stepPasses
75
+ total_failures += metrics.stepFailures
76
+ total_skipped += metrics.stepSkipped
77
+ end
78
+
79
+ [total_passes, total_failures, total_skipped]
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,38 @@
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
+ module Taf
10
+ # test_steps.rb - process the required test step functions
11
+ module TestSteps
12
+ def self.handlers
13
+ @handlers ||= {}
14
+ end
15
+
16
+ # process the test step data by matching the test step functions and
17
+ # processing the associated data accordingly
18
+ def self.process_test_steps(test_file_name, test_step_idx, step_attributes,
19
+ metrics)
20
+ # print the test step information
21
+ Taf::Report.print_test_step_header(test_file_name, test_step_idx,
22
+ step_attributes[:testdesc])
23
+ runtest = step_attributes[:skipTestCase]
24
+ step_function = step_attributes[:testFunction]
25
+ handler = handlers[step_function.to_s]
26
+
27
+ if handler.respond_to?(:perform)
28
+ func = handler.perform(step_attributes) if runtest == false
29
+ Taf::Report.test_pass_fail(func, test_file_name, test_step_idx, metrics)
30
+ Taf::Report.check_failure_threshold(test_file_name)
31
+ return true
32
+ else
33
+ Taf::MyLog.log.warn "\nUnable to match function: #{step_function}"
34
+ raise Taf::UnknownTestStep, "Unknown test step: #{step_function}"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Taf
4
+ # Base Hanfer file to contain all shared login functions
5
+ module TestSteps
6
+ module Handlers
7
+ # All Login functions function.
8
+ class Base
9
+ def initialize(step_attributes)
10
+ @value = step_attributes[:testvalue]
11
+ @value2 = step_attributes[:testvalue2]
12
+ @locate = step_attributes[:locate]
13
+ @locate2 = step_attributes[:locate2]
14
+ end
15
+
16
+ def self.register(name)
17
+ TestSteps.handlers[name.to_s] = self
18
+ end
19
+
20
+ def self.perform(*args)
21
+ new(*args).perform
22
+ end
23
+
24
+ def login_process(b_title, user_elm, pass_elm, user, pass)
25
+ if Taf::Browser.b.title.eql?(b_title)
26
+ Taf::Browser.b.text_field(id: user_elm).wait_until(&:exists?)
27
+ .set user
28
+ Taf::Browser.b.text_field(id: pass_elm).wait_until(&:exists?)
29
+ .set pass
30
+ button = 'Sign in' || 'Log in'
31
+ Taf::Browser.b.button(value: button).wait_until(&:exists?).click
32
+ sleep 1
33
+ else
34
+ Taf::MyLog.log.warn("User: #{user} has failed to log in.")
35
+ end
36
+ end
37
+
38
+ def login_check(b_title_sucess, user)
39
+ if Taf::Browser.b.title.eql?(b_title_sucess)
40
+ Taf::MyLog.log.info("User: #{user} has logged in successful.")
41
+ true
42
+ else
43
+ Taf::MyLog.log.warn("User: #{user} has failed to log in.")
44
+ false
45
+ end
46
+ end
47
+
48
+ def mem_word_check(user, b_title_sucess)
49
+ if Taf::Browser.b.title.eql?('Memorable word')
50
+ portal_mem_word(user, b_title_sucess)
51
+ elsif Taf::Browser.b.title.eql?(b_title_sucess)
52
+ Taf::MyLog.log.info("User: #{user} has logged in successful.")
53
+ true
54
+ else
55
+ Taf::MyLog.log.warn("User: #{user} has failed to log in.")
56
+ false
57
+ end
58
+ end
59
+
60
+ def portal_mem_word(user, b_title_sucess)
61
+ password = ENV['PORTAL_MEM']
62
+ nums = (1..256).to_a
63
+ found_mem_nums = nums.each_with_object([]) do |num_val, mem_word|
64
+ elm_id = "user_memorable_parts_#{num_val}"
65
+ mem_word.push(num_val) if Taf::Browser.b.select(id: elm_id).exist?
66
+ end.compact
67
+
68
+ array_password = password.split('')
69
+ array_password.map!(&:upcase)
70
+
71
+ found_mem_nums.each do |mem_num|
72
+ char = array_password[(mem_num - 1)]
73
+ elm_id = "user_memorable_parts_#{mem_num}"
74
+ Taf::Browser.b.select_list(id: elm_id).option(value: char.to_s)
75
+ .select
76
+ end
77
+
78
+ Taf::Browser.b.button(value: 'Sign in').wait_until(&:exists?).click
79
+ if Taf::Browser.b.title.eql?(b_title_sucess)
80
+ Taf::MyLog.log.info("User: #{user} has logged in successful.")
81
+ return true
82
+ else
83
+ Taf::MyLog.log.warn("User: #{user} has failed to log in.")
84
+ return false
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end