awetestlib 0.1.22 → 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --hide-void-return
2
+ --verbose
3
+ --exclude version.rb
4
+ --exclude html_report.rb
5
+ --no-private
6
+ --title "Awetest DSL"
7
+ lib/**/*.rb
data/lib/awetestlib.rb CHANGED
@@ -5,6 +5,7 @@ module Awetestlib
5
5
  ::USING_WINDOWS = !!((RUBY_PLATFORM =~ /(win|w)(32|64)$/) || (RUBY_PLATFORM=~ /mswin|mingw/))
6
6
  ::USING_OSX = RUBY_PLATFORM =~ /darwin/
7
7
 
8
+ # @private
8
9
  BROWSER_MAP = {
9
10
  'FF' => 'Firefox',
10
11
  'IE' => 'Internet Explorer',
@@ -13,6 +14,7 @@ module Awetestlib
13
14
  'C' => 'Chrome'
14
15
  }
15
16
 
17
+ # @private
16
18
  BROWSER_ALTERNATES = {
17
19
  'OSX' => { 'IE' => 'S' },
18
20
  'Windows' => { 'S' => 'IE' }
@@ -20,7 +22,7 @@ module Awetestlib
20
22
 
21
23
  if USING_WINDOWS
22
24
  #require 'win32ole' <-- We'll load this later in Shamisen::AwetestLegacy::Runner. It has to be loaded after watir, see https://www.pivotaltracker.com/story/show/19249981
23
- require 'win32/screenshot' # triggering segmentation fault 10sep2012 pmn
25
+ #require 'win32/screenshot' # triggering segmentation fault 10sep2012 pmn
24
26
  end
25
27
  #require 'active_support/inflector'
26
28
  #require 'active_support/core_ext/object'
@@ -1,6 +1,9 @@
1
1
  module Awetestlib
2
+ # Report generator for Awetestlib.
2
3
  class HtmlReport
4
+
3
5
  # Initialize the report class
6
+ # @private
4
7
  def initialize(report_name)
5
8
  @reportname = report_name
6
9
  @reportContent1 = ''
@@ -8,53 +11,15 @@ module Awetestlib
8
11
  end
9
12
 
10
13
  # Create a report
14
+ # @private
11
15
  def create_report(reportName)
12
16
  # Get current time
13
17
  t = Time.now
14
- # Format the day
15
- if(t.day.to_s.length == 1)
16
- strDay = '0' + t.day.to_s
17
- else
18
- strDay = t.day.to_s
19
- end
20
-
21
- # Format the month
22
- if(t.month.to_s.length == 1)
23
- strMonth = '0' + t.month.to_s
24
- else
25
- strMonth = t.month.to_s
26
- end
27
-
28
- # Format the year
29
- strYear = t.year.to_s
30
-
31
- # Format the hour
32
- if(t.hour.to_s.length == 1)
33
- strHour = '0' + t.hour.to_s
34
- else
35
- strHour = t.hour.to_s
36
- end
37
-
38
- # Format the minutes
39
- if(t.min.to_s.length == 1)
40
- strMinutes = '0' + t.min.to_s
41
- else
42
- strMinutes = t.min.to_s
43
- end
44
-
45
- # Format the seconds
46
- if(t.sec.to_s.length == 1)
47
- strSeconds = '0' + t.sec.to_s
48
- elsif (t.sec.to_s.length == 0)
49
- strSeconds = '00'
50
- else
51
- strSeconds = t.sec.to_s
52
- end
53
18
 
54
19
  # Create the report name
55
- strTime = '_' + strMonth + strDay + strYear + '_' + strHour + strMinutes + strSeconds + '.html'
56
- strNiceTime = strDay + '-' + strMonth + '-' + strYear + ' @ ' + strHour + ':' + strMinutes + ':' + strSeconds
57
- strTotalReport = reportName + strTime
20
+ strTime = "#{t.strftime("%Y%m%d_%H%M%S")}"
21
+ strNiceTime = "#{t.strftime("%m/%d/%Y @ %H:%M:%S")}"
22
+ strTotalReport = "#{reportName}_#{strTime}.html"
58
23
 
59
24
  # Create the HTML report
60
25
  strFile = File.open(strTotalReport, 'w')
@@ -135,7 +100,9 @@ module Awetestlib
135
100
  return strTotalReport
136
101
  end
137
102
 
138
- def add_to_report(step, result)
103
+ # Add a row to the report
104
+ # @private
105
+ def add_to_report(step, result, level = 1)
139
106
  # Format the body of the HTML report
140
107
  if (result == 'PASSED')
141
108
  @reportContent2 = @reportContent2 + '<tr><td class=border_left width=80%><p class=normal_text>' + step + '</p></td>'
@@ -143,13 +110,17 @@ module Awetestlib
143
110
  elsif (result == 'FAILED')
144
111
  @reportContent2 = @reportContent2 + '<tr><td class=border_left width=80%><p class=normal_text>' + step + '</p></td>'
145
112
  @reportContent2 = @reportContent2 + '<td class=border_right width=20%><p class=result_nok>' + result + '</p></td>'
113
+ elsif level < 1
114
+ @reportContent2 = @reportContent2 + '<tr><td class=border_left width=80%><p class=normal_text>' + step + '</p></td>'
115
+ @reportContent2 = @reportContent2 + '<td class=border_right width=20%><p class=result_nok>' + result + '</p></td>'
146
116
  else
147
117
  @reportContent2 = @reportContent2 + '<tr><td class=mark_testlevel_left width=80%><p class=bold_large_text>' + step + '</p></td>'
148
118
  @reportContent2 = @reportContent2 + '<td class=mark_testlevel_right width=20%><p class=result_nok>' + result + '</p></td>'
149
119
  end
150
-
151
120
  end
152
121
 
122
+ # Close the report HTML
123
+ # @private
153
124
  def finish_report(reportName)
154
125
  # Open the HTML report
155
126
  strFile = File.open(reportName, 'a')
@@ -1,425 +1,385 @@
1
1
  module Awetestlib
2
- module Logging
2
+ # Logging and reporting.
3
+ module Logging
3
4
 
4
- # @deprecated
5
- def self.included(mod)
6
- # puts "RegressionSupport::Logging extended by #{mod}"
7
- end
5
+ # @deprecated
6
+ def self.included(mod)
7
+ # puts "RegressionSupport::Logging extended by #{mod}"
8
+ end
8
9
 
9
- # Format log message and write to STDOUT. Write to physical log if indicated.
10
- # @private
11
- # @param [Fixnum] severity Severity level of message. Use constants DEBUG, INFO, WARN, ERROR, FATAL, or UNKNOWN
12
- # @param [String] message The message to be placed in the log.
13
- # @param [String, Fixnum] tag Indicates the type of message. Valid string values are 'FAIL' and 'PASS'.
14
- # Valid number values are 0 to 9.
15
- # @param [Fixnum] lnbr the line number in the calling script
16
- # @param [Fixnum] addts Obsolete, no longer used.
17
- # @param [String] exception Obsolete, no longer used.
18
- def log_message(severity, message, tag = '', lnbr = nil, addts = 1, exception=nil)
19
- # caller = get_caller(lnbr, exception)
20
-
21
- # @sequence ||= log_properties ? log_properties.fetch('sequence', 0) : 0
22
- # @sequence += 1
23
-
24
- t = Time.now.utc
25
- @last_t ||= t
26
- @last_t = t
27
- dt = t.strftime("%H%M%S")
28
- mySev = translate_severity(severity)
29
- myCaller = get_caller(lnbr) || 'unknown'
30
-
31
- myMsg = "%-8s" % mySev
32
- myMsg << '[' + dt + ']:'
33
- if tag
34
- if tag.is_a? Fixnum
35
- tag = '-LVL' + tag.to_s
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
- #private log_message
62
-
63
- # Translates tag value to corresponding value for +pass+ column in database.
64
- # @private
65
- # @param [String, Fixnum] tag
66
- # @return [String] Single character
67
- def pass_code_for(tag)
68
- case
69
- when tag =~ /PASS/
70
- 'P'
71
- when tag =~ /FAIL/
72
- 'F'
73
- #when tag =~ /\d+/ # avoid having to require andand for awetestlib. pmn 05jun2012
74
- when tag.andand.is_a?(Fixnum)
75
- 'H'
76
- when tag =~ /DONE/
77
- 'D'
78
- when tag =~ /role/
79
- 'R'
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
- def log_sikuli_output(output_file, passed)
84
- output_lines = File.open(output_file, 'r') { |f| f.readlines }
85
- puts "IM FAILING?! #{passed}"
86
-
87
- # if passed
88
-
89
- log_messages = ['[log]', '[error]']
90
- output_lines = output_lines.select { |l| log_messages } #.detect{|msg| l.include?(msg)} }
91
- while line = output_lines.shift do
92
- puts "line to be logged: #{line}"
93
- if line.include? '[log]'
94
- passed_to_log line
95
- elsif line.include? '[error]'
96
- failed_to_log line
97
- elsif line.match /\s*Exception/
98
- failed_to_log output_lines.join("\n")
99
- break
100
- else
101
- debug_tolog line
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
- # else
106
- # failed_to_log "SIKULI LOG:\n\n #{output_lines.join('\n')}"
107
- # end
98
+ # else
99
+ # failed_to_log "SIKULI LOG:\n\n #{output_lines.join('\n')}"
100
+ # end
108
101
 
109
- return { :result => passed, :msg => output_str }
110
- end
102
+ return { :result => passed, :msg => output_str }
103
+ end
111
104
 
112
- # Put status message to the log and output window
113
- # TODO: figure out a way to do the leveling automatically based on actual call depth within script (and project library?)
114
- # When using to mark test groupings, include
115
- # level 'lvl' (numeric literal, 1 through 9, usually 1-4)
116
- # indicating test grouping hierarchy:
117
- # 0 lowest level test case, a single validation
118
- # a.k.a TEST CASE, VALIDATION
119
- # not normally used in scripts as it is
120
- # implied by method with 'validate' in name
121
- # 1 group of closely related level 0 validations
122
- # a.k.a TEST GROUP
123
- # should never be followed by another level 1
124
- # or higher level message without intervening
125
- # level 0 validations.
126
- # 2 group of closely related level 1 validation sets.
127
- # a.k.a TEST SET, SUBMODULE, USE CASE
128
- # should never be followed by another level 2
129
- # or higher level message without intervening
130
- # lower levels.
131
- # 3 group of closely related level 2 validation sets.
132
- # a.k.a TEST SET, TEST SUITE, MODULE, USE CASE
133
- # should never be followed by another level 3
134
- # or higher level message without intervening
135
- # lower levels.
136
- # 4 group of closely related level 3 validation sets.
137
- # a.k.a TEST SUITE, APPLICATION UNDER TEST, PLAN, PROJECT
138
- # should never be followed by another level 4
139
- # or higher level message without intervening
140
- # lower levels. Will seldom appear directly in
141
- # scripts
142
-
143
- =begin rdoc
144
- category: Logging
145
- tags: report, log, test level
146
- =end
147
- def mark_testlevel(message, lvl, desc = '', dbg = nil)
148
- strg = ''
149
- strg << message
150
- strg << " [#{desc}]" if desc.length > 0
151
- strg << " \n#{get_debug_list}" if dbg or @debug_calls
152
- @report_class.add_to_report(message, "&nbsp")
153
- log_message(INFO, strg, lvl, 1)
154
- rescue
155
- failed_to_log("#{__method__}: #{$!}")
156
- end
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, "&nbsp", lvl)
150
+ log_message(INFO, strg, lvl, 1)
151
+ rescue
152
+ failed_to_log("#{__method__}: #{$!}")
153
+ end
157
154
 
