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.
- checksums.yaml +7 -0
- data/bin/taf +4 -0
- data/lib/functions/handlers.rb +4 -0
- data/lib/functions/handlers/base_handler.rb +89 -0
- data/lib/functions/handlers/browser_back.rb +19 -0
- data/lib/functions/handlers/browser_forward.rb +19 -0
- data/lib/functions/handlers/browser_quit.rb +19 -0
- data/lib/functions/handlers/browser_refresh.rb +19 -0
- data/lib/functions/handlers/capture_alert.rb +20 -0
- data/lib/functions/handlers/check_box.rb +22 -0
- data/lib/functions/handlers/check_boxdata.rb +40 -0
- data/lib/functions/handlers/check_browser_title.rb +23 -0
- data/lib/functions/handlers/check_logs.rb +24 -0
- data/lib/functions/handlers/check_screendata.rb +23 -0
- data/lib/functions/handlers/check_url.rb +22 -0
- data/lib/functions/handlers/click_button.rb +53 -0
- data/lib/functions/handlers/execute_system_command.rb +23 -0
- data/lib/functions/handlers/handle_browser_window.rb +23 -0
- data/lib/functions/handlers/insert_value_config.rb +28 -0
- data/lib/functions/handlers/ipause.rb +21 -0
- data/lib/functions/handlers/list_all_dropdowns_values.rb +24 -0
- data/lib/functions/handlers/login.rb +25 -0
- data/lib/functions/handlers/open_portal_url.rb +25 -0
- data/lib/functions/handlers/open_url.rb +26 -0
- data/lib/functions/handlers/ping_test.rb +28 -0
- data/lib/functions/handlers/radio_button.rb +25 -0
- data/lib/functions/handlers/select_dropdown.rb +28 -0
- data/lib/functions/handlers/send_special_keys.rb +22 -0
- data/lib/functions/handlers/write_box_data.rb +40 -0
- data/lib/functions/handlers/write_to_editor.rb +27 -0
- data/lib/main.rb +74 -0
- data/lib/parser/parser.rb +87 -0
- data/lib/parser/xlsx_parser.rb +126 -0
- data/lib/report/junit_report.rb +68 -0
- data/lib/report/report.rb +155 -0
- data/lib/report/report_summary.rb +78 -0
- data/lib/taf_config.rb +37 -0
- data/lib/utils/browser.rb +140 -0
- data/lib/utils/create_directories.rb +94 -0
- data/lib/utils/exceptions.rb +7 -0
- data/lib/utils/test_engine.rb +164 -0
- data/lib/utils/test_steps.rb +39 -0
- data/lib/utils/zap.rb +131 -0
- data/lib/version.rb +21 -0
- metadata +301 -0
@@ -0,0 +1,140 @@
|
|
1
|
+
# Created on 02 Aug 2018
|
2
|
+
# @author: Andy Perrett
|
3
|
+
#
|
4
|
+
# Versions:
|
5
|
+
# 1.0 - Baseline
|
6
|
+
#
|
7
|
+
# browser_setup.rb - a browser functions
|
8
|
+
module Browser
|
9
|
+
require_relative '../taf_config.rb'
|
10
|
+
# open_browser function
|
11
|
+
def self.open_browser
|
12
|
+
lc_browser_type = $browserType.downcase
|
13
|
+
case lc_browser_type
|
14
|
+
when 'chrome'
|
15
|
+
chrome
|
16
|
+
when 'chrome-headless'
|
17
|
+
chrome_headless
|
18
|
+
when 'firefox'
|
19
|
+
firefox
|
20
|
+
when 'firefox-headless'
|
21
|
+
firefox_headless
|
22
|
+
when 'ie'
|
23
|
+
ie
|
24
|
+
when 'safari'
|
25
|
+
safari
|
26
|
+
else
|
27
|
+
puts "unable to open selected browser: #{lc_browser_type}"
|
28
|
+
raise BrowserFailedOpen
|
29
|
+
end
|
30
|
+
rescue BrowserFailedOpen => error
|
31
|
+
# construct the error message from custom text and the actual system error
|
32
|
+
# message (converted to a string)
|
33
|
+
error_text = "Unable to open"\
|
34
|
+
"the requested browser: #{lc_browser_type} " + error.to_s
|
35
|
+
raise error_text
|
36
|
+
end
|
37
|
+
|
38
|
+
# chrome browser details
|
39
|
+
def self.chrome
|
40
|
+
@browser = Watir::Browser.new :chrome, switches: %w[
|
41
|
+
--acceptInsecureCerts-true --start-maximized --window-size=1920,1080
|
42
|
+
]
|
43
|
+
browser_version
|
44
|
+
end
|
45
|
+
|
46
|
+
# chrome headless browser details
|
47
|
+
def self.chrome_headless
|
48
|
+
@browser = Watir::Browser.new :chrome, switches: %w[
|
49
|
+
--start-maximized --disable-gpu --headless --acceptInsecureCerts-true
|
50
|
+
--no-sandbox --window-size=1920,1080
|
51
|
+
]
|
52
|
+
browser_version
|
53
|
+
end
|
54
|
+
|
55
|
+
# firefox browser details
|
56
|
+
def self.firefox
|
57
|
+
caps = Selenium::WebDriver::Remote::Capabilities.firefox
|
58
|
+
caps['acceptInsecureCerts'] = true
|
59
|
+
driver = Selenium::WebDriver.for(:firefox, desired_capabilities: caps)
|
60
|
+
@browser = Watir::Browser.new(driver)
|
61
|
+
browser_full_screen
|
62
|
+
browser_version
|
63
|
+
end
|
64
|
+
|
65
|
+
# firefox headless browser details
|
66
|
+
def self.firefox_headless
|
67
|
+
caps = Selenium::WebDriver::Remote::Capabilities.firefox
|
68
|
+
options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless'])
|
69
|
+
caps['acceptInsecureCerts'] = true
|
70
|
+
driver = Selenium::WebDriver.for(:firefox, options: options,
|
71
|
+
desired_capabilities: caps)
|
72
|
+
@browser = Watir::Browser.new(driver)
|
73
|
+
# makes the browser full screen.
|
74
|
+
@browser.driver.manage.window.resize_to(1920, 1200)
|
75
|
+
@browser.driver.manage.window.move_to(0, 0)
|
76
|
+
browser_version
|
77
|
+
# browser
|
78
|
+
end
|
79
|
+
|
80
|
+
# ie browser details
|
81
|
+
def self.ie
|
82
|
+
@browser = Watir::Browser.new :ie
|
83
|
+
browser_full_screen
|
84
|
+
browser_version
|
85
|
+
end
|
86
|
+
|
87
|
+
# sarfari headless browser details
|
88
|
+
def self.safari
|
89
|
+
@browser = Watir::Browser.new :safari
|
90
|
+
browser_full_screen
|
91
|
+
browser_version
|
92
|
+
end
|
93
|
+
|
94
|
+
# makes the browser full screen.
|
95
|
+
def self.browser_full_screen
|
96
|
+
screen_width = @browser.execute_script('return screen.width;')
|
97
|
+
screen_height = @browser.execute_script('return screen.height;')
|
98
|
+
@browser.driver.manage.window.resize_to(screen_width, screen_height)
|
99
|
+
@browser.driver.manage.window.move_to(0, 0)
|
100
|
+
end
|
101
|
+
|
102
|
+
# define browser value
|
103
|
+
def self.b
|
104
|
+
browser = @browser
|
105
|
+
end
|
106
|
+
|
107
|
+
# Check browser version
|
108
|
+
def self.browser_version
|
109
|
+
browserversion = @browser.driver.capabilities[:version]
|
110
|
+
rescue StandardError
|
111
|
+
browserversion = 'No Browser version'
|
112
|
+
end
|
113
|
+
|
114
|
+
# create screenshot filename and save the screenshot if the test has failed or
|
115
|
+
# if explictly required
|
116
|
+
def self.check_save_screenshot(full_sc_dirname, screen_shot)
|
117
|
+
if ($currentTestFail || screen_shot)
|
118
|
+
time = Time.now.strftime('%H%M')
|
119
|
+
if ($currentTestFail)
|
120
|
+
scFileName = full_sc_dirname + "/Test_step-#{$testStep}_Failed_"\
|
121
|
+
"#{time}.png"
|
122
|
+
else
|
123
|
+
# file name will be teststep.png
|
124
|
+
scFileName = full_sc_dirname + "/Test_step-#{$testStep}_#{time}.png"
|
125
|
+
end
|
126
|
+
|
127
|
+
# Screenshot capture for websites
|
128
|
+
Browser.b.screenshot.save scFileName
|
129
|
+
Report.results.puts("Screenshot saved to: #{scFileName}")
|
130
|
+
else
|
131
|
+
Report.results.puts 'No screenshot requested'
|
132
|
+
end
|
133
|
+
|
134
|
+
# if any issues with saving the screenshot then log a warning
|
135
|
+
rescue StandardError => error
|
136
|
+
# construct the error message from custom text and the actual system
|
137
|
+
# error message (converted to a string).
|
138
|
+
$log.puts("Error saving the screenshot: #{scFileName} #{error.to_s}")
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,94 @@
|
|
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
|
+
# create_directories.rb - Creates folder structures.
|
10
|
+
module CreateDirectories
|
11
|
+
# create the project directories and open the test results file,
|
12
|
+
# returns the screenshot directory name, the screenshot will be placed in a
|
13
|
+
# unique filename based upon the testStep.
|
14
|
+
# A single top-level directory named after the Project ID will be used and the
|
15
|
+
# target sub-directories will be created for each run of the test
|
16
|
+
#
|
17
|
+
# ----> Project directory (working directory)
|
18
|
+
#
|
19
|
+
# ------->directory named after the test run number
|
20
|
+
#
|
21
|
+
# ---------->directory named after test_id (with browser type identified)
|
22
|
+
#
|
23
|
+
# ------------->directory named 'Test_Results'
|
24
|
+
#
|
25
|
+
# ------------->directory named 'Screenshots'
|
26
|
+
|
27
|
+
def self.construct_projectdirs
|
28
|
+
# create top-level 'Results' directory if it doesn't already exist
|
29
|
+
result_home = 'Results'
|
30
|
+
Dir.mkdir(result_home) unless File.directory? result_home
|
31
|
+
|
32
|
+
# create the 'Project' directory if it doesn't already exist
|
33
|
+
project_id = $projectId.delete(' ')
|
34
|
+
project_iddir = result_home + '/' + project_id
|
35
|
+
Dir.mkdir(project_iddir) unless File.directory? project_iddir
|
36
|
+
|
37
|
+
# Creates a folder Ran_on_Time with the time as of now.
|
38
|
+
time = Time.new
|
39
|
+
f_date = time.strftime('%d-%b-%Y')
|
40
|
+
f_time = time.strftime('%H_%M_%S')
|
41
|
+
$runNoDir = project_iddir + '/' + 'Ran_on_' + f_date + '_' + f_time
|
42
|
+
Dir.mkdir($runNoDir)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.construct_testspecdirs
|
46
|
+
# create directories for each test spec
|
47
|
+
# create a sub-directory named from the 'testId' (with any spaces taken out)
|
48
|
+
# if it doesn't already exist plus the browser type
|
49
|
+
testid_dir = $runNoDir + '/' + $testId.delete(' ') + '_' + $browserType.capitalize
|
50
|
+
Dir.mkdir(testid_dir) unless File.directory? testid_dir
|
51
|
+
|
52
|
+
# create a screenshot directory under the 'testId' directory - it will always need creating
|
53
|
+
screenshot_dir = testid_dir + '/' + 'Screenshots' + '/'
|
54
|
+
Dir.mkdir(screenshot_dir)
|
55
|
+
|
56
|
+
# create a test results directory under the 'test run' directory - it will always need creating
|
57
|
+
test_res_dir = testid_dir + '/' + 'Test_Results' + '/'
|
58
|
+
Dir.mkdir(test_res_dir)
|
59
|
+
|
60
|
+
# create absolute paths to the screenshots, test results and test suite summary directories
|
61
|
+
abs_path_screenshot_dir = File.absolute_path(screenshot_dir)
|
62
|
+
abs_path_test_res_dir = File.absolute_path(test_res_dir)
|
63
|
+
abs_path_run_no_dir = File.absolute_path($runNoDir)
|
64
|
+
|
65
|
+
# the test results file name will be 'testId'_Res.txt
|
66
|
+
$testResultFileName = abs_path_test_res_dir + '/' + $testId + '_Res.txt'
|
67
|
+
|
68
|
+
# the test suite summary file name will be 'suite_summary.txt'
|
69
|
+
$testSuiteSummaryFileName = abs_path_run_no_dir + '/suite_summary.txt'
|
70
|
+
|
71
|
+
# the test suite summary is a XML report generated will be called 'suite_summary.xml'
|
72
|
+
time = Time.new
|
73
|
+
f_date = time.strftime('%d-%b-%Y')
|
74
|
+
f_time = time.strftime('%H_%M_%S')
|
75
|
+
|
76
|
+
$TestSuiteSummaryXML = 'Results/' + $projectId + '/' + f_date + '_' + f_time + '_test_result.xml'
|
77
|
+
|
78
|
+
# the log file name will be under the test ID directory
|
79
|
+
$logFileName = testid_dir + '/TestLogFile.txt'
|
80
|
+
|
81
|
+
puts "TestId: #{$testId}"
|
82
|
+
puts "Screenshot directory: #{abs_path_screenshot_dir}"
|
83
|
+
puts "Test result directory: #{abs_path_test_res_dir}"
|
84
|
+
|
85
|
+
# if any issues then set error message and re-raise the exception
|
86
|
+
rescue Exception => error
|
87
|
+
# construct the error message from custom text and the actual system error message (converted to a string)
|
88
|
+
error_to_display = 'Error creating the test directory structure or opening the test results file : ' + error.to_s
|
89
|
+
raise error_to_display
|
90
|
+
else
|
91
|
+
# if no exception then return the screenshot file directory path
|
92
|
+
abs_path_screenshot_dir
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,164 @@
|
|
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
|
+
# test_engine.rb - controls the iteration through the test suite and specs
|
10
|
+
module TestEngine
|
11
|
+
require_relative '../taf_config.rb'
|
12
|
+
|
13
|
+
# process the test files to execute the tests
|
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
|
+
# get the overall test start time
|
21
|
+
$test_start_time = Report.current_time
|
22
|
+
|
23
|
+
# create project folders - these only need creating once per test suite
|
24
|
+
CreateDirectories.construct_projectdirs
|
25
|
+
|
26
|
+
# 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
|
+
$securityTest = test_suite[:securitytest]
|
37
|
+
|
38
|
+
if ARGV.length < 2
|
39
|
+
$browserType = test_suite[:browser]
|
40
|
+
$securityTest = test_suite[:securitytest]
|
41
|
+
puts ''
|
42
|
+
puts "Will use the following browser from Test Suite: #{$browserType}"
|
43
|
+
puts ''
|
44
|
+
elsif ARGV.length < 3
|
45
|
+
$browserType = ARGV[1]
|
46
|
+
$securityTest = ARGV[2]
|
47
|
+
puts "\nWill use the following browser from CMD line: " + ARGV[1]
|
48
|
+
puts ''
|
49
|
+
elsif ARGV.length < 4
|
50
|
+
$securityTest = ARGV[2]
|
51
|
+
puts "\nWill use the following browser from CMD line: " + ARGV[2]
|
52
|
+
puts ''
|
53
|
+
else
|
54
|
+
raise IOError, 'Unable to open browser'
|
55
|
+
end
|
56
|
+
|
57
|
+
# if ARGV.length < 2
|
58
|
+
# $browserType = test_suite[:browser]
|
59
|
+
# puts ''
|
60
|
+
# puts "Will use the following browser from Test Suite: #{$browserType}"
|
61
|
+
# puts ''
|
62
|
+
# elsif ARGV.length < 3
|
63
|
+
# $browserType = ARGV[1]
|
64
|
+
# puts "\nWill use the following browser from CMD line: " + ARGV[1]
|
65
|
+
# puts ''
|
66
|
+
# else
|
67
|
+
# raise IOError, 'Unable to open browser'
|
68
|
+
# end
|
69
|
+
|
70
|
+
# remove any unwanted end-of-line characters from the file name
|
71
|
+
test_file_name = $testSpecDesc
|
72
|
+
|
73
|
+
begin # start of rescue block for readTestData
|
74
|
+
# read in the test data
|
75
|
+
testFileType = Parser.read_test_data(test_file_name)
|
76
|
+
# if unable to read the test data, show the error and move onto the
|
77
|
+
# next file (if there is one)
|
78
|
+
rescue StandardError => error
|
79
|
+
$stderr.puts "Terminating the current test case: " \
|
80
|
+
"#{test_file_name} #{error}"
|
81
|
+
$stderr.puts '...continuing with the next test case (if there is one)'
|
82
|
+
end # of rescue block for readTestData
|
83
|
+
|
84
|
+
# create the project directories, returns the screenshot directory name
|
85
|
+
begin # start of rescue block for construct_projectdirs
|
86
|
+
# create test spec directories - these need creating once per testspec
|
87
|
+
full_sc_dirname = CreateDirectories.construct_testspecdirs
|
88
|
+
# open the log file
|
89
|
+
Report.open_log_file
|
90
|
+
# if an error then show the error and terminate
|
91
|
+
rescue StandardError => error
|
92
|
+
warn error
|
93
|
+
$stdout.puts error
|
94
|
+
abort
|
95
|
+
end
|
96
|
+
|
97
|
+
# open the test results output file
|
98
|
+
Report.open_test_report_file
|
99
|
+
|
100
|
+
# print the main test header
|
101
|
+
Report.print_test_header
|
102
|
+
|
103
|
+
# loop through the test file
|
104
|
+
if testFileType != 'XLSX'
|
105
|
+
puts 'Not a valid XLSX File Type'
|
106
|
+
end
|
107
|
+
|
108
|
+
Report.results.puts("Number of test steps: #{$numberOfTestSteps}")
|
109
|
+
|
110
|
+
# get the test case start time
|
111
|
+
$test_case_start_time = Report.current_time
|
112
|
+
# initialise the test end time
|
113
|
+
$test_case_end_time = Report.current_time
|
114
|
+
|
115
|
+
begin
|
116
|
+
test_steps = Parser.parse_test_step_data(testFileType)
|
117
|
+
|
118
|
+
test_steps.each_with_index do |test_step, index|
|
119
|
+
$testStep = test_step[:testStep]
|
120
|
+
$testStepDes = test_step[:testdesc]
|
121
|
+
screen_shot = test_step[:screenShotData]
|
122
|
+
|
123
|
+
# process the test step data
|
124
|
+
TestSteps.process_test_steps(test_file_name, index, test_step)
|
125
|
+
# see if screenshot required
|
126
|
+
Browser.check_save_screenshot(full_sc_dirname, screen_shot)
|
127
|
+
end
|
128
|
+
rescue TafError => error
|
129
|
+
warn error
|
130
|
+
$log.puts error
|
131
|
+
end
|
132
|
+
|
133
|
+
# get the test case end time
|
134
|
+
$test_case_end_time = Report.current_time
|
135
|
+
|
136
|
+
# output the test results summary for the current test case,
|
137
|
+
# pass in the test file number to save the summary against it's testfile
|
138
|
+
ReportSummary.test_step_summary(test_file_name, test_file_name_index)
|
139
|
+
JunitReport.test_step_summary_xml(test_file_name, test_file_name_index)
|
140
|
+
|
141
|
+
# close the test results file for the current test case
|
142
|
+
Report.close_test_results_file
|
143
|
+
|
144
|
+
# close the log file
|
145
|
+
Report.close_log_file
|
146
|
+
|
147
|
+
# close the browser if created
|
148
|
+
Browser.b.quit
|
149
|
+
|
150
|
+
# increment loop counter to move onto next test file
|
151
|
+
test_file_name_index += 1
|
152
|
+
|
153
|
+
# record total passes and failures and reset the failure counters for
|
154
|
+
# the test steps
|
155
|
+
$totalTestPasses += $testStepPasses
|
156
|
+
$totalTestFailures += $testStepFailures
|
157
|
+
$totalTestNotrun += $testStepNotrun
|
158
|
+
$testStepPasses = 0
|
159
|
+
$testStepFailures = 0
|
160
|
+
$testStepNotrun = 0
|
161
|
+
end
|
162
|
+
end # while loop for test files
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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
|
+
# test_steps.rb - process the required test step functions
|
10
|
+
module TestSteps
|
11
|
+
require_relative '../taf_config.rb'
|
12
|
+
|
13
|
+
def self.handlers
|
14
|
+
@handlers ||= {}
|
15
|
+
end
|
16
|
+
|
17
|
+
# process the test step data by matching the test step functions and
|
18
|
+
# processing the associated data accordingly
|
19
|
+
def self.process_test_steps(test_file_name, teststepindex, step_attributes)
|
20
|
+
# print the test step information
|
21
|
+
Report.print_test_step_header(test_file_name, teststepindex)
|
22
|
+
|
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
|
+
Report.test_pass_fail(func, test_file_name, teststepindex)
|
30
|
+
Report.check_failure_threshold(test_file_name, teststepindex)
|
31
|
+
return true
|
32
|
+
else
|
33
|
+
Report.results.puts("\nUnable to match function: #{step_function}")
|
34
|
+
puts "\nUnable to match function: #{step_function}"
|
35
|
+
raise UnknownTestStep, "Unknown test step: #{step_function}"
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/utils/zap.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# Created on 22 Oct 2018
|
2
|
+
# @author: Andy Perrett
|
3
|
+
#
|
4
|
+
# Versions:
|
5
|
+
# 1.0 - Baseline
|
6
|
+
#
|
7
|
+
# Zap.rb - Zap functions
|
8
|
+
module Zap
|
9
|
+
# require './taf_config.rb'
|
10
|
+
# zap_check function
|
11
|
+
def self.zap_check
|
12
|
+
security_test = $securityTest.downcase
|
13
|
+
case security_test
|
14
|
+
when 'yes'
|
15
|
+
run_zap
|
16
|
+
when 'no'
|
17
|
+
puts "No Security Test required."
|
18
|
+
else
|
19
|
+
puts "unable to run security test: #{security_test}"
|
20
|
+
raise SecurityFailedOpen
|
21
|
+
end
|
22
|
+
rescue SecurityFailedOpen => error
|
23
|
+
# construct the error message from custom text and the actual system error
|
24
|
+
# message (converted to a string)
|
25
|
+
error_text = "unable to run security test: #{security_test} " + error.to_s
|
26
|
+
raise error_text
|
27
|
+
end
|
28
|
+
|
29
|
+
# run zap security test
|
30
|
+
def self.run_zap
|
31
|
+
@browser = Watir::Browser.new :chrome, switches: %w[
|
32
|
+
--acceptInsecureCerts-true --start-maximized --window-size=1920,1080
|
33
|
+
]
|
34
|
+
browser_version
|
35
|
+
end
|
36
|
+
|
37
|
+
# chrome headless browser details
|
38
|
+
def self.chrome_headless
|
39
|
+
@browser = Watir::Browser.new :chrome, switches: %w[
|
40
|
+
--start-maximized --disable-gpu --headless --acceptInsecureCerts-true
|
41
|
+
--no-sandbox --window-size=1920,1080
|
42
|
+
]
|
43
|
+
browser_version
|
44
|
+
end
|
45
|
+
|
46
|
+
# firefox browser details
|
47
|
+
def self.firefox
|
48
|
+
caps = Selenium::WebDriver::Remote::Capabilities.firefox
|
49
|
+
caps['acceptInsecureCerts'] = true
|
50
|
+
driver = Selenium::WebDriver.for(:firefox, desired_capabilities: caps)
|
51
|
+
@browser = Watir::Browser.new(driver)
|
52
|
+
browser_full_screen
|
53
|
+
browser_version
|
54
|
+
end
|
55
|
+
|
56
|
+
# firefox headless browser details
|
57
|
+
def self.firefox_headless
|
58
|
+
caps = Selenium::WebDriver::Remote::Capabilities.firefox
|
59
|
+
options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless'])
|
60
|
+
caps['acceptInsecureCerts'] = true
|
61
|
+
driver = Selenium::WebDriver.for(:firefox, options: options,
|
62
|
+
desired_capabilities: caps)
|
63
|
+
@browser = Watir::Browser.new(driver)
|
64
|
+
# makes the browser full screen.
|
65
|
+
@browser.driver.manage.window.resize_to(1920, 1200)
|
66
|
+
@browser.driver.manage.window.move_to(0, 0)
|
67
|
+
browser_version
|
68
|
+
# browser
|
69
|
+
end
|
70
|
+
|
71
|
+
# ie browser details
|
72
|
+
def self.ie
|
73
|
+
@browser = Watir::Browser.new :ie
|
74
|
+
browser_full_screen
|
75
|
+
browser_version
|
76
|
+
end
|
77
|
+
|
78
|
+
# sarfari headless browser details
|
79
|
+
def self.safari
|
80
|
+
@browser = Watir::Browser.new :safari
|
81
|
+
browser_full_screen
|
82
|
+
browser_version
|
83
|
+
end
|
84
|
+
|
85
|
+
# makes the browser full screen.
|
86
|
+
def self.browser_full_screen
|
87
|
+
screen_width = @browser.execute_script('return screen.width;')
|
88
|
+
screen_height = @browser.execute_script('return screen.height;')
|
89
|
+
@browser.driver.manage.window.resize_to(screen_width, screen_height)
|
90
|
+
@browser.driver.manage.window.move_to(0, 0)
|
91
|
+
end
|
92
|
+
|
93
|
+
# define browser value
|
94
|
+
def self.b
|
95
|
+
browser = @browser
|
96
|
+
end
|
97
|
+
|
98
|
+
# Check browser version
|
99
|
+
def self.browser_version
|
100
|
+
browserversion = @browser.driver.capabilities[:version]
|
101
|
+
rescue StandardError
|
102
|
+
browserversion = 'No Browser version'
|
103
|
+
end
|
104
|
+
|
105
|
+
# create screenshot filename and save the screenshot if the test has failed or
|
106
|
+
# if explictly required
|
107
|
+
def self.check_save_screenshot(full_sc_dirname, screen_shot)
|
108
|
+
if ($currentTestFail || screen_shot)
|
109
|
+
time = Time.now.strftime('%H%M')
|
110
|
+
if ($currentTestFail)
|
111
|
+
scFileName = full_sc_dirname + "/Test_step-#{$testStep}_Failed_"\
|
112
|
+
"#{time}.png"
|
113
|
+
else
|
114
|
+
# file name will be teststep.png
|
115
|
+
scFileName = full_sc_dirname + "/Test_step-#{$testStep}_#{time}.png"
|
116
|
+
end
|
117
|
+
|
118
|
+
# Screenshot capture for websites
|
119
|
+
Browser.b.screenshot.save scFileName
|
120
|
+
Report.results.puts("Screenshot saved to: #{scFileName}")
|
121
|
+
else
|
122
|
+
Report.results.puts 'No screenshot requested'
|
123
|
+
end
|
124
|
+
|
125
|
+
# if any issues with saving the screenshot then log a warning
|
126
|
+
rescue StandardError => error
|
127
|
+
# construct the error message from custom text and the actual system
|
128
|
+
# error message (converted to a string).
|
129
|
+
$log.puts("Error saving the screenshot: #{scFileName} #{error.to_s}")
|
130
|
+
end
|
131
|
+
end
|