awetestlib 0.1.30-x86-mingw32 → 1.2.4-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +101 -41
  3. data/awetestlib.gemspec +36 -47
  4. data/awetestlib_osx.gemspec +24 -18
  5. data/awetestlib_windows.gemspec +46 -0
  6. data/bin/awetestlib +130 -111
  7. data/bin/awetestlib-driver-setup.rb +0 -2
  8. data/bin/awetestlib-helpers.rb +43 -30
  9. data/lib/awetestlib.rb +196 -20
  10. data/lib/awetestlib/command_line.rb +44 -0
  11. data/lib/awetestlib/html_report.rb +57 -50
  12. data/lib/awetestlib/logging.rb +242 -171
  13. data/lib/awetestlib/regression/awetest_dsl.rb +4240 -0
  14. data/lib/awetestlib/regression/browser.rb +514 -397
  15. data/lib/awetestlib/regression/date_and_time.rb +280 -0
  16. data/lib/awetestlib/regression/drag_and_drop.rb +24 -0
  17. data/lib/awetestlib/regression/find.rb +70 -43
  18. data/lib/awetestlib/regression/legacy.rb +1 -1
  19. data/lib/awetestlib/regression/mobile.rb +293 -0
  20. data/lib/awetestlib/regression/reporting.rb +298 -0
  21. data/lib/awetestlib/regression/runner.rb +156 -200
  22. data/lib/awetestlib/regression/tables.rb +117 -7
  23. data/lib/awetestlib/regression/test_data.rb +354 -0
  24. data/lib/awetestlib/regression/user_input.rb +179 -93
  25. data/lib/awetestlib/regression/utilities.rb +755 -286
  26. data/lib/awetestlib/regression/validations.rb +325 -115
  27. data/lib/awetestlib/regression/waits.rb +60 -133
  28. data/lib/awetestlib/runner.rb +5 -2
  29. data/lib/version.rb +11 -2
  30. data/setup_samples/sample_cucumber/features/step_definitions/predefined_steps.rb +109 -49
  31. data/setup_samples/sample_mobile_app/features/support/env.rb +1 -1
  32. data/test/google_search2.rb +7 -6
  33. data/test/popup_child_0.rb +13 -0
  34. data/test/popup_child_1.rb +33 -0
  35. data/test/watir_no_require.rb +13 -0
  36. data/test/watir_with_require.rb +16 -0
  37. data/test/zoho_exercise.rb +8 -8
  38. metadata +216 -303
  39. data/AwetestLib Instructions.rtf +0 -0
  40. data/awetestlib.windows.gemspec +0 -42
  41. data/lib/patches/README +0 -2
  42. data/lib/patches/firewatir.rb +0 -106
  43. data/lib/patches/watir.rb +0 -175
@@ -0,0 +1,44 @@
1
+ module CommandLine
2
+
3
+ def build_awetestlib_command_line(options)
4
+
5
+ option_keys = {
6
+ :browser => '-b',
7
+ :capture_load_times => '-L',
8
+ :debug_dsl => '-d',
9
+ :device_id => '-I',
10
+ :device_type => '-T',
11
+ :emulator => '-E',
12
+ :environment_name => '-n',
13
+ :environment_nodename => '-f',
14
+ :environment_url => '-e',
15
+ :global_debug => '-D',
16
+ :library => '-l',
17
+ :log_path_subdir => '-S',
18
+ :output_to_log => '-o',
19
+ :platform => '-P',
20
+ :pry => '-p',
21
+ :remote_url => '-u',
22
+ :report_all_test_refs => '-R',
23
+ :root_path => '-r',
24
+ :screencap_path => '-s',
25
+ :sdk => '-K',
26
+ :locate_timeout => '-t',
27
+ :version => '-v',
28
+ :xls_path => '-x',
29
+ :help => '-h',
30
+ }
31
+
32
+ run_cmd = "awetestlib #{options[:script_file]}"
33
+
34
+ option_keys.each_key do |opt|
35
+ if options[opt]
36
+ run_cmd << " #{option_keys[opt]} #{options[opt]}"
37
+ end
38
+ end
39
+
40
+ run_cmd
41
+
42
+ end
43
+
44
+ end
@@ -2,34 +2,38 @@ module Awetestlib
2
2
  # Report generator for Awetestlib.
