awetestlib 0.1.22-x86-mingw32 → 0.1.23-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +7 -0
- data/lib/awetestlib/html_report.rb +15 -44
- data/lib/awetestlib/logging.rb +334 -374
- data/lib/awetestlib/regression/browser.rb +61 -71
- data/lib/awetestlib/regression/drag_and_drop.rb +31 -5
- data/lib/awetestlib/regression/find.rb +21 -139
- data/lib/awetestlib/regression/legacy.rb +1175 -1
- data/lib/awetestlib/regression/runner.rb +10 -6
- data/lib/awetestlib/regression/tables.rb +71 -25
- data/lib/awetestlib/regression/user_input.rb +88 -900
- data/lib/awetestlib/regression/utilities.rb +43 -18
- data/lib/awetestlib/regression/validations.rb +165 -248
- data/lib/awetestlib/regression/waits.rb +180 -94
- data/lib/awetestlib/runner.rb +1 -0
- data/lib/awetestlib.rb +3 -1
- data/lib/version.rb +2 -2
- data/test/create_zoho_account1.rb +1 -1
- data/test/login.xls +0 -0
- data/test/login_1.rb +37 -0
- data/test/login_1a.rb +37 -0
- data/test/login_2.rb +32 -0
- data/test/zoho_exercise.rb +21 -0
- metadata +10 -4
data/lib/awetestlib/logging.rb
CHANGED
@@ -1,425 +1,385 @@
|
|
1
1
|
module Awetestlib
|
2
|
-
|
2
|
+
# Logging and reporting.
|
3
|
+
module Logging
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
# @deprecated
|
6
|
+
def self.included(mod)
|
7
|
+
# puts "RegressionSupport::Logging extended by #{mod}"
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
10
|
+
# Format log message and write to STDOUT. Write to physical log if indicated.
|
11
|
+
# @private
|
12
|
+
# @param [Fixnum] severity Severity level of message. Use constants DEBUG, INFO, WARN, ERROR, FATAL, or UNKNOWN
|
13
|
+
# @param [String] message The message to be placed in the log.
|
14
|
+
# @param [String, Fixnum] tag Indicates the type of message. Valid string values are 'FAIL' and 'PASS'.
|
15
|
+
# Valid number values are 0 to 9.
|
16
|
+
# @param [Fixnum] lnbr the line number in the calling script
|
17
|
+
# @param [Fixnum] addts Obsolete, no longer used.
|
18
|
+
# @param [String] exception Obsolete, no longer used.
|
19
|
+
def log_message(severity, message, tag = '', lnbr = nil, addts = 1, exception=nil)
|
20
|
+
# caller = get_caller(lnbr, exception)
|
21
|
+
|
22
|
+
# @sequence ||= log_properties ? log_properties.fetch('sequence', 0) : 0
|
23
|
+
# @sequence += 1
|
24
|
+
|
25
|
+
t = Time.now.utc
|
26
|
+
@last_t ||= t
|
27
|
+
@last_t = t
|
28
|
+
dt = t.strftime("%H%M%S")
|
29
|
+
mySev = translate_severity(severity)
|
30
|
+
myCaller = get_caller(lnbr) || 'unknown'
|
31
|
+
|
32
|
+
myMsg = "%-8s" % mySev
|
33
|
+
myMsg << '[' + dt + ']:'
|
34
|
+
if tag
|
35
|
+
if tag.is_a? Fixnum
|
36
|
+
tag = '-LVL' + tag.to_s
|
37
|
+
end
|
36
38
|
end
|
39
|
+
myMsg << "[%-5s]:" % tag
|
40
|
+
#myMsg << '[' + t.to_f.to_s + ']:'
|
41
|
+
#myMsg << '[' + myCaller + ']:'
|
42
|
+
#myMsg << "#{get_call_list[-1]}#{get_call_list[-2]} "
|
43
|
+
myMsg << get_call_list_new.to_s
|
44
|
+
myMsg << ' '+message
|
45
|
+
myMsg << " [#{lnbr}] " if lnbr
|
46
|
+
|
47
|
+
@myLog.add(severity, myMsg) if @myLog # add persistent logging for awetestlib. pmn 05jun2012
|
48
|
+
puts myMsg+"\n"
|
49
|
+
|
50
|
+
nil # so method doesn't return whole @output.
|
37
51
|
end
|
38
|
-
myMsg << "[%-5s]:" % tag
|
39
|
-
#myMsg << '[' + t.to_f.to_s + ']:'
|
40
|
-
#myMsg << '[' + myCaller + ']:'
|
41
|
-
#myMsg << "#{get_call_list[-1]}#{get_call_list[-2]} "
|
42
|
-
myMsg << get_call_list_new.to_s
|
43
|
-
myMsg << ' '+message
|
44
|
-
# myMsg << " {#{lnbr}} " if lnbr
|
45
|
-
|
46
|
-
# # TODO This is broken: @myBrowser is not necessarily populated
|
47
|
-
# if @screenCaptureOn and is_browser?(@myBrowser)
|
48
|
-
# if severity >= @options['screenshot'] andand
|
49
|
-
# tag.match(/PASS|FAIL/)
|
50
|
-
# then
|
51
|
-
# capture_screen(@myBrowser, t)
|
52
|
-
# end
|
53
|
-
# end
|
54
|
-
|
55
|
-
@myLog.add(severity, myMsg) if @myLog # add persistent logging for awetestlib. pmn 05jun2012
|
56
|
-
puts myMsg+"\n"
|
57
|
-
|
58
|
-
nil # so method doesn't return whole @output.
|
59
|
-
end
|
60
52
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
53
|
+
#private log_message
|
54
|
+
|
55
|
+
# Translates tag value to corresponding value for +pass+ column in database.
|
56
|
+
# @private
|
57
|
+
# @param [String, Fixnum] tag
|
58
|
+
# @return [String] Single character
|
59
|
+
def pass_code_for(tag)
|
60
|
+
case
|
61
|
+
when tag =~ /PASS/
|
62
|
+
'P'
|
63
|
+
when tag =~ /FAIL/
|
64
|
+
'F'
|
65
|
+
#when tag =~ /\d+/ # avoid having to require andand for awetestlib. pmn 05jun2012
|
66
|
+
when tag.andand.is_a?(Fixnum)
|
67
|
+
'H'
|
68
|
+
when tag =~ /DONE/
|
69
|
+
'D'
|
70
|
+
when tag =~ /role/
|
71
|
+
'R'
|
72
|
+
end
|
80
73
|
end
|
81
|
-
end
|
82
74
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
75
|
+
# @private
|
76
|
+
def log_sikuli_output(output_file, passed)
|
77
|
+
output_lines = File.open(output_file, 'r') { |f| f.readlines }
|
78
|
+
puts "IM FAILING?! #{passed}"
|
79
|
+
|
80
|
+
# if passed
|
81
|
+
|
82
|
+
log_messages = ['[log]', '[error]']
|
83
|
+
output_lines = output_lines.select { |l| log_messages } #.detect{|msg| l.include?(msg)} }
|
84
|
+
while line = output_lines.shift do
|
85
|
+
puts "line to be logged: #{line}"
|
86
|
+
if line.include? '[log]'
|
87
|
+
passed_to_log line
|
88
|
+
elsif line.include? '[error]'
|
89
|
+
failed_to_log line
|
90
|
+
elsif line.match /\s*Exception/
|
91
|
+
failed_to_log output_lines.join("\n")
|
92
|
+
break
|
93
|
+
else
|
94
|
+
debug_tolog line
|
95
|
+
end
|
102
96
|
end
|
103
|
-
end
|
104
97
|
|
105
|
-
|
106
|
-
|
107
|
-
|
98
|
+
# else
|
99
|
+
# failed_to_log "SIKULI LOG:\n\n #{output_lines.join('\n')}"
|
100
|
+
# end
|
108
101
|
|
109
|
-
|
110
|
-
|
102
|
+
return { :result => passed, :msg => output_str }
|
103
|
+
end
|
111
104
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
105
|
+
# Put status message to the log and output window
|
106
|
+
# TODO: figure out a way to do the leveling automatically based on actual call depth within script (and project library?)
|
107
|
+
# When using to mark test groupings, include
|
108
|
+
# level 'lvl' (numeric literal, 1 through 9, usually 1-4)
|
109
|
+
# indicating test grouping hierarchy:
|
110
|
+
# 0 lowest level test case, a single validation
|
111
|
+
# a.k.a TEST CASE, VALIDATION
|
112
|
+
# not normally used in scripts as it is
|
113
|
+
# implied by method with 'validate' in name
|
114
|
+
# 1 group of closely related level 0 validations
|
115
|
+
# a.k.a TEST GROUP
|
116
|
+
# should never be followed by another level 1
|
117
|
+
# or higher level message without intervening
|
118
|
+
# level 0 validations.
|
119
|
+
# 2 group of closely related level 1 validation sets.
|
120
|
+
# a.k.a TEST SET, SUBMODULE, USE CASE
|
121
|
+
# should never be followed by another level 2
|
122
|
+
# or higher level message without intervening
|
123
|
+
# lower levels.
|
124
|
+
# 3 group of closely related level 2 validation sets.
|
125
|
+
# a.k.a TEST SET, TEST SUITE, MODULE, USE CASE
|
126
|
+
# should never be followed by another level 3
|
127
|
+
# or higher level message without intervening
|
128
|
+
# lower levels.
|
129
|
+
# 4 group of closely related level 3 validation sets.
|
130
|
+
# a.k.a TEST SUITE, APPLICATION UNDER TEST, PLAN, PROJECT
|
131
|
+
# should never be followed by another level 4
|
132
|
+
# or higher level message without intervening
|
133
|
+
# lower levels. Will seldom appear directly in
|
134
|
+
# scripts
|
135
|
+
|
136
|
+
# Write a status message to the log and report indicating location or activity
|
137
|
+
# in the script.
|
138
|
+
# @param [String] message The text to place in the log and report
|
139
|
+
# @param [Fixnum] lvl A number from 0 to 9 to roughly indicate call level within
|
140
|
+
# the script. '0' forces a message to the report without a specific level attached.
|
141
|
+
# @param [String] desc Any additional information to add to the message.
|
142
|
+
# @param [Boolean] dbg When set to true adds a trace to the message.
|
143
|
+
# @return [void]
|
144
|
+
def mark_testlevel(message, lvl, desc = '', dbg = nil)
|
145
|
+
strg = ''
|
146
|
+
strg << message
|
147
|
+
strg << " [#{desc}]" if desc.length > 0
|
148
|
+
strg << " #{get_debug_list}" if dbg or @debug_calls
|
149
|
+
@report_class.add_to_report(strg, " ", lvl)
|
150
|
+
log_message(INFO, strg, lvl, 1)
|
151
|
+
rescue
|
152
|
+
failed_to_log("#{__method__}: #{$!}")
|
153
|
+
end
|
157
154
|
|
158
|
-
|
155
|
+
alias mark_test_level mark_testlevel
|
159
156
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
log_message(INFO, message, nil, lnbr)
|
166
|
-
end
|
157
|
+
# @param [String] message The text to place in the log
|
158
|
+
# @return [void]
|
159
|
+
def info_to_log(message, lnbr = nil)
|
160
|
+
log_message(INFO, message, nil, lnbr)
|
161
|
+
end
|
167
162
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
=begin rdoc
|
173
|
-
category: Logging
|
174
|
-
tags: log, debug
|
175
|
-
=end
|
176
|
-
def debug_to_log(message, lnbr = __LINE__, dbg = false)
|
177
|
-
message << " \n#{get_debug_list}" if dbg or @debug_calls # and not @debug_calls_fail_only)
|
178
|
-
log_message(DEBUG, "#{message}", nil, lnbr)
|
179
|
-
end
|
163
|
+
alias message_tolog info_to_log
|
164
|
+
alias message_to_log info_to_log
|
165
|
+
alias info_tolog info_to_log
|
180
166
|
|
181
|
-
|
167
|
+
# @param [String] message The text to place in the log and report
|
168
|
+
# @return [void]
|
169
|
+
def debug_to_log(message, lnbr = nil, dbg = false)
|
170
|
+
message << "\n#{get_debug_list}" if dbg or @debug_calls # and not @debug_calls_fail_only)
|
171
|
+
log_message(DEBUG, "#{message}", nil, lnbr)
|
172
|
+
end
|
182
173
|
|
183
|
-
|
184
|
-
category: Logging
|
185
|
-
tags: log, error
|
186
|
-
Do not use for failed validations.
|
187
|
-
=end
|
188
|
-
def error_to_log(message, lnbr = __LINE__)
|
189
|
-
log_message(ERROR, message, nil, lnbr)
|
190
|
-
end
|
174
|
+
alias debug_tolog debug_to_log
|
191
175
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
def passed_to_log(message, lnbr = __LINE__, dbg = false)
|
199
|
-
message << " \n#{get_debug_list}" if dbg or @debug_calls # and not @debug_calls_fail_only)
|
200
|
-
@my_passed_count += 1 if @my_passed_count
|
201
|
-
parse_error_references(message)
|
202
|
-
@report_class.add_to_report(message, "PASSED")
|
203
|
-
log_message(INFO, "#{message}", PASS, lnbr)
|
204
|
-
end
|
176
|
+
# @note Do not use for failed validations. Use only for serious error conditions.
|
177
|
+
# @return [void]
|
178
|
+
# @param [String] message The text to place in the log and report
|
179
|
+
def error_to_log(message, lnbr = nil)
|
180
|
+
log_message(ERROR, message, nil, lnbr)
|
181
|
+
end
|
205
182
|
|
206
|
-
|
207
|
-
alias validate_passed_to_log passed_to_log
|
208
|
-
alias passed_tolog passed_to_log
|
209
|
-
alias pass_tolog passed_to_log
|
210
|
-
alias pass_to_log passed_to_log
|
211
|
-
|
212
|
-
=begin rdoc
|
213
|
-
category: Logging
|
214
|
-
tags: log, error, fail, reference, tag, report
|
215
|
-
=end
|
216
|
-
def failed_to_log(message, lnbr = __LINE__, dbg = false)
|
217
|
-
message << " \n#{get_debug_list}" if dbg or @debug_calls or @debug_calls_fail_only
|
218
|
-
@my_failed_count += 1 if @my_failed_count
|
219
|
-
parse_error_references(message, true)
|
220
|
-
@report_class.add_to_report("#{message}" + " [#{get_caller(lnbr)}]","FAILED")
|
221
|
-
log_message(WARN, "#{message}", FAIL, lnbr)
|
222
|
-
end
|
183
|
+
alias error_tolog error_to_log
|
223
184
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
=end
|
234
|
-
def fatal_to_log(message, lnbr = __LINE__, dbg = false)
|
235
|
-
message << " \n#{get_debug_list}" if dbg or (@debug_calls and not @debug_calls_fail_only)
|
236
|
-
@my_failed_count += 1 if @my_failed_count
|
237
|
-
parse_error_references(message, true)
|
238
|
-
debug_to_report("#{__method__}:\n#{dump_caller(lnbr)}")
|
239
|
-
log_message(FATAL, "#{message} (#{lnbr})", FAIL, lnbr)
|
240
|
-
end
|
185
|
+
# @param [String] message The text to place in the log and report
|
186
|
+
# @return [void]
|
187
|
+
def passed_to_log(message, lnbr = nil, dbg = false)
|
188
|
+
message << " \n#{get_debug_list}" if dbg or @debug_calls # and not @debug_calls_fail_only)
|
189
|
+
@my_passed_count += 1 if @my_passed_count
|
190
|
+
parse_error_references(message)
|
191
|
+
@report_class.add_to_report(message, "PASSED")
|
192
|
+
log_message(INFO, "#{message}", PASS, lnbr)
|
193
|
+
end
|
241
194
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
195
|
+
alias validate_passed_tolog passed_to_log
|
196
|
+
alias validate_passed_to_log passed_to_log
|
197
|
+
alias passed_tolog passed_to_log
|
198
|
+
alias pass_tolog passed_to_log
|
199
|
+
alias pass_to_log passed_to_log
|
200
|
+
|
201
|
+
# @param [String] message The text to place in the log and report
|
202
|
+
# @return [void]
|
203
|
+
def failed_to_log(message, lnbr = nil, dbg = false)
|
204
|
+
message << " \n#{get_debug_list}" if dbg or @debug_calls or @debug_calls_fail_only
|
205
|
+
@my_failed_count += 1 if @my_failed_count
|
206
|
+
parse_error_references(message, true)
|
207
|
+
@report_class.add_to_report("#{message}" + " [#{get_caller(lnbr)}]", "FAILED")
|
208
|
+
log_message(WARN, "#{message}", FAIL, lnbr)
|
209
|
+
end
|
246
210
|
|
247
|
-
|
211
|
+
alias validate_failed_tolog failed_to_log
|
212
|
+
alias validate_failed_to_log failed_to_log
|
213
|
+
alias failed_tolog failed_to_log
|
214
|
+
alias fail_tolog failed_to_log
|
215
|
+
alias fail_to_log failed_to_log
|
216
|
+
|
217
|
+
# @param [String] message The text to place in the log and report
|
218
|
+
# @return [void]
|
219
|
+
def fatal_to_log(message, lnbr = nil, dbg = false)
|
220
|
+
message << " \n#{get_debug_list}" if dbg or (@debug_calls and not @debug_calls_fail_only)
|
221
|
+
@my_failed_count += 1 if @my_failed_count
|
222
|
+
parse_error_references(message, true)
|
223
|
+
@report_class.add_to_report("#{message}" + " [#{get_caller(lnbr)}]", "FAILED")
|
224
|
+
debug_to_report("#{__method__}:\n#{dump_caller(lnbr)}")
|
225
|
+
log_message(FATAL, "#{message} (#{lnbr})", FAIL, lnbr)
|
226
|
+
end
|
248
227
|
|
249
|
-
|
250
|
-
category: Logging
|
251
|
-
tags: log, report
|
252
|
-
=end
|
253
|
-
def message_to_report(message, dbg = false)
|
254
|
-
mark_testlevel("#{message}", 0, '', dbg)
|
255
|
-
end
|
228
|
+
alias fatal_tolog fatal_to_log
|
256
229
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
mark_testlevel("(DEBUG): \n", 0, "#{message}", dbg)
|
263
|
-
end
|
230
|
+
# @param [String] message The text to place in the log and report
|
231
|
+
# @return [void]
|
232
|
+
def message_to_report(message, dbg = false)
|
233
|
+
mark_testlevel("#{message}", 0, '', dbg)
|
234
|
+
end
|
264
235
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
mySev = 'DEBUG'
|
270
|
-
when severity == 1
|
271
|
-
mySev = 'INFO'
|
272
|
-
when severity == 2
|
273
|
-
mySev = 'WARN'
|
274
|
-
when severity == 3
|
275
|
-
mySev = 'ERROR'
|
276
|
-
when severity == 4
|
277
|
-
mySev = 'FATAL'
|
278
|
-
when severity > 4
|
279
|
-
mySev = 'UNKNOWN'
|
236
|
+
# @param [String] message The text to place in the log and report
|
237
|
+
# @return [void]
|
238
|
+
def debug_to_report(message, dbg = false)
|
239
|
+
mark_testlevel("(DEBUG): ", 0, "#{message}", dbg)
|
280
240
|
end
|
281
|
-
mySev
|
282
|
-
end
|
283
241
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
=
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
242
|
+
# @private
|
243
|
+
# @return [Fixnum] required by logger.
|
244
|
+
def translate_severity(severity)
|
245
|
+
mySev = ''
|
246
|
+
case
|
247
|
+
when severity == 0
|
248
|
+
mySev = 'DEBUG'
|
249
|
+
when severity == 1
|
250
|
+
mySev = 'INFO'
|
251
|
+
when severity == 2
|
252
|
+
mySev = 'WARN'
|
253
|
+
when severity == 3
|
254
|
+
mySev = 'ERROR'
|
255
|
+
when severity == 4
|
256
|
+
mySev = 'FATAL'
|
257
|
+
when severity > 4
|
258
|
+
mySev = 'UNKNOWN'
|
298
259
|
end
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
260
|
+
mySev
|
261
|
+
end
|
262
|
+
|
263
|
+
# @private
|
264
|
+
def get_caller(lnbr=nil, exception=nil)
|
265
|
+
script_name ||= File.basename(script_file)
|
266
|
+
if lnbr && script_type.eql?("Selenium")
|
267
|
+
[script_name, lnbr, 'in run()'].join(":")
|
268
|
+
elsif lnbr && script_type.eql?("MobileNativeApp")
|
269
|
+
[script_name, lnbr, 'in scenario()'].join(":")
|
303
270
|
else
|
304
|
-
|
271
|
+
caller_object = exception ? exception.backtrace : Kernel.caller
|
272
|
+
call_frame = caller_object.detect do |frame|
|
273
|
+
frame.match(/#{script_name}/) or (library && frame.match(/#{library}/))
|
274
|
+
end
|
275
|
+
unless call_frame.nil?
|
276
|
+
call_frame.gsub!(/^C:/, '')
|
277
|
+
file, line, method = call_frame.split(":")
|
278
|
+
[File.basename(file), line, method].join(":")
|
279
|
+
else
|
280
|
+
'unknown'
|
281
|
+
end
|
305
282
|
end
|
306
283
|
end
|
307
|
-
end
|
308
284
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
285
|
+
# @private
|
286
|
+
def init_logger(logFile, scriptName = nil)
|
287
|
+
if File.exist?(logFile)
|
288
|
+
puts "==> Logfile already exists: #{logFile}. Replacing it."
|
289
|
+
begin
|
290
|
+
File.delete(logFile)
|
291
|
+
rescue
|
292
|
+
puts "#{scriptName}: init_logger RESCUE: #{$!}"
|
293
|
+
end
|
316
294
|
end
|
295
|
+
logger = ActiveSupport::BufferedLogger.new(logFile)
|
296
|
+
logger.level = ActiveSupport::BufferedLogger::DEBUG
|
297
|
+
logger.auto_flushing = (true)
|
298
|
+
logger.add(INFO, "#{logFile}\n#{ENV["OS"]}")
|
299
|
+
logger
|
317
300
|
end
|
318
|
-
logger = ActiveSupport::BufferedLogger.new(logFile)
|
319
|
-
logger.level = ActiveSupport::BufferedLogger::DEBUG
|
320
|
-
logger.auto_flushing = (true)
|
321
|
-
logger.add(INFO, "#{logFile}\n#{ENV["OS"]}")
|
322
|
-
logger
|
323
|
-
end
|
324
|
-
|
325
|
-
#private init_logger
|
326
|
-
|
327
|
-
=begin rdoc
|
328
|
-
category: Logging
|
329
|
-
tags: error, fail, reference, tag
|
330
|
-
=end
|
331
|
-
def start_run(ts = nil)
|
332
|
-
@start_timestamp = Time.now unless ts
|
333
|
-
utc_ts = @start_timestamp.getutc
|
334
|
-
loc_tm = "#{@start_timestamp.strftime("%H:%M:%S")} #{@start_timestamp.zone}"
|
335
|
-
debug_to_log(">> Starting #{@myName.titleize}")
|
336
|
-
end
|
337
|
-
|
338
|
-
alias start_to_log start_run
|
339
301
|
|
340
|
-
|
341
|
-
category: Logging
|
342
|
-
tags: log, begin, error, reference, validation, pass, fail, tallies, tag
|
343
|
-
=end
|
344
|
-
def finish_run(ts = nil)
|
345
|
-
timestamp = Time.now unless ts
|
302
|
+
#private init_logger
|
346
303
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
304
|
+
# @private
|
305
|
+
def start_run(ts = nil)
|
306
|
+
@start_timestamp = Time.now unless ts
|
307
|
+
utc_ts = @start_timestamp.getutc
|
308
|
+
loc_tm = "#{@start_timestamp.strftime("%H:%M:%S")} #{@start_timestamp.zone}"
|
309
|
+
mark_testlevel(">> Starting #{@myName.titleize} #{utc_ts} (#{loc_tm})", 0)
|
310
|
+
end
|
353
311
|
|
354
|
-
|
355
|
-
|
356
|
-
|
312
|
+
alias start_to_log start_run
|
313
|
+
|
314
|
+
# @private
|
315
|
+
# Tally and report duration, validation and failure counts, and end time for the script.
|
316
|
+
# @param [DateTime] ts Time stamp indicating the time the script completed.
|
317
|
+
def finish_run(ts = nil)
|
318
|
+
tally_error_references
|
319
|
+
timestamp = Time.now unless ts
|
320
|
+
mark_testlevel(">> Duration: #{sec2hms(timestamp - @start_timestamp)}", 0)
|
321
|
+
mark_testlevel(">> Validations: #{@my_passed_count + @my_failed_count} | "+
|
322
|
+
"Fails: #{@my_failed_count}", 0) if @my_passed_count and @my_failed_count
|
323
|
+
utc_ts = timestamp.getutc
|
324
|
+
loc_tm = "#{timestamp.strftime("%H:%M:%S")} #{timestamp.zone}"
|
325
|
+
debug_to_log(">> End #{@myName.titleize} #{utc_ts} (#{loc_tm})")
|
357
326
|
|
358
|
-
|
327
|
+
end
|
359
328
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
=
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
@my_error_hits.each_key do |ref|
|
373
|
-
mark_testlevel("#{ref} - #{@my_error_hits[ref]}", 0)
|
329
|
+
alias finish_to_log finish_run
|
330
|
+
|
331
|
+
# @private
|
332
|
+
def tally_error_references(list_tags = @report_all_refs)
|
333
|
+
tags_tested = 0
|
334
|
+
tags_hit = 0
|
335
|
+
if @my_error_hits and @my_error_hits.length > 0
|
336
|
+
mark_testlevel(">> Tagged Error Hits:", 0)
|
337
|
+
tags_hit = @my_error_hits.length
|
338
|
+
@my_error_hits.each_key do |ref|
|
339
|
+
mark_testlevel("#{ref} - #{@my_error_hits[ref]}", 0)
|
340
|
+
end
|
374
341
|
end
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
342
|
+
if list_tags
|
343
|
+
if @my_error_references and @my_error_references.length > 0
|
344
|
+
mark_testlevel(">> Error and Test Case Tags:", 0)
|
345
|
+
tags_tested = @my_error_references.length
|
346
|
+
@my_error_references.each_key do |ref|
|
347
|
+
mark_testlevel("#{ref} - #{@my_error_references[ref]}", 0)
|
348
|
+
end
|
349
|
+
mark_testlevel(">> Fails were hit on #{tags_hit} of #{tags_tested} error/test case references", 0)
|
350
|
+
else
|
351
|
+
mark_testlevel(">> No Error or Test Case References found.", 0)
|
382
352
|
end
|
383
|
-
mark_testlevel("Fails were hit on #{tags_hit} of #{tags_tested} error/test case references", 0)
|
384
|
-
else
|
385
|
-
mark_testlevel("No Error or Test Case References found.", 0)
|
386
353
|
end
|
387
354
|
end
|
388
|
-
end
|
389
355
|
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
capture_error_reference($1, fail)
|
398
|
-
msg.sub!($1, '')
|
356
|
+
# @private
|
357
|
+
def parse_error_references(message, fail = false)
|
358
|
+
msg = message.dup
|
359
|
+
while msg =~ /(\*\*\*\s+[\w\d_\s,-:;\?]+\s+\*\*\*)/
|
360
|
+
capture_error_reference($1, fail)
|
361
|
+
msg.sub!($1, '')
|
362
|
+
end
|
399
363
|
end
|
400
|
-
end
|
401
364
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
=
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
365
|
+
# @private
|
366
|
+
def capture_error_reference(ref, fail)
|
367
|
+
if fail
|
368
|
+
@my_error_hits = Hash.new unless @my_error_hits
|
369
|
+
if @my_error_hits[ref]
|
370
|
+
@my_error_hits[ref] += 1
|
371
|
+
else
|
372
|
+
@my_error_hits[ref] = 1
|
373
|
+
end
|
374
|
+
#debug_to_report("#{__method__}: error hits:\n#{@my_error_hits.to_yaml}")
|
375
|
+
end
|
376
|
+
@my_error_references = Hash.new unless @my_error_references
|
377
|
+
if @my_error_references[ref]
|
378
|
+
@my_error_references[ref] += 1
|
411
379
|
else
|
412
|
-
@
|
380
|
+
@my_error_references[ref] = 1
|
413
381
|
end
|
414
|
-
#debug_to_report("#{__method__}: error hits:\n#{@my_error_hits.to_yaml}")
|
415
|
-
end
|
416
|
-
@my_error_references = Hash.new unless @my_error_references
|
417
|
-
if @my_error_references[ref]
|
418
|
-
@my_error_references[ref] += 1
|
419
|
-
else
|
420
|
-
@my_error_references[ref] = 1
|
421
382
|
end
|
422
|
-
end
|
423
383
|
|
424
|
-
end
|
384
|
+
end
|
425
385
|
end
|