158
- alias mark_test_level mark_testlevel
155
+ alias mark_test_level mark_testlevel
159
156
 
160
- =begin rdoc
161
- category: Logging
162
- tags: log
163
- =end
164
- def info_to_log(message, lnbr = __LINE__)
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
- alias message_tolog info_to_log
169
- alias message_to_log info_to_log
170
- alias info_tolog info_to_log
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
- alias debug_tolog debug_to_log
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
- =begin rdoc
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
- alias error_tolog error_to_log
193
-
194
- =begin rdoc
195
- category: Logging
196
- tags: log, error, pass, reference, tag, report
197
- =end
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
- alias validate_passed_tolog passed_to_log
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
- alias validate_failed_tolog failed_to_log
225
- alias validate_failed_to_log failed_to_log
226
- alias failed_tolog failed_to_log
227
- alias fail_tolog failed_to_log
228
- alias fail_to_log failed_to_log
229
-
230
- =begin rdoc
231
- category: Logging
232
- tags: log, error, fail, reference, tag, fatal, report
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
- #def fatal_to_log(message, lnbr = __LINE__)
243
- # log_message(FATAL, "#{message} (#{lnbr})", FAIL, lnbr)
244
- # log_message(DEBUG, "\n#{dump_caller(lnbr)}")
245
- #end
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
- alias fatal_tolog fatal_to_log
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
- =begin rdoc
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
- =begin rdoc
258
- category: Logging
259
- tags: log, debug, report
260
- =end
261
- def debug_to_report(message, dbg = false)
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
- def translate_severity(severity)
266
- mySev = ''
267
- case
268
- when severity == 0
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
- =begin rdoc
285
- category: Debug
286
- tags: log, caller, trace, report
287
- =end
288
- def get_caller(lnbr=nil, exception=nil)
289
- script_name ||= File.basename(script_file)
290
- if lnbr && script_type.eql?("Selenium")
291
- [script_name, lnbr, 'in run()'].join(":")
292
- elsif lnbr && script_type.eql?("MobileNativeApp")
293
- [script_name, lnbr, 'in scenario()'].join(":")
294
- else
295
- caller_object = exception ? exception.backtrace : Kernel.caller
296
- call_frame = caller_object.detect do |frame|
297
- frame.match(/#{script_name}/) or (library && frame.match(/#{library}/))
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
- unless call_frame.nil?
300
- call_frame.gsub!(/^C:/, '')
301
- file, line, method = call_frame.split(":")
302
- [File.basename(file), line, method].join(":")
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
- 'unknown'
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
- def init_logger(logFile, scriptName = nil)
310
- if File.exist?(logFile)
311
- puts "==> Logfile already exists: #{logFile}. Replacing it."
312
- begin
313
- File.delete(logFile)
314
- rescue
315
- puts "#{scriptName}: init_logger RESCUE: #{$!}"
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
- =begin rdoc
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
- mark_testlevel(">> Duration: #{sec2hms(timestamp - @start_timestamp)}", 0)
348
-
349
- mark_testlevel(">> Validations: #{@my_passed_count + @my_failed_count} | "+
350
- "Fails: #{@my_failed_count}", 0) if @my_passed_count and @my_failed_count
351
-
352
- tally_error_references
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
- utc_ts = timestamp.getutc
355
- loc_tm = "#{timestamp.strftime("%H:%M:%S")} #{timestamp.zone}"
356
- debug_to_log(">> End #{@myName.titleize}")
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
- end
327
+ end
359
328
 
360
- alias finish_to_log finish_run
361
-
362
- =begin rdoc
363
- category: Logging
364
- tags: log, error, reference, tag, tallies
365
- =end
366
- def tally_error_references(list_tags = @report_all_refs)
367
- tags_tested = 0
368
- tags_hit = 0
369
- if @my_error_hits and @my_error_hits.length > 0
370
- mark_testlevel("Tagged Error Hits:", 0)
371
- tags_hit = @my_error_hits.length
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
- end
376
- if list_tags
377
- if @my_error_references and @my_error_references.length > 0
378
- mark_testlevel("Error and Test Case Tags:", 0)
379
- tags_tested = @my_error_references.length
380
- @my_error_references.each_key do |ref|
381
- mark_testlevel("#{ref} - #{@my_error_references[ref]}", 0)
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
- =begin rdoc
391
- category: Logging
392
- tags: error, reference, tag, tallies
393
- =end
394
- def parse_error_references(message, fail = false)
395
- msg = message.dup
396
- while msg =~ /(\*\*\*\s+[\w\d_\s,-:;\?]+\s+\*\*\*)/
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
- =begin rdoc
403
- category: Logging
404
- tags: error, fail, hits, reference, tag, tallies
405
- =end
406
- def capture_error_reference(ref, fail)
407
- if fail
408
- @my_error_hits = Hash.new unless @my_error_hits
409
- if @my_error_hits[ref]
410
- @my_error_hits[ref] += 1
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
- @my_error_hits[ref] = 1
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