3
3
  class HtmlReport
4
4
 
5
+ attr_accessor :report_name,
6
+ :html_file_name,
7
+ :json_file_name
8
+
9
+ # TODO: split the json and html reports to separate classes
5
10
  # Initialize the report class
6
11
  # @private
7
- def initialize(report_name)
8
- @reportname = report_name
9
- @reportContent1 = ''
10
- @reportContent2 = ''
12
+ def initialize(report_name, report_dir, ts)
13
+ @report_name = report_name
14
+ @report_content_1 = ''
15
+ @report_content_2 = ''
16
+ rpt_time = "#{ts.strftime("%Y%m%d_%H%M%S")}"
17
+ self.html_file_name = File.join(report_dir, "#{report_name}_#{rpt_time}.html")
18
+ self.json_file_name = File.join(report_dir, "#{report_name}_#{rpt_time}.json")
19
+
11
20
  end
12
21
 
13
22
  # Create a report
14
23
  # @private
15
- def create_report(reportName)
24
+ def create_report(report_name)
16
25
  # Get current time
17
26
  t = Time.now
18
27
 
19
- @col_1_p = '65%'
20
- @col_2_p = '25%'
21
- @col_3_p = '10%'
22
-
23
- # Create the report name
24
- rpt_time = "#{t.strftime("%Y%m%d_%H%M%S")}"
25
- rpt_nice_time = "#{t.strftime("%m/%d/%Y @ %H:%M:%S")}"
26
- rpt_file_name = "#{reportName}_#{rpt_time}.html"
28
+ @col_1_p = '66%'
29
+ @col_2_p = '22%'
30
+ @col_3_p = '6%'
31
+ @col_4_p = '6%'
27
32
 
28
- # Create the HTML report
29
- rpt_file = File.open(rpt_file_name, 'w')
33
+ rpt_nice_time = "#{t.strftime("%m/%d/%Y @ %H:%M:%S")}"
30
34
 
31
35
  # Format the header of the HTML report
32
- @reportContent1 = '<html>
36
+ @report_content_1 = '<html>
33
37
  <head>
34
38
  <meta content=text/html; charset=ISO-8859-1 http-equiv=content-type>
35
39
  <title>Awetestlib Test Run</title>
@@ -66,7 +70,7 @@ module Awetestlib
66
70
  <tbody>
67
71
  <tr>
68
72
  <td style=width: 150px;>&nbsp;</td>
69
- <td align=left><img src="https://raw.github.com/3qilabs/awetestlib/develop/images/logo.png"></img></td>
73
+ <td align=left><img src="http://awetest.com/images/awetest_logo.png"></img></td>
70
74
  <td align=right><p class=title>Test Report</p></td>
71
75
  </tr>
72
76
  </tbody>
@@ -80,7 +84,7 @@ module Awetestlib
80
84
  <td width=10%><p class=normal_text></p></td>
81
85
  <td width=20%><p class=bold_text>Script</p></td>
82
86
  <td width=5%><p class=bold_text>:</p></td>
83
- <td width=65%><p class=normal_text>' + @reportname.capitalize + '</p></td>
87
+ <td width=65%><p class=normal_text>' + report_name.capitalize + '</p></td>
84
88
  </tr>
85
89
  <tr>
86
90
  <td width=10%><p class=normal_text></p></td>
@@ -90,7 +94,7 @@ module Awetestlib
90
94
  </tr>
91
95
  <tr>'
92
96
 
93
- @reportContent2 = '</tr>
97
+ @report_content_2 = '</tr>
94
98
  </tbody>
95
99
  </table>
96
100
  </center>
@@ -101,28 +105,34 @@ module Awetestlib
101
105
  <tr>
102
106
  <td class=bborder_left width=' + @col_1_p + '><p>Test Step</p></td>
103
107
  <td class=bborder_left width=' + @col_2_p + '><p>Location</p></td>
104
- <td class=bborder_left width=' + @col_3_p + '><p>Result</p></td>
108
+ <td class=bborder_left width=' + @col_3_p + '><p>Duration</p></td>
109
+ <td class=bborder_left width=' + @col_4_p + '><p>Result</p></td>
105
110
  </tr>' + "\n"
