Module: Awetestlib::Regression::Reporting

Defined in:
lib/awetestlib/regression/reporting.rb

Instance Method Summary collapse

Instance Method Details

#filter_call(call) ⇒ Object



90
91
92
93
94
# File 'lib/awetestlib/regression/reporting.rb', line 90

def filter_call(call)
  modl = call.match(/^(browser|logging|find|runner|tables|user_input|utilities|validations|waits|page_data|legacy|drag_and_drop|awetest)/) || ''
  meth = call.match(/in .(run|each)/) || ''
  true unless "#{modl}#{meth}".length > 0
end

#get_call_list(depth = 9, dbg = false) ⇒ Object Also known as: get_callers



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/awetestlib/regression/reporting.rb', line 13

def get_call_list(depth = 9, dbg = false)
  my_list   = []
  call_list = Kernel.caller
  debug_to_log(with_caller(call_list)) if dbg
  call_list.each_index do |x|
    my_caller = call_list[x].to_s
    my_caller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
    my_list << "[#{$1.gsub(/eval/, @myName)}] "
    break if x > depth or my_caller =~ /:in .run.$/
  end
  my_list
rescue
  failed_to_log(unable_to)
end

#get_call_list_new(depth = 15, dbg = $debug) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/awetestlib/regression/reporting.rb', line 30

def get_call_list_new(depth = 15, dbg = $debug)
  a_list    = ['[unknown]']
  proj_name = File.basename(@library) if @library
  call_list = Kernel.caller
  log_message(DEBUG, with_caller(call_list)) if dbg
  call_list.each_index do |x|
    a_caller = call_list[x].to_s
    a_caller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
    caller = $1
    if caller =~ /#{@myName}/
      a_list << "#{caller.gsub(/\(eval\)/, "(#{@myName})")}"
    elsif proj_name and caller =~ /#{proj_name}/
      a_list << "#{caller.gsub(/\(eval\)/, "(#{proj_name})")}" if proj_name
    elsif @library2 and caller =~ /#{@library2}/
      a_list << "#{caller.gsub(/\(eval\)/, "(#{@library2})")}" if @library2
    else
      a_list << "#{caller}"
    end
    next if a_caller =~ /:in .run.$/ and not a_caller.include?(@myName)
    break if x > depth
  end
  a_list
rescue
  failed_to_log(unable_to)
end

#get_caller_lineObject



7
8
9
10
11
# File 'lib/awetestlib/regression/reporting.rb', line 7

def get_caller_line
  last_caller = get_call_list[0]
  line        = last_caller.split(':', 3)[1]
  line
end

#get_debug_list(dbg = false, no_trace = false, last_only = false) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/awetestlib/regression/reporting.rb', line 56

def get_debug_list(dbg = false, no_trace = false, last_only = false)
  calls = get_call_array(10)
  debug_to_log(with_caller("*** #{__LINE__}\n#{calls.to_yaml}\n***")) if dbg
  arr = []
  calls.each_index do |ix|
    if ix > 1 # skip this method and the logging method
      if filter_call(calls[ix])
        arr << calls[ix]
      end
    end
  end
  debug_to_log(with_caller("*** #{__LINE__}\n#{arr.to_yaml}\n***")) if dbg
  if arr.length > 0
    list = ''
    arr.reverse.each do |l|
      if last_only
        list = l
        break
      else
        list << "=>#{l}"
      end
    end
    if no_trace
      "#{list}"
    else
      " [TRACE:#{list}]"
    end
  else
    ''
  end
rescue
  failed_to_log(unable_to)
end

#get_test_level(meth = nil) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/awetestlib/regression/reporting.rb', line 96

def get_test_level(meth = nil)
  arr       = []
  each_line = 0
  call_list = Kernel.caller
  #debug_to_log("#{call_list.to_yaml}")
  call_list.each_index do |x|
    myCaller = call_list[x].to_s
    myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
    string = $1
    unless string =~ /logging\.rb|mark_test_level|mark_test_level|debug_to_report|debug_toreport/
      if string.length > 0
        if string =~ /each|each_key/
          each_line = string.match(/\:(\d+)\:/)[1]
        elsif string.match(/\:(\d+)\:/)[1] == each_line
          next
        else
          arr << string.gsub(/eval/, @myName)
        end
      end
    end
    break if meth and string.match(/#{meth}/)
    break if myCaller =~ /:in .run.$|runner\.rb/
  end
  #debug_to_log("#{arr.length} #{nice_array(arr)}")
  [arr.length, arr]
end

#html_to_log(element) ⇒ Object

TODO: need to sanitize html for html report



124
125
126
# File 'lib/awetestlib/regression/reporting.rb', line 124

def html_to_log(element)
  debug_to_log("#{element}\n #{element.html}")
end

#initialize_reference_regexpObject



146
147
148
149
150
151
152
# File 'lib/awetestlib/regression/reporting.rb', line 146

def initialize_reference_regexp
  unless @reference_regexp.is_a?(Regexp)
    @reference_template = '(\*\*\*\s+@@@@\s+\*\*\*)'
    @reference_pattern  = @reference_template.sub('@@@@', '([\w\d_\s,-:;\?]+)')
    @reference_regexp   = Regexp.new(@reference_pattern)
  end
end

#report_results(errors, msg) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/awetestlib/regression/reporting.rb', line 283

def report_results(errors, msg)
  call_script, call_line, call_meth = parse_caller(get_call_array[1])
  msg                               = ">> SUMMARY: #{build_msg("#{call_meth.titleize}:", msg)}"
  if errors > 0
    mark_test_level("#{msg}  ::FAIL::")
  else
    mark_test_level("#{msg}  ::Pass::")
    true
  end
rescue
  failed_to_log(unable_to)
end