awetestlib 0.1.29pre4-x86-mingw32 → 0.1.29-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +123 -123
- data/bin/awetestlib-android-setup.rb +28 -28
- data/bin/awetestlib-cucumber-setup.rb +30 -30
- data/bin/awetestlib-driver-setup.rb +22 -22
- data/bin/awetestlib-helpers.rb +42 -42
- data/bin/awetestlib-mobile-app-setup.rb +32 -32
- data/bin/awetestlib-netbeans-setup.rb +60 -60
- data/bin/awetestlib-regression-setup.rb +30 -30
- data/bin/awetestlib-rubymine-setup.rb +45 -45
- data/lib/awetestlib/logging.rb +366 -366
- data/lib/awetestlib/regression/browser.rb +1378 -1385
- data/lib/awetestlib/regression/drag_and_drop.rb +3 -4
- data/lib/awetestlib/regression/runner.rb +2 -3
- data/lib/awetestlib/regression/tables.rb +9 -17
- data/lib/awetestlib/regression/user_input.rb +1 -1
- data/lib/awetestlib/regression/utilities.rb +24 -82
- data/lib/awetestlib/regression/validations.rb +1075 -1094
- data/lib/version.rb +2 -2
- data/netbeans_setup.md +6 -6
- data/rubymine_setup.md +5 -5
- data/setup_samples/sample_cucumber/features/step_definitions/predefined_steps.rb +354 -354
- metadata +8 -26
- data/images/netbeans1.jpg +0 -0
- data/images/netbeans2.jpg +0 -0
- data/images/netbeans3.jpg +0 -0
- data/images/netbeans4.jpg +0 -0
- data/images/netbeans5.jpg +0 -0
- data/images/rubymine1.jpg +0 -0
- data/images/rubymine2.jpg +0 -0
- data/images/rubymine3.jpg +0 -0
- data/images/rubymine4.jpg +0 -0
- data/images/scripting1.png +0 -0
- data/images/scripting2.png +0 -0
- data/images/scripting3.png +0 -0
- data/images/scripting4.png +0 -0
- data/test/demo_wwd.rb +0 -7
data/lib/awetestlib/logging.rb
CHANGED
@@ -1,366 +1,366 @@
|
|
1
|
-
module Awetestlib
|
2
|
-
# Logging and reporting.
|
3
|
-
module Logging
|
4
|
-
|
5
|
-
# @deprecated
|
6
|
-
def self.included(mod)
|
7
|
-
# puts "RegressionSupport::Logging extended by #{mod}"
|
8
|
-
end
|
9
|
-
|
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
|
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.
|
51
|
-
end
|
52
|
-
|
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
|
73
|
-
end
|
74
|
-
|
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
|
96
|
-
end
|
97
|
-
|
98
|
-
# else
|
99
|
-
# failed_to_log "SIKULI LOG:\n\n #{output_lines.join('\n')}"
|
100
|
-
# end
|
101
|
-
|
102
|
-
return { :result => passed, :msg => output_str }
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
# Write a status message to the log and report indicating location or activity
|
107
|
-
# in the script. mark_test_level automatically determines the call hierarchy level
|
108
|
-
# of the calling method within the script and project utility methods. The top level
|
109
|
-
# method of the script is always level 1. The method also prefixes the calling method
|
110
|
-
# name (titleized) to the message to be placed in the log.
|
111
|
-
# @param [String] message The text to place in the log and report after the titleized
|
112
|
-
# calling method name.
|
113
|
-
# @param [Fixnum] lvl '0' forces a message to the report without a specific level
|
114
|
-
# attached. Any other integer is ignored in favor of the calculated level
|
115
|
-
# @param [String] desc Any additional information to add to the message.
|
116
|
-
# @param [Boolean] dbg When set to true adds a trace to the message.
|
117
|
-
# @return [void]
|
118
|
-
def mark_test_level(message = '', lvl = nil, desc = '', dbg = nil)
|
119
|
-
call_arr = get_call_array()
|
120
|
-
#debug_to_log("#{call_arr.to_yaml}")
|
121
|
-
strg = ''
|
122
|
-
call_script, call_line, call_meth = parse_caller(call_arr[1])
|
123
|
-
if not lvl or lvl > 1
|
124
|
-
lvl, list = get_test_level
|
125
|
-
strg << "#{call_meth.titleize}"
|
126
|
-
end
|
127
|
-
strg << " #{message}" if message.length > 0
|
128
|
-
strg << " (#{desc})" if desc.length > 0
|
129
|
-
strg << " [#{call_line}]"
|
130
|
-
strg << "\n#{list.to_yaml}" if dbg or @debug_calls
|
131
|
-
@report_class.add_to_report(strg, " ", lvl || 1) unless Awetestlib::Runner.nil?
|
132
|
-
log_message(INFO, strg, lvl, nil, 1)
|
133
|
-
rescue
|
134
|
-
failed_to_log("#{__method__}: #{$!}")
|
135
|
-
end
|
136
|
-
|
137
|
-
alias mark_testlevel mark_test_level
|
138
|
-
|
139
|
-
# @param [String] message The text to place in the log
|
140
|
-
# @return [void]
|
141
|
-
def info_to_log(message, lnbr = nil)
|
142
|
-
log_message(INFO, message, 0, lnbr)
|
143
|
-
end
|
144
|
-
|
145
|
-
alias message_tolog info_to_log
|
146
|
-
alias message_to_log info_to_log
|
147
|
-
alias info_tolog info_to_log
|
148
|
-
|
149
|
-
# @param [String] message The text to place in the log and report
|
150
|
-
# @return [void]
|
151
|
-
def debug_to_log(message, lnbr = nil, dbg = false)
|
152
|
-
message << "\n#{get_debug_list}" if dbg or @debug_calls # and not @debug_calls_fail_only)
|
153
|
-
log_message(DEBUG, "#{message}", nil, lnbr)
|
154
|
-
end
|
155
|
-
|
156
|
-
alias debug_tolog debug_to_log
|
157
|
-
|
158
|
-
# @note Do not use for failed validations. Use only for serious error conditions.
|
159
|
-
# @return [void]
|
160
|
-
# @param [String] message The text to place in the log and report
|
161
|
-
def error_to_log(message, lnbr = nil)
|
162
|
-
log_message(ERROR, message, nil, lnbr)
|
163
|
-
end
|
164
|
-
|
165
|
-
alias error_tolog error_to_log
|
166
|
-
|
167
|
-
# @param [String] message The text to place in the log and report
|
168
|
-
# @return [void]
|
169
|
-
def passed_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
|
-
@my_passed_count += 1 if @my_passed_count
|
172
|
-
parse_error_references(message)
|
173
|
-
@report_class.add_to_report(message, "PASSED") unless Awetestlib::Runner.nil?
|
174
|
-
log_message(INFO, "#{message}", PASS, lnbr)
|
175
|
-
end
|
176
|
-
|
177
|
-
alias validate_passed_tolog passed_to_log
|
178
|
-
alias validate_passed_to_log passed_to_log
|
179
|
-
alias passed_tolog passed_to_log
|
180
|
-
alias pass_tolog passed_to_log
|
181
|
-
alias pass_to_log passed_to_log
|
182
|
-
|
183
|
-
# @param [String] message The text to place in the log and report
|
184
|
-
# @return [void]
|
185
|
-
def failed_to_log(message, lnbr = nil, dbg = false, exception = nil)
|
186
|
-
message << " \n#{get_debug_list}" if dbg.to_s == 'true' or @debug_calls or @debug_calls_fail_only
|
187
|
-
@my_failed_count += 1 if @my_failed_count
|
188
|
-
parse_error_references(message, true)
|
189
|
-
@report_class.add_to_report("#{message}" + " [#{get_caller(lnbr)}]", "FAILED") unless Awetestlib::Runner.nil?
|
190
|
-
log_message(WARN, "#{message}", FAIL, lnbr, nil, exception)
|
191
|
-
end
|
192
|
-
|
193
|
-
alias validate_failed_tolog failed_to_log
|
194
|
-
alias validate_failed_to_log failed_to_log
|
195
|
-
alias failed_tolog failed_to_log
|
196
|
-
alias fail_tolog failed_to_log
|
197
|
-
alias fail_to_log failed_to_log
|
198
|
-
|
199
|
-
# @param [String] message The text to place in the log and report
|
200
|
-
# @return [void]
|
201
|
-
def fatal_to_log(message, lnbr = nil, dbg = false, exception = nil)
|
202
|
-
message << " \n#{get_debug_list}" if dbg.to_s == 'true' or (@debug_calls and not @debug_calls_fail_only)
|
203
|
-
@my_failed_count += 1 if @my_failed_count
|
204
|
-
parse_error_references(message, true)
|
205
|
-
@report_class.add_to_report("#{message}" + " [#{get_caller(lnbr)}]", "FAILED") unless Awetestlib::Runner.nil?
|
206
|
-
debug_to_report("#{__method__}:\n#{dump_caller(lnbr)}")
|
207
|
-
log_message(FATAL, "#{message} (#{lnbr})", FAIL, lnbr, nil, exception)
|
208
|
-
end
|
209
|
-
|
210
|
-
alias fatal_tolog fatal_to_log
|
211
|
-
|
212
|
-
# @param [String] message The text to place in the log and report
|
213
|
-
# @return [void]
|
214
|
-
def message_to_report(message, dbg = false)
|
215
|
-
mark_testlevel(message, 0, '', dbg)
|
216
|
-
end
|
217
|
-
|
218
|
-
# @param [String] message The text to place in the log and report
|
219
|
-
# @return [void]
|
220
|
-
def debug_to_report(message, dbg = false)
|
221
|
-
mark_testlevel("(DEBUG): ", 0, "#{message}", dbg)
|
222
|
-
end
|
223
|
-
|
224
|
-
# @private
|
225
|
-
# @return [Fixnum] required by logger.
|
226
|
-
def translate_severity(severity)
|
227
|
-
mySev = ''
|
228
|
-
case
|
229
|
-
when severity == 0
|
230
|
-
mySev = 'DEBUG'
|
231
|
-
when severity == 1
|
232
|
-
mySev = 'INFO'
|
233
|
-
when severity == 2
|
234
|
-
mySev = 'WARN'
|
235
|
-
when severity == 3
|
236
|
-
mySev = 'ERROR'
|
237
|
-
when severity == 4
|
238
|
-
mySev = 'FATAL'
|
239
|
-
when severity > 4
|
240
|
-
mySev = 'UNKNOWN'
|
241
|
-
end
|
242
|
-
mySev
|
243
|
-
end
|
244
|
-
|
245
|
-
# @private
|
246
|
-
def get_caller(lnbr=nil, exception=nil)
|
247
|
-
script_name ||= File.basename(script_file)
|
248
|
-
if lnbr && script_type.eql?("Selenium")
|
249
|
-
[script_name, lnbr, 'in run()'].join(":")
|
250
|
-
elsif lnbr && script_type.eql?("MobileNativeApp")
|
251
|
-
[script_name, lnbr, 'in scenario()'].join(":")
|
252
|
-
else
|
253
|
-
caller_object = exception ? exception.backtrace : Kernel.caller
|
254
|
-
call_frame = caller_object.detect do |frame|
|
255
|
-
frame.match(/#{script_name}/) or (library && frame.match(/#{library}/))
|
256
|
-
end
|
257
|
-
unless call_frame.nil?
|
258
|
-
call_frame.gsub!(/^C:/, '')
|
259
|
-
file, line, method = call_frame.split(":")
|
260
|
-
[File.basename(file), line, method].join(":")
|
261
|
-
else
|
262
|
-
'unknown'
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
# @private
|
268
|
-
def init_logger(logFile, scriptName = nil)
|
269
|
-
if File.exist?(logFile)
|
270
|
-
puts "==> Logfile already exists: #{logFile}. Replacing it."
|
271
|
-
begin
|
272
|
-
File.delete(logFile)
|
273
|
-
rescue
|
274
|
-
puts "#{scriptName}: init_logger RESCUE: #{$!}"
|
275
|
-
end
|
276
|
-
end
|
277
|
-
logger = ActiveSupport::BufferedLogger.new(logFile)
|
278
|
-
logger.level = ActiveSupport::BufferedLogger::DEBUG
|
279
|
-
logger.auto_flushing = (true)
|
280
|
-
logger.add(INFO, "#{logFile}\n#{ENV["OS"]}")
|
281
|
-
logger
|
282
|
-
end
|
283
|
-
|
284
|
-
#private init_logger
|
285
|
-
|
286
|
-
# @private
|
287
|
-
def start_run(ts = nil)
|
288
|
-
@start_timestamp = Time.now unless ts
|
289
|
-
utc_ts = @start_timestamp.getutc
|
290
|
-
loc_tm = "#{@start_timestamp.strftime("%H:%M:%S")} #{@start_timestamp.zone}"
|
291
|
-
message_to_report(">> Starting #{@myName.titleize} #{utc_ts} (#{loc_tm})")
|
292
|
-
end
|
293
|
-
|
294
|
-
alias start_to_log start_run
|
295
|
-
|
296
|
-
# @private
|
297
|
-
# Tally and report duration, validation and failure counts, and end time for the script.
|
298
|
-
# @param [DateTime] ts Time stamp indicating the time the script completed.
|
299
|
-
def finish_run(ts = Time.now)
|
300
|
-
tally_error_references
|
301
|
-
message_to_report(
|
302
|
-
">> #{@myName.titleize} duration: #{sec2hms(ts - @start_timestamp)}")
|
303
|
-
message_to_report(">> #{@myName.titleize} validations: #{@my_passed_count + @my_failed_count} "+
|
304
|
-
"fail: #{@my_failed_count}]") if @my_passed_count and @my_failed_count
|
305
|
-
utc_ts = ts.getutc
|
306
|
-
loc_tm = "#{ts.strftime("%H:%M:%S")} #{ts.zone}"
|
307
|
-
message_to_report(">> End #{@myName.titleize} #{utc_ts} (#{loc_tm})")
|
308
|
-
end
|
309
|
-
|
310
|
-
alias finish_to_log finish_run
|
311
|
-
|
312
|
-
# @private
|
313
|
-
def tally_error_references(list_tags = @report_all_refs)
|
314
|
-
tags_tested = 0
|
315
|
-
tags_hit = 0
|
316
|
-
if @my_error_hits and @my_error_hits.length > 0
|
317
|
-
message_to_report(">> Tagged Error Hits:")
|
318
|
-
tags_hit = @my_error_hits.length
|
319
|
-
@my_error_hits.each_key do |ref|
|
320
|
-
message_to_report("#{ref} - #{@my_error_hits[ref]}")
|
321
|
-
end
|
322
|
-
end
|
323
|
-
if list_tags
|
324
|
-
if @my_error_references and @my_error_references.length > 0
|
325
|
-
message_to_report(">> Error and Test Case Tags:")
|
326
|
-
tags_tested = @my_error_references.length
|
327
|
-
@my_error_references.each_key do |ref|
|
328
|
-
message_to_report("#{ref} - #{@my_error_references[ref]}")
|
329
|
-
end
|
330
|
-
message_to_report(">> Fails were hit on #{tags_hit} of #{tags_tested} error/test case references")
|
331
|
-
else
|
332
|
-
message_to_report(">> No Error or Test Case References found.")
|
333
|
-
end
|
334
|
-
end
|
335
|
-
end
|
336
|
-
|
337
|
-
# @private
|
338
|
-
def parse_error_references(message, fail = false)
|
339
|
-
msg = message.dup
|
340
|
-
while msg =~ /(\*\*\*\s+[\w\d_\s,-:;\?]+\s+\*\*\*)/
|
341
|
-
capture_error_reference($1, fail)
|
342
|
-
msg.sub!($1, '')
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
# @private
|
347
|
-
def capture_error_reference(ref, fail)
|
348
|
-
if fail
|
349
|
-
@my_error_hits = Hash.new unless @my_error_hits
|
350
|
-
if @my_error_hits[ref]
|
351
|
-
@my_error_hits[ref] += 1
|
352
|
-
else
|
353
|
-
@my_error_hits[ref] = 1
|
354
|
-
end
|
355
|
-
#debug_to_report("#{__method__}: error hits:\n#{@my_error_hits.to_yaml}")
|
356
|
-
end
|
357
|
-
@my_error_references = Hash.new unless @my_error_references
|
358
|
-
if @my_error_references[ref]
|
359
|
-
@my_error_references[ref] += 1
|
360
|
-
else
|
361
|
-
@my_error_references[ref] = 1
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
end
|
366
|
-
end
|
1
|
+
module Awetestlib
|
2
|
+
# Logging and reporting.
|
3
|
+
module Logging
|
4
|
+
|
5
|
+
# @deprecated
|
6
|
+
def self.included(mod)
|
7
|
+
# puts "RegressionSupport::Logging extended by #{mod}"
|
8
|
+
end
|
9
|
+
|
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
|
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.
|
51
|
+
end
|
52
|
+
|
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
|
73
|
+
end
|
74
|
+
|
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
|
96
|
+
end
|
97
|
+
|
98
|
+
# else
|
99
|
+
# failed_to_log "SIKULI LOG:\n\n #{output_lines.join('\n')}"
|
100
|
+
# end
|
101
|
+
|
102
|
+
return { :result => passed, :msg => output_str }
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
# Write a status message to the log and report indicating location or activity
|
107
|
+
# in the script. mark_test_level automatically determines the call hierarchy level
|
108
|
+
# of the calling method within the script and project utility methods. The top level
|
109
|
+
# method of the script is always level 1. The method also prefixes the calling method
|
110
|
+
# name (titleized) to the message to be placed in the log.
|
111
|
+
# @param [String] message The text to place in the log and report after the titleized
|
112
|
+
# calling method name.
|
113
|
+
# @param [Fixnum] lvl '0' forces a message to the report without a specific level
|
114
|
+
# attached. Any other integer is ignored in favor of the calculated level
|
115
|
+
# @param [String] desc Any additional information to add to the message.
|
116
|
+
# @param [Boolean] dbg When set to true adds a trace to the message.
|
117
|
+
# @return [void]
|
118
|
+
def mark_test_level(message = '', lvl = nil, desc = '', dbg = nil)
|
119
|
+
call_arr = get_call_array()
|
120
|
+
#debug_to_log("#{call_arr.to_yaml}")
|
121
|
+
strg = ''
|
122
|
+
call_script, call_line, call_meth = parse_caller(call_arr[1])
|
123
|
+
if not lvl or lvl > 1
|
124
|
+
lvl, list = get_test_level
|
125
|
+
strg << "#{call_meth.titleize}"
|
126
|
+
end
|
127
|
+
strg << " #{message}" if message.length > 0
|
128
|
+
strg << " (#{desc})" if desc.length > 0
|
129
|
+
strg << " [#{call_line}]"
|
130
|
+
strg << "\n#{list.to_yaml}" if dbg or @debug_calls
|
131
|
+
@report_class.add_to_report(strg, " ", lvl || 1) unless Awetestlib::Runner.nil?
|
132
|
+
log_message(INFO, strg, lvl, nil, 1)
|
133
|
+
rescue
|
134
|
+
failed_to_log("#{__method__}: #{$!}")
|
135
|
+
end
|
136
|
+
|
137
|
+
alias mark_testlevel mark_test_level
|
138
|
+
|
139
|
+
# @param [String] message The text to place in the log
|
140
|
+
# @return [void]
|
141
|
+
def info_to_log(message, lnbr = nil)
|
142
|
+
log_message(INFO, message, 0, lnbr)
|
143
|
+
end
|
144
|
+
|
145
|
+
alias message_tolog info_to_log
|
146
|
+
alias message_to_log info_to_log
|
147
|
+
alias info_tolog info_to_log
|
148
|
+
|
149
|
+
# @param [String] message The text to place in the log and report
|
150
|
+
# @return [void]
|
151
|
+
def debug_to_log(message, lnbr = nil, dbg = false)
|
152
|
+
message << "\n#{get_debug_list}" if dbg or @debug_calls # and not @debug_calls_fail_only)
|
153
|
+
log_message(DEBUG, "#{message}", nil, lnbr)
|
154
|
+
end
|
155
|
+
|
156
|
+
alias debug_tolog debug_to_log
|
157
|
+
|
158
|
+
# @note Do not use for failed validations. Use only for serious error conditions.
|
159
|
+
# @return [void]
|
160
|
+
# @param [String] message The text to place in the log and report
|
161
|
+
def error_to_log(message, lnbr = nil)
|
162
|
+
log_message(ERROR, message, nil, lnbr)
|
163
|
+
end
|
164
|
+
|
165
|
+
alias error_tolog error_to_log
|
166
|
+
|
167
|
+
# @param [String] message The text to place in the log and report
|
168
|
+
# @return [void]
|
169
|
+
def passed_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
|
+
@my_passed_count += 1 if @my_passed_count
|
172
|
+
parse_error_references(message)
|
173
|
+
@report_class.add_to_report(message, "PASSED") unless Awetestlib::Runner.nil?
|
174
|
+
log_message(INFO, "#{message}", PASS, lnbr)
|
175
|
+
end
|
176
|
+
|
177
|
+
alias validate_passed_tolog passed_to_log
|
178
|
+
alias validate_passed_to_log passed_to_log
|
179
|
+
alias passed_tolog passed_to_log
|
180
|
+
alias pass_tolog passed_to_log
|
181
|
+
alias pass_to_log passed_to_log
|
182
|
+
|
183
|
+
# @param [String] message The text to place in the log and report
|
184
|
+
# @return [void]
|
185
|
+
def failed_to_log(message, lnbr = nil, dbg = false, exception = nil)
|
186
|
+
message << " \n#{get_debug_list}" if dbg.to_s == 'true' or @debug_calls or @debug_calls_fail_only
|
187
|
+
@my_failed_count += 1 if @my_failed_count
|
188
|
+
parse_error_references(message, true)
|
189
|
+
@report_class.add_to_report("#{message}" + " [#{get_caller(lnbr)}]", "FAILED") unless Awetestlib::Runner.nil?
|
190
|
+
log_message(WARN, "#{message}", FAIL, lnbr, nil, exception)
|
191
|
+
end
|
192
|
+
|
193
|
+
alias validate_failed_tolog failed_to_log
|
194
|
+
alias validate_failed_to_log failed_to_log
|
195
|
+
alias failed_tolog failed_to_log
|
196
|
+
alias fail_tolog failed_to_log
|
197
|
+
alias fail_to_log failed_to_log
|
198
|
+
|
199
|
+
# @param [String] message The text to place in the log and report
|
200
|
+
# @return [void]
|
201
|
+
def fatal_to_log(message, lnbr = nil, dbg = false, exception = nil)
|
202
|
+
message << " \n#{get_debug_list}" if dbg.to_s == 'true' or (@debug_calls and not @debug_calls_fail_only)
|
203
|
+
@my_failed_count += 1 if @my_failed_count
|
204
|
+
parse_error_references(message, true)
|
205
|
+
@report_class.add_to_report("#{message}" + " [#{get_caller(lnbr)}]", "FAILED") unless Awetestlib::Runner.nil?
|
206
|
+
debug_to_report("#{__method__}:\n#{dump_caller(lnbr)}")
|
207
|
+
log_message(FATAL, "#{message} (#{lnbr})", FAIL, lnbr, nil, exception)
|
208
|
+
end
|
209
|
+
|
210
|
+
alias fatal_tolog fatal_to_log
|
211
|
+
|
212
|
+
# @param [String] message The text to place in the log and report
|
213
|
+
# @return [void]
|
214
|
+
def message_to_report(message, dbg = false)
|
215
|
+
mark_testlevel(message, 0, '', dbg)
|
216
|
+
end
|
217
|
+
|
218
|
+
# @param [String] message The text to place in the log and report
|
219
|
+
# @return [void]
|
220
|
+
def debug_to_report(message, dbg = false)
|
221
|
+
mark_testlevel("(DEBUG): ", 0, "#{message}", dbg)
|
222
|
+
end
|
223
|
+
|
224
|
+
# @private
|
225
|
+
# @return [Fixnum] required by logger.
|
226
|
+
def translate_severity(severity)
|
227
|
+
mySev = ''
|
228
|
+
case
|
229
|
+
when severity == 0
|
230
|
+
mySev = 'DEBUG'
|
231
|
+
when severity == 1
|
232
|
+
mySev = 'INFO'
|
233
|
+
when severity == 2
|
234
|
+
mySev = 'WARN'
|
235
|
+
when severity == 3
|
236
|
+
mySev = 'ERROR'
|
237
|
+
when severity == 4
|
238
|
+
mySev = 'FATAL'
|
239
|
+
when severity > 4
|
240
|
+
mySev = 'UNKNOWN'
|
241
|
+
end
|
242
|
+
mySev
|
243
|
+
end
|
244
|
+
|
245
|
+
# @private
|
246
|
+
def get_caller(lnbr=nil, exception=nil)
|
247
|
+
script_name ||= File.basename(script_file)
|
248
|
+
if lnbr && script_type.eql?("Selenium")
|
249
|
+
[script_name, lnbr, 'in run()'].join(":")
|
250
|
+
elsif lnbr && script_type.eql?("MobileNativeApp")
|
251
|
+
[script_name, lnbr, 'in scenario()'].join(":")
|
252
|
+
else
|
253
|
+
caller_object = exception ? exception.backtrace : Kernel.caller
|
254
|
+
call_frame = caller_object.detect do |frame|
|
255
|
+
frame.match(/#{script_name}/) or (library && frame.match(/#{library}/))
|
256
|
+
end
|
257
|
+
unless call_frame.nil?
|
258
|
+
call_frame.gsub!(/^C:/, '')
|
259
|
+
file, line, method = call_frame.split(":")
|
260
|
+
[File.basename(file), line, method].join(":")
|
261
|
+
else
|
262
|
+
'unknown'
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
# @private
|
268
|
+
def init_logger(logFile, scriptName = nil)
|
269
|
+
if File.exist?(logFile)
|
270
|
+
puts "==> Logfile already exists: #{logFile}. Replacing it."
|
271
|
+
begin
|
272
|
+
File.delete(logFile)
|
273
|
+
rescue
|
274
|
+
puts "#{scriptName}: init_logger RESCUE: #{$!}"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
logger = ActiveSupport::BufferedLogger.new(logFile)
|
278
|
+
logger.level = ActiveSupport::BufferedLogger::DEBUG
|
279
|
+
logger.auto_flushing = (true)
|
280
|
+
logger.add(INFO, "#{logFile}\n#{ENV["OS"]}")
|
281
|
+
logger
|
282
|
+
end
|
283
|
+
|
284
|
+
#private init_logger
|
285
|
+
|
286
|
+
# @private
|
287
|
+
def start_run(ts = nil)
|
288
|
+
@start_timestamp = Time.now unless ts
|
289
|
+
utc_ts = @start_timestamp.getutc
|
290
|
+
loc_tm = "#{@start_timestamp.strftime("%H:%M:%S")} #{@start_timestamp.zone}"
|
291
|
+
message_to_report(">> Starting #{@myName.titleize} #{utc_ts} (#{loc_tm})")
|
292
|
+
end
|
293
|
+
|
294
|
+
alias start_to_log start_run
|
295
|
+
|
296
|
+
# @private
|
297
|
+
# Tally and report duration, validation and failure counts, and end time for the script.
|
298
|
+
# @param [DateTime] ts Time stamp indicating the time the script completed.
|
299
|
+
def finish_run(ts = Time.now)
|
300
|
+
tally_error_references
|
301
|
+
message_to_report(
|
302
|
+
">> #{@myName.titleize} duration: #{sec2hms(ts - @start_timestamp)}")
|
303
|
+
message_to_report(">> #{@myName.titleize} validations: #{@my_passed_count + @my_failed_count} "+
|
304
|
+
"fail: #{@my_failed_count}]") if @my_passed_count and @my_failed_count
|
305
|
+
utc_ts = ts.getutc
|
306
|
+
loc_tm = "#{ts.strftime("%H:%M:%S")} #{ts.zone}"
|
307
|
+
message_to_report(">> End #{@myName.titleize} #{utc_ts} (#{loc_tm})")
|
308
|
+
end
|
309
|
+
|
310
|
+
alias finish_to_log finish_run
|
311
|
+
|
312
|
+
# @private
|
313
|
+
def tally_error_references(list_tags = @report_all_refs)
|
314
|
+
tags_tested = 0
|
315
|
+
tags_hit = 0
|
316
|
+
if @my_error_hits and @my_error_hits.length > 0
|
317
|
+
message_to_report(">> Tagged Error Hits:")
|
318
|
+
tags_hit = @my_error_hits.length
|
319
|
+
@my_error_hits.each_key do |ref|
|
320
|
+
message_to_report("#{ref} - #{@my_error_hits[ref]}")
|
321
|
+
end
|
322
|
+
end
|
323
|
+
if list_tags
|
324
|
+
if @my_error_references and @my_error_references.length > 0
|
325
|
+
message_to_report(">> Error and Test Case Tags:")
|
326
|
+
tags_tested = @my_error_references.length
|
327
|
+
@my_error_references.each_key do |ref|
|
328
|
+
message_to_report("#{ref} - #{@my_error_references[ref]}")
|
329
|
+
end
|
330
|
+
message_to_report(">> Fails were hit on #{tags_hit} of #{tags_tested} error/test case references")
|
331
|
+
else
|
332
|
+
message_to_report(">> No Error or Test Case References found.")
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
# @private
|
338
|
+
def parse_error_references(message, fail = false)
|
339
|
+
msg = message.dup
|
340
|
+
while msg =~ /(\*\*\*\s+[\w\d_\s,-:;\?]+\s+\*\*\*)/
|
341
|
+
capture_error_reference($1, fail)
|
342
|
+
msg.sub!($1, '')
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
# @private
|
347
|
+
def capture_error_reference(ref, fail)
|
348
|
+
if fail
|
349
|
+
@my_error_hits = Hash.new unless @my_error_hits
|
350
|
+
if @my_error_hits[ref]
|
351
|
+
@my_error_hits[ref] += 1
|
352
|
+
else
|
353
|
+
@my_error_hits[ref] = 1
|
354
|
+
end
|
355
|
+
#debug_to_report("#{__method__}: error hits:\n#{@my_error_hits.to_yaml}")
|
356
|
+
end
|
357
|
+
@my_error_references = Hash.new unless @my_error_references
|
358
|
+
if @my_error_references[ref]
|
359
|
+
@my_error_references[ref] += 1
|
360
|
+
else
|
361
|
+
@my_error_references[ref] = 1
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
end
|
366
|
+
end
|