106
111
 
107
- # Close the report
108
- rpt_file.close
112
+ @json_content = {}
113
+ @json_content['report_type'] = 'Awetestlib Report'
114
+ @json_content['Data_order'] = 'message, location, result, level, Time.now, line' #, duration'
115
+ @line_no = 1
116
+
109
117
 
110
- return rpt_file_name
111
118
  end
112
119
 
113
120
  # Add a row to the report
114
121
  # @private
115
- def add_to_report(message, location, result, level = 1)
122
+ def add_to_report(message, location, result, duration = 0, level = 1)
116
123
  # Format the body of the HTML report
117
124
 
125
+ fmt_duration = "#{'%9.5f' % (duration)}"
126
+
118
127
  left_class = 'border_left'
119
128
  right_class = 'border_right'
120
129
  pgph_class = 'normal_text'
121
130
  loc_class = 'center_text'
131
+ dur_class = 'center_text'
122
132
  rslt_class = 'result_ok'
123
133
  middle_class = 'border_middle'
124
134
 
125
- rslt_class = 'result_nok' if result == "FAILED"
135
+ rslt_class = 'result_nok' if result == "FAILED"
126
136
  case result
127
137
  when 'FAILED'
128
138
  rslt_class = 'result_nok'
@@ -135,6 +145,10 @@ module Awetestlib
135
145
  left_class = 'mark_testlevel_left'
136
146
  middle_class = 'mark_testlevel_middle'
137
147
  right_class = 'mark_testlevel_right'
148
+ location = ''
149
+ fmt_duration = ''
150
+ else
151
+ result = ''
138
152
  end
139
153
  end
140
154
  end
@@ -142,47 +156,40 @@ module Awetestlib
142
156
  row = '<tr>
143
157
  <td class=' + left_class + ' width=' + @col_1_p + '><p class=' + pgph_class + '>' + message + '</p></td>
144
158
  <td class=' + middle_class + ' width=' + @col_2_p + '><p class=' + loc_class + '>' + location + '</p></td>
145
- <td class=' + right_class + ' width=' + @col_3_p + '><p class=' + rslt_class + '>' + result + '</p></td>
159
+ <td class=' + middle_class + ' width=' + @col_3_p + '><p class=' + dur_class + '>' + fmt_duration + '</p></td>
160
+ <td class=' + right_class + ' width=' + @col_4_p + '><p class=' + rslt_class + '>' + result + '</p></td>
146
161
  </tr>'
147
162
 
148
- @reportContent2 += row + "\n"
149
-
150
-
151
- #if (result == 'PASSED')
152
- # @reportContent2 = @reportContent2 + '<tr>C'
153
- # @reportContent2 = @reportContent2 + '<td class=border_right width=20%><p class=result_ok>' + result + '</p></td>'
154
- #elsif (result == 'FAILED')
155
- # @reportContent2 = @reportContent2 + '<tr><td class=border_left width=80%><p class=normal_text>' + step + '</p></td>'
156
- # @reportContent2 = @reportContent2 + '<td class=border_right width=20%><p class=result_nok>' + result + '</p></td>'
157
- #elsif level < 1
158
- # @reportContent2 = @reportContent2 + '<tr><td class=border_left width=80%><p class=normal_text>' + step + '</p></td>'
159
- # @reportContent2 = @reportContent2 + '<td class=border_right width=20%><p class=result_ok>' + result + '</p></td>'
160
- #else
161
- # @reportContent2 = @reportContent2 + '<tr><td class=mark_testlevel_left width=80%><p class=bold_large_text>' + step + '</p></td>'
162
- # @reportContent2 = @reportContent2 + '<td class=mark_testlevel_right width=20%><p class=result_ok>' + result + '</p></td>'
163
- #end
163
+ @report_content_2 += row + "\n"
164
+ @json_content["line_no_#{@line_no}"] = [message, location, result, level, Time.now, @line_no] #, duration]
165
+ @line_no += 1
164
166
 
165
167
  end
166
168
 
167
169
  # Close the report HTML
168
170
  # @private
169
- def finish_report(reportName)
170
- # Open the HTML report
171
- rpt_file = File.open(reportName, 'a')
171
+ def finish_report
172
172
 
173
- @reportContent2 = @reportContent2 + '<tr>
173
+ # HTML Report
174
+ rpt_file = File.open(self.html_file_name, 'w')
175
+ @report_content_2 = @report_content_2 + '<tr>
174
176
  <td class=bborder_left width=' + @col_1_p + '><p>&nbsp;</p></td>
175
177
  <td class=bborder_left width=' + @col_2_p + '><p>&nbsp;</p></td>
176
178
  <td class=bborder_left width=' + @col_3_p + '><p>&nbsp;</p></td>
179
+ <td class=bborder_left width=' + @col_4_p + '><p>&nbsp;</p></td>
177
180
  </tr>
178
181
  </table>'
182
+ rpt_file.puts(@report_content_1)
183
+ rpt_file.puts(@report_content_2)
184
+ rpt_file.close
179
185
 
180
- rpt_file.puts(@reportContent1)
186
+ # JSON report
187
+ rpt_json = File.open(self.json_file_name, 'w')
188
+ rpt_json.puts(@json_content.to_json)
189
+ rpt_json.close
181
190
 
182
- rpt_file.puts(@reportContent2)
191
+ self.html_file_name
183
192
 
184
- # Close the report
185
- rpt_file.close
186
193
  end
187
194
  end
188
195
  end
@@ -1,7 +1,8 @@
1
1
  module Awetestlib
2
2
  # Logging and reporting.
3
- module Logging
4
3
 
4
+ module Logging
5
+ include ActiveSupport
5
6
  # @deprecated
6
7
  def self.included(mod)
7
8
  # puts "RegressionSupport::Logging extended by #{mod}"
@@ -13,39 +14,44 @@ module Awetestlib
13
14
  # @param [String] message The message to be placed in the log.
14
15
  # @param [String, Fixnum] tag Indicates the type of message. Valid string values are 'FAIL' and 'PASS'.
15
16
  # 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
17
+ def log_message(severity, message, tag = '', who_called = nil, exception = nil)
18
+ level = nil
24
19
 
25
20
  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 + ']:'
21
+ @last_ts ||= t
22
+ duration = (t.to_f - @last_ts.to_f)
23
+
24
+ # durations = calculate_durations(tag, t = Time.now.utc)
25
+
26
+ tstmp = t.strftime("%H%M%S") + '.' + t.to_f.modulo(t.to_i).to_s.split('.')[1].slice(0, 5)
27
+ my_sev = translate_severity(severity)
28
+ my_msg = '%-8s' % my_sev
29
+ my_msg << '[' + tstmp + ']:'
30
+
31
+ my_msg << "[#{'%9.5f' % duration}]:"
32
+
34
33
  if tag
35
34
  if tag.is_a? Fixnum
35
+ level = tag.to_i
36
36
  tag = '-LVL' + tag.to_s
37
37
  end
38
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
39
+ my_msg << '[%-6s][:' % tag
46
40
 
47
- @myLog.add(severity, myMsg) if @myLog # add persistent logging for awetestlib. pmn 05jun2012
48
- puts myMsg+"\n"
41
+ unless who_called
42
+ who_called = exception.nil? ? get_debug_list(false, true, true) : get_caller(exception)
43
+ end
44
+ my_msg << who_called
45
+
46
+ my_msg << ']: ' + message
47
+
48
+ @logger.add(severity, my_msg) if @logger
49
+
50
+ puts my_msg + "\n"
51
+
52
+ @report_class.add_to_report(message, who_called, text_for_level(tag), duration, level) if tag and tag.length > 0
53
+
54
+ @last_ts = t
49
55
 
50
56
  nil # so method doesn't return whole @output.
51
57
  end
@@ -55,20 +61,24 @@ module Awetestlib
55
61
  # Translates tag value to corresponding value for +pass+ column in database.
56
62
  # @private
57
63
  # @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'
64
+ # @return [String] Single word
65
+ def text_for_level(tag)
66
+ case tag
67
+ when /PASS/
68
+ 'PASSED'
69
+ when /FAIL/
70
+ 'FAILED'
65
71
  #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
+ when /\d+/
73
+ unless tag == '0'
74
+ tag.to_s
75
+ end
76
+ when /DONE/
77
+ 'DONE'
78
+ when /role/
79
+ 'ROLE'
80
+ else
81
+ ''
72
82
  end
73
83
  end
74
84
 
@@ -77,11 +87,11 @@ module Awetestlib
77
87
  output_lines = File.open(output_file, 'r') { |f| f.readlines }
78
88
  puts "IM FAILING?! #{passed}"
79
89
 
80
- # if passed
90
+ # if passed
81
91
 
82
92
  log_messages = ['[log]', '[error]']
83
93
  output_lines = output_lines.select { |l| log_messages } #.detect{|msg| l.include?(msg)} }
84
- while line = output_lines.shift do
94
+ while line == output_lines.shift do
85
95
  puts "line to be logged: #{line}"
86
96
  if line.include? '[log]'
87
97
  passed_to_log line
@@ -91,7 +101,7 @@ module Awetestlib
91
101
  failed_to_log output_lines.join("\n")
92
102
  break
93
103
  else
94
- debug_tolog line
104
+ debug_to_log line
95
105
  end
96
106
  end
97
107
 
@@ -102,7 +112,6 @@ module Awetestlib
102
112
  return { :result => passed, :msg => output_lines }
103
113
  end
104
114
 
105
-
106
115
  # Write a status message to the log and report indicating location or activity
107
116
  # in the script. mark_test_level automatically determines the call hierarchy level
108
117
  # of the calling method within the script and project utility methods. The top level
@@ -113,33 +122,41 @@ module Awetestlib
113
122
  # @param [Fixnum] lvl '0' forces a message to the report without a specific level
114
123
  # attached. Any other integer is ignored in favor of the calculated level
115
124
  # @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}")
125
+ # @param [Boolean] trc When set to true adds a trace to the message.
126
+ # @return [Boolean] Always returns true
127
+ def mark_test_level(message = '', lvl = nil, desc = '', caller = 1, wai_lvl = 4, trc = $debug)
121
128
  strg = ''
122
- call_script, call_line, call_meth = parse_caller(call_arr[1])
129
+ list = nil
130
+ call_arr = get_call_array
131
+
132
+ debug_to_log("#{call_arr.to_yaml}") if trc
133
+ call_script, call_line, call_meth = parse_caller(call_arr[caller])
134
+
123
135
  if not lvl or lvl > 1
124
136
  lvl, list = get_test_level
125
- strg << "#{call_meth.titleize}"
137
+ strg << "#{call_meth.titleize}: "
138
+ end
139
+
140
+ if lvl == 0
141
+ parse_error_references(message)
126
142
  end
127
- strg << " #{message}" if message.length > 0
143
+ strg << "#{message}" if message.length > 0
128
144
  strg << " (#{desc})" if desc.length > 0
129
- strg << " [#{call_line}]" if dbg or @debug_calls
130
- strg << "\n#{list.to_yaml}" if dbg or @debug_calls
131
- @report_class.add_to_report(strg, "&nbsp", "&nbsp", lvl || 1) unless Awetestlib::Runner.nil?
132
- log_message(INFO, strg, lvl, nil, 1)
145
+ strg << " [#{call_line}]" if trc
146
+ strg << "\n#{list.to_yaml}" if list and trc
147
+
148
+ log_message(INFO, strg, lvl, where_am_i?(wai_lvl))
149
+ true
133
150
  rescue
134
- failed_to_log("#{__method__}: #{$!}")
151
+ failed_to_log(unable_to)
135
152
  end
136
153
 
137
154
  alias mark_testlevel mark_test_level
138
155
 
139
156
  # @param [String] message The text to place in the log
140
157
  # @return [void]
141
- def info_to_log(message, lnbr = nil)
142
- log_message(INFO, message, 0, lnbr)
158
+ def info_to_log(message, wai_lvl = 1)
159
+ log_message(INFO, message, '', where_am_i?(wai_lvl))
143
160
  end
144
161
 
145
162
  alias message_tolog info_to_log
@@ -148,9 +165,12 @@ module Awetestlib
148
165
 
149
166
  # @param [String] message The text to place in the log and report
150
167
  # @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)
168
+ def debug_to_log(message, wai_lvl = 3)
169
+ message << "\n#{get_debug_list}" if $debug
170
+ scr_lvl = first_script_index
171
+ lvl = scr_lvl > 0 ? scr_lvl : wai_lvl
172
+ log_message(DEBUG, "#{message}", nil, where_am_i?(lvl))
173
+ true
154
174
  end
155
175
 
156
176
  alias debug_tolog debug_to_log
@@ -158,20 +178,25 @@ module Awetestlib
158
178
  # @note Do not use for failed validations. Use only for serious error conditions.
159
179
  # @return [void]
160
180
  # @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)
181
+ def error_to_log(message, wai_lvl = 3, exception = nil)
182
+ scr_lvl = first_script_index
183
+ lvl = scr_lvl > 0 ? scr_lvl : wai_lvl
184
+ log_message(ERROR, message, nil, where_am_i?(lvl), exception)
185
+ false
163
186
  end
164
187
 
165
188
  alias error_tolog error_to_log
166
189
 
167
190
  # @param [String] message The text to place in the log and report
168
191
  # @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)
192
+ def passed_to_log(message, wai_lvl = 3, dbg = false)
193
+ message << " \n#{get_debug_list}" if $debug
171
194
  @my_passed_count += 1 if @my_passed_count
172
195
  parse_error_references(message)
173
- @report_class.add_to_report(message, get_caller(lnbr), "PASSED") unless Awetestlib::Runner.nil?
174
- log_message(INFO, "#{message}", PASS, lnbr)
196
+ scr_lvl = first_script_index
197
+ lvl = scr_lvl > 0 ? scr_lvl : wai_lvl
198
+ log_message(INFO, "#{message}", PASS, where_am_i?(lvl))
199
+ true
175
200
  end
176
201
 
177
202
  alias validate_passed_tolog passed_to_log
@@ -182,12 +207,14 @@ module Awetestlib
182
207
 
183
208
  # @param [String] message The text to place in the log and report
184
209
  # @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
210
+ def failed_to_log(message, wai_lvl = 3, exception = nil)
211
+ message << " \n#{get_debug_list}" if $debug
187
212
  @my_failed_count += 1 if @my_failed_count
188
213
  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)
214
+ scr_lvl = first_script_index
215
+ lvl = scr_lvl > 0 ? scr_lvl : wai_lvl
216
+ log_message(WARN, "#{message}", FAIL, where_am_i?(lvl), exception)
217
+ false
191
218
  end
192
219
 
193
220
  alias validate_failed_tolog failed_to_log
@@ -198,168 +225,212 @@ module Awetestlib
198
225
 
199
226
  # @param [String] message The text to place in the log and report
200
227
  # @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)
228
+ def fatal_to_log(message, wai_lvl = 3, exception = nil)
229
+ message << " #{get_debug_list}"
203
230
  @my_failed_count += 1 if @my_failed_count
204
231
  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)
232
+ debug_to_report("#{__method__}:\n#{dump_caller(nil)}")
233
+ scr_lvl = first_script_index
234
+ lvl = scr_lvl > 0 ? scr_lvl : wai_lvl
235
+ log_message(FATAL, "#{message} '#{$!}'", FAIL, where_am_i?(lvl), exception)
236
+ false
208
237
  end
209
238
 
210
239
  alias fatal_tolog fatal_to_log
211
240
 
212
241
  # @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)
242
+ # @return [Boolean] Always returns true
243
+ def message_to_report(message, wai_lvl = 4)
244
+ scr_lvl = first_script_index
245
+ lvl = scr_lvl > 0 ? scr_lvl : wai_lvl
246
+ mark_test_level(message, 0, '', 1, lvl + 1)
247
+ true
216
248
  end
217
249
 
218
250
  # @param [String] message The text to place in the log and report
219
251
  # @return [void]
220
- def debug_to_report(message, dbg = false)
221
- mark_testlevel("(DEBUG): ", 0, "#{message}", dbg)
252
+ def debug_to_report(message, wai_lvl = 4)
253
+ scr_lvl = first_script_index
254
+ lvl = scr_lvl > 0 ? scr_lvl : wai_lvl
255
+ mark_test_level("(DEBUG): ", 0, "#{message}", 1, lvl + 1)
256
+ true
222
257
  end
223
258
 
224
259
  # @private
225
- # @return [Fixnum] required by logger.
260
+ # @severity [Fixnum] used by logger.
226
261
  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'
262
+ case severity
263
+ when 0
264
+ 'DEBUG'
265
+ when 1
266
+ 'INFO'
267
+ when 2
268
+ 'WARN'
269
+ when 3
270
+ 'ERROR'
271
+ when 4
272
+ 'FATAL'
273
+ when 4
274
+ 'UNKNOWN'
275
+ else
276
+ ''
241
277
  end
242
- mySev
243
278
  end
244
279
 
245
280
  # @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
281
+ def get_call_array(depth = 9)
282
+ arr = []
283
+ call_list = Kernel.caller
284
+ call_list.each_index do |x|
285
+ my_caller = call_list[x].to_s
286
+ my_caller =~ /([\(\)\w_\_\-\.]+\:\d+\:.*?)$/
287
+ # myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
288
+ arr << $1.gsub(/eval/, @myName)
289
+ break if x > depth or my_caller =~ /:in .run.*$/
290
+ end
291
+ arr
292
+ rescue
293
+ failed_to_log(unable_to)
294
+ end
295
+
296
+ # @private
297
+ def get_caller(exception = nil)
298
+ # TODO: Awetestlib no longer supports script types 'Selenium' or 'MobileNativeApp'.
299
+ # Those are supported directly by Shamisen and Awetest
300
+ # script_name ||= File.basename(@myName)
301
+ # if lnbr && script_type.eql?("Selenium")
302
+ # [script_name, lnbr, 'in run()'].join(":")
303
+ # elsif lnbr && script_type.eql?("MobileNativeApp")
304
+ # [script_name, lnbr, 'in scenario()'].join(":")
305
+ # else
253
306
  caller_object = exception ? exception.backtrace : Kernel.caller
254
307
  call_frame = caller_object.detect do |frame|
255
- frame.match(/#{script_name}/) or (library && frame.match(/#{library}/))
308
+ frame.match(/#{self.script_name}/) or
309
+ (@library && frame.match(/#{@library}/)) or
310
+ (@library2 && frame.match(/#{@library2}/))
256
311
  end
257
- unless call_frame.nil?
312
+ if call_frame.nil?
313
+ 'unknown'
314
+ else
258
315
  call_frame.gsub!(/^C:/, '')
259
316
  file, line, method = call_frame.split(":")
260
317
  [File.basename(file), line, method].join(":")
261
- else
262
- 'unknown'
263
318
  end
264
- end
319
+ # end
265
320
  end
266
321
 
267
322
  # @private
268
- def init_logger(logFile, scriptName = nil)
269
- if File.exist?(logFile)
270
- puts "==> Logfile already exists: #{logFile}. Replacing it."
323
+ def init_logger(log_spec, script_name = nil)
324
+ if File.exist?(log_spec)
325
+ puts "==> log_spec already exists: #{log_spec}. Replacing it."
271
326
  begin
272
- File.delete(logFile)
327
+ File.delete(log_spec)
273
328
  rescue
274
- puts "#{scriptName}: init_logger RESCUE: #{$!}"
329
+ puts "#{script_name}: init_logger RESCUE: #{$!}"
275
330
  end
276
331
  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"]}")
332
+ logger = ActiveSupport::Logger.new(log_spec)
333
+ logger.level = ActiveSupport::Logger::DEBUG
334
+ # logger.auto_flushing = (true)
335
+ logger.add(INFO, "#{log_spec}\n#{ENV["OS"]}")
281
336
  logger
282
337
  end
283
338
 
284
339
  #private init_logger
285
340
 
286
341
  # @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}"
342
+ def log_begin_run(begin_time)
343
+ message_to_report(">> Running on host '#{$os.nodename}'")
344
+ message_to_report(">> Running #{$os.name} version #{$os.version}")
345
+ @my_failed_count = 0 unless @my_failed_count
346
+ @my_passed_count = 0 unless @my_passed_count
347
+ utc_ts = begin_time.getutc
348
+ loc_tm = "#{begin_time.strftime("%H:%M:%S")} #{begin_time.zone}"
291
349
  message_to_report(">> Starting #{@myName.titleize} #{utc_ts} (#{loc_tm})")
350
+ debug_to_log("\nAwetestlib #{$metadata.to_yaml}")
351
+ rescue
352
+ failed_to_log(unable_to)
292
353
  end
293
354
 
294
- alias start_to_log start_run
295
-
296
355
  # @private
297
356
  # Tally and report duration, validation and failure counts, and end time for the script.
298
357
  # @param [DateTime] ts Time stamp indicating the time the script completed.
299
- def finish_run(ts = Time.now)
358
+ def log_finish_run(ts = Time.now, begin_time = $begin_time)
300
359
  tally_error_references
301
360
  message_to_report(
302
- ">> #{@myName.titleize} duration: #{sec2hms(ts - @start_timestamp)}")
361
+ ">> #{@myName.titleize} duration: #{sec2hms(ts - begin_time)}")
303
362
  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
363
+ "fail: #{@my_failed_count}]") if @my_passed_count and @my_failed_count
305
364
  utc_ts = ts.getutc
306
365
  loc_tm = "#{ts.strftime("%H:%M:%S")} #{ts.zone}"
307
366
  message_to_report(">> End #{@myName.titleize} #{utc_ts} (#{loc_tm})")
308
367
  end
309
368
 
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")
369
+ def calculate_durations(tag, t = Time.now.utc)
370
+ last_log_ts ||= t
371
+ last_lvl_ts ||= t
372
+ last_val_ts ||= t
373
+ log_dur = "%9.5f" % (t.to_f - last_log_ts.to_f)
374
+ lvl_dur = "%9.5f" % (t.to_f - last_lvl_ts.to_f)
375
+ val_dur = "%9.5f" % (t.to_f - last_val_ts.to_f)
376
+ last_log_ts = t
377
+ case tag
378
+ when /LVL/i
379
+ last_lvl_ts = t
380
+ dur = lvl_dur
381
+ when /PASS|FAIL/i
382
+ last_val_ts = t
383
+ dur = val_dur
331
384
  else
332
- message_to_report(">> No Error or Test Case References found.")
333
- end
385
+ dur = log_dur
334
386
  end
387
+ [dur, log_dur, lvl_dur, val_dur]
335
388
  end
336
389
 
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, '')
390
+ def with_caller(message = '', *strings)
391
+ call_arr = get_call_array
392
+ call_script, call_line, call_meth = parse_caller(call_arr[1])
393
+ strg = "#{call_meth.titleize}"
394
+ strg << ':' # if strings.size > 0
395
+ strg << ' '
396
+ strg << build_message(message, *strings)
397
+ strg
398
+ end
399
+
400
+ alias message_with_caller with_caller
401
+ alias msg_with_caller with_caller
402
+
403
+ def where_am_i?(index = 2)
404
+ index = index ? index : 2
405
+ calls = get_call_list_new
406
+ log_message(DEBUG, "=== #{__LINE__}\n#{calls.to_yaml}\n===") if $debug
407
+ if calls[index]
408
+ where = calls[index].dup.to_s
409
+ here = where.gsub(/^\[/, '').gsub(/\]\s*$/, '')
410
+ else
411
+ here = 'unknown'
343
412
  end
413
+ here
414
+ rescue
415
+ failed_to_log(unable_to)
344
416
  end
345
417
 
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
418
+ def first_script_index(script = @myName)
419
+ here = 0
420
+ call_list = get_call_list_new
421
+ debug_to_log(DEBUG, with_caller("=== #{__LINE__}\n#{call_list.to_yaml}\n===")) if $debug
422
+ call_list.each_index do |x|
423
+ a_caller = call_list[x].to_s
424
+ a_caller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
425
+ caller = $1
426
+ if caller =~ /#{script}/
427
+ here = x
428
+ break
354
429
  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
430
  end
431
+ here
432
+ rescue
433
+ failed_to_log(unable_to)
363
434
  end
364
435
 
365
436
  end