Class: ReportingGroups

Inherits:
Object show all
Defined in:
lib/tdriver/report/report_grouping.rb

Instance Method Summary collapse

Constructor Details

#initialize(tdriver_groups, test_cases_array, grouping = true) ⇒ ReportingGroups

Returns a new instance of ReportingGroups.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tdriver/report/report_grouping.rb', line 22

def initialize(tdriver_groups,test_cases_array,grouping=true)
  #@reporting_groups='Common:Application:Close:Open|Common:Connect to|Common:Disconnect|Qt:Tap|Qt:Drag:Drag to|Qt:Type Text'
  if tdriver_groups != nil
    @reporting_groups=clean_reporting_groups(tdriver_groups)
  else
    @reporting_groups=nil
  end
  @main_groups=Array.new
  @main_groups_sub_level_one=Array.new
  @main_groups_sub_level_two=Array.new
  @main_groups_sub_level_three=Array.new
  @main_groups_sub_level_four=Array.new
  @main_groups_sub_level_five=Array.new
  #Group statistics
  @main_total=0
  @main_passed=0
  @main_failed=0
  @main_not_run=0
  @group_test_case_arr=Array.new(test_cases_array)
  @grouping=grouping
  @pass_statuses= $parameters[ :report_passed_statuses, "passed" ].split('|')
  @fail_statuses= $parameters[ :report_failed_statuses, "failed" ].split('|')
  @not_run_statuses= $parameters[ :report_not_run_statuses, "not run" ].split('|')
end

Instance Method Details

#check_duplicate_groups(group_arr, group) ⇒ Object



149
150
151
152
153
154
155
156
157
158
# File 'lib/tdriver/report/report_grouping.rb', line 149

def check_duplicate_groups(group_arr,group)
  b_group_exists=false
  group_arr.each do |existing_group|
    if existing_group[0] == group
      b_group_exists=true
      break
    end
  end
  b_group_exists
end

#check_duplicate_sub_groups(group_arr, main_group, sub_group) ⇒ Object



159
160
161
162
163
164
165
166
167
168
# File 'lib/tdriver/report/report_grouping.rb', line 159

def check_duplicate_sub_groups(group_arr,main_group,sub_group)
  b_group_exists=false
  group_arr.each do |existing_group|
    if existing_group[0].to_s == main_group.to_s && existing_group[1].to_s == sub_group.to_s
      b_group_exists=true
      break
    end
  end
  b_group_exists
end

#clean_reporting_groups(report_group_string) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/tdriver/report/report_grouping.rb', line 46

def clean_reporting_groups(report_group_string)
  cleaned_group_string=''
  reporting_groups_arr=report_group_string.split('|')
  reporting_groups_arr.each do |main|
    groups_arr=main.split(':')
    first=true
    groups_arr.each do |sub|
      if first==true
        cleaned_group_string+=sub.strip
        first=false
      else
        cleaned_group_string+=':'+sub.strip
      end
    end
    cleaned_group_string+='|'
  end
  cleaned_group_string
end

#generate_report(status) ⇒ Object



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
# File 'lib/tdriver/report/report_grouping.rb', line 455

def generate_report(status)
  html_body=Array.new    
  if @grouping==true
    @main_groups.each do |group|
      @main_total=0
      @main_passed=0
      @main_failed=0
      @main_not_run=0
      group_body=Array.new
      group_body << tog_list_begin(group,@group_test_case_arr,status,'main')
      group_body << generate_test_results_table(status,@group_test_case_arr,[group,group])
      tog_list1=0
      tog_list2=0
      tog_list3=0
      tog_list4=0
      tog_list5=0
      @main_groups_sub_level_one.each do |item1|

        if group.to_s == item1.at(0).to_s && @reporting_groups.include?(group.to_s+':'+item1.at(1).to_s)
          tog_list1=tog_list_begin(item1.at(1).to_s,@group_test_case_arr,status)
          if tog_list1 != 0
            group_body << tog_list1
            group_body << generate_test_results_table(status,@group_test_case_arr,item1)
          end
          @main_groups_sub_level_two.each do |item2|
            if group.to_s == item2.at(0).to_s && @reporting_groups.include?(item1.at(1).to_s+':'+item2.at(1).to_s)
              tog_list2=tog_list_begin(item2.at(1).to_s,@group_test_case_arr,status)
              if tog_list2 != 0
                group_body << tog_list2
                group_body << generate_test_results_table(status,@group_test_case_arr,item2)
              end
              @main_groups_sub_level_three.each do |item3|
                if group.to_s == item3.at(0).to_s && @reporting_groups.include?(item2.at(1).to_s+':'+item3.at(1).to_s)
                  tog_list3=tog_list_begin(item3.at(1).to_s,@group_test_case_arr,status)
                  if tog_list3 != 0
                    group_body << tog_list3
                    group_body << generate_test_results_table(status,@group_test_case_arr,item3)
                  end
                  @main_groups_sub_level_four.each do |item4|
                    if group.to_s == item4.at(0).to_s && @reporting_groups.include?(item3.at(1).to_s+':'+item4.at(1).to_s)
                      tog_list4=tog_list_begin(item4.at(1).to_s,@group_test_case_arr,status)
                      if tog_list4 != 0
                        group_body << tog_list4
                        group_body << generate_test_results_table(status,@group_test_case_arr,item4)
                      end
                      @main_groups_sub_level_five.each do |item5|
                        if group.to_s == item5.at(0).to_s && @reporting_groups.include?(item4.at(1).to_s+':'+item5.at(1).to_s)
                          tog_list5=tog_list_begin(item5.at(1).to_s,@group_test_case_arr,status)
                          if tog_list5 != 0
                            group_body << tog_list5
                            group_body << generate_test_results_table(status,@group_test_case_arr,item5)
                            group_body << tog_list_end()
                          end
                        end
                      end
                      if tog_list4 != 0
                        group_body << tog_list_end()
                      end
                    end
                  end
                  if tog_list3 != 0
                    group_body << tog_list_end()
                  end
                end
              end
              if tog_list2 != 0
                group_body << tog_list_end()
              end
            end
          end
          if tog_list1 != 0
            group_body << tog_list_end()
          end
        end
      end
      group_body << tog_list_end('main')
      html_body << group_body if @main_total > 0
    end
    html_body << generate_test_results_table(status,@group_test_case_arr,['not_in_any_user_defined_group','not_in_any_user_defined_group'])
  else
    #html_body << tog_list_begin('Total run',@group_test_case_arr,status,'main')
    html_body << generate_test_results_table(status,@group_test_case_arr,nil)
    html_body << tog_list_end('main')
  end
  html_body
end

#generate_test_results_table(status, tc_arr, item) ⇒ Object



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# File 'lib/tdriver/report/report_grouping.rb', line 261

def generate_test_results_table(status,tc_arr,item)
  table_body=Array.new
  if item==nil
    cases_in_group=0
    element=0
    table_body='<table align="center" style="width:100%;">'<<
      '<tr>'<<
      '<td>'<<
      '<b>Execution</b></td>'<<
      '<td>'<<
      '<b>Start Time</b></td>'<<
      '<td>'<<
      '<b>Name</b></td>'<<
      '<td>'<<
      '<b>Duration</b></td>'<<
      '<td>'<<
      '<b>Memory</b></td>'<<
      '<td>'<<
      '<b>Result</b></td>'<<
      '<td>'<<
      '<b>Comment</b></td>'
      
    user_cols=get_user_cols(status,tc_arr)
    if (user_cols!=nil && !user_cols.empty?)
      user_cols.sort.each do |col|
        table_body<<'<td>'<<'<b>'<<col.to_s<<'</b></td>'
      end
    end

    table_body<<'</tr>'
    
    tc_arr.each do |x|        
      cases_in_group+=1
      @main_total+=1
      tc_status=x[7].to_s
      tc_style_tag=' id=""'
      tc_style_tag=' id="passed_case"' if tc_status=='passed' || @pass_statuses.include?(tc_status)
      tc_style_tag=' id="failed_case"' if tc_status=='failed' || @fail_statuses.include?(tc_status)
      tc_style_tag=' id="not_run_case"' if tc_status=='not run' || @not_run_statuses.include?(tc_status)
      @main_passed+=1 if tc_status=='passed' || @pass_statuses.include?(tc_status)
      @main_failed+=1 if tc_status=='failed' || @fail_statuses.include?(tc_status)
      @main_not_run+=1 if tc_status=='not run' || @not_run_statuses.include?(tc_status)
      tc_name=x[0].to_s.gsub('_',' ')
      
      table_body << '<tr' <<
        tc_style_tag <<
        '>'<<
      '<td>'<<
        x[8]<< #testcase execution number
      '</td>'<<
        '<td>'<<
        x[4]<< #testcase start time
      '</td>'<<
        '<td><a name="'+tc_name.gsub(' ','_')+'_'+tc_status.to_s.gsub(' ','_')+'"></a>'<<
        '<a href="'<<
        x[11]<<
        '">'<<
        tc_name<<
        '</a></td>'<<
        '<td>'<<
        x[5]<< #testcase duration
      '</td>'<<
        '<td>'<<
        x[6]<< #testcase memory usage
      '</td>'<<
        '<td>'<<
        status_select(x[8],tc_status) <<
        '</td>'<<
        '<td>'<<
        "<textarea name=\"#{x[8]}_text_area\"  cols=\"23\" rows=\"2\">#{x[10]}</textarea>" <<
        '</td>'

        data_hash=x[12] 
        if (data_hash!=nil && !data_hash.empty?)
          #display user data
          pad_user_data(status,data_hash,user_cols)
          user_cols.sort.each do |col|
            row = '<td>'+data_hash[col].to_s+'</td>'
            table_body<<row
          end
        end
        table_body<<'</tr>'
    end
    if cases_in_group>0
      table_body << '</table>'
    else
      table_body='<br/>'
    end
  else
    if status=='all'
      cases_in_group=0
      element=0
      table_body='<table align="center" style="width:100%;">'<<
        '<tr>'<<
        '<td>'<<
        '<b>Name</b></td>'<<
        '<td>'<<
        '<b>Result</b></td>'<<
        '<td>'<<
        '<b>Comment</b></td>'<<
        '</tr>'
      tc_arr.each do |x|
        if x[1]==item.at(1).to_s
          cases_in_group+=1
          @main_total+=1
          tc_status=x[7].to_s
          tc_style_tag=' id=""'
          tc_style_tag=' id="passed_case"' if tc_status=='passed' || @pass_statuses.include?(tc_status)
          tc_style_tag=' id="failed_case"' if tc_status=='failed' || @fail_statuses.include?(tc_status)
          tc_style_tag=' id="not_run_case"' if tc_status=='not run' || @not_run_statuses.include?(tc_status)
          @main_passed+=1 if tc_status=='passed' || @pass_statuses.include?(tc_status)
          @main_failed+=1 if tc_status=='failed' || @fail_statuses.include?(tc_status)
          @main_not_run+=1 if tc_status=='not run' || @not_run_statuses.include?(tc_status)
          tc_name=x[0].to_s.gsub('_',' ')
          table_body << '<tr' <<
            tc_style_tag<<
            '>'<<
            '<td>'<<
            '<a href="'<<
            x[11]<<
            '">'<<
            tc_name<<
            '</a></td>'<<
            '<td>'<<
            status_select(x[8],tc_status) <<
            '</td>'<<
            '<td>'<<
            "<textarea name=\"#{x[8]}_text_area\"  cols=\"23\" rows=\"2\">#{x[10]}</textarea>" <<
            '</td>'<<
            '</tr>'
          @group_test_case_arr[element]=['--','--']
        end
        element+=1
      end
      if cases_in_group>0
        table_body << '</table>'
      else
        table_body='<br/>'
        
      end
    else
      tc_style_tag=' id=""'
      tc_style_tag=' id="passed_case"' if status=='passed' || @pass_statuses.include?(status)
      tc_style_tag=' id="failed_case"' if status=='failed' || @fail_statuses.include?(status)
      tc_style_tag=' id="not_run_case"' if status=='not run' || @not_run_statuses.include?(status)
      cases_in_group=0
      element=0
      table_body='<table align="center" style="width:100%;">'<<
        '<tr>'<<
        '<td>'<<
        '<b>Name</b></td>'<<
        '<td>'<<
        '<b>Result</b></td>'<<
        '<td>'<<
        '<b>Comment</b></td>'<<
        '</tr>'
      tc_arr.each do |x|
        if x[1]==item.at(1).to_s
          @main_total+=1
          @main_passed+=1 if status=='passed' || @pass_statuses.include?(status)
          @main_failed+=1 if status=='failed' || @fail_statuses.include?(status)
          @main_not_run+=1 if status=='not run' || @not_run_statuses.include?(status)
          cases_in_group+=1
          tc_status=x[7]
          tc_name=x[0].to_s.gsub('_',' ')
          table_body << '<tr' <<
            tc_style_tag<<
            '>'<<
            '<td>'<<
            '<a href="'<<
            x[11]<<
            '">'<<
            tc_name<<
            '</a></td>'<<
            '<td>'<<
            status_select(x[8],tc_status) <<
            '</td>'<<
            '<td>'<<
            "<textarea name=\"#{x[8]}_text_area\"  cols=\"23\" rows=\"2\">#{x[10]}</textarea>" <<
            '</td>'<<
            '</tr>'
          @group_test_case_arr[element]=['--','--']
        end
        element+=1
      end
      if cases_in_group > 0
        table_body << '</table>'
      else
        table_body='<br/>'
      end
    end
  end
  table_body
end

#get_user_cols(status, tc_arr) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/tdriver/report/report_grouping.rb', line 239

def get_user_cols(status,tc_arr)
  cols=nil
  if status=='all' && tc_arr!= nil 
    cols = Array.new
    tc_arr.each do |x|
      data_hash=x[12]
      cols << data_hash.keys
    end
    cols=cols.flatten.uniq
  end
  cols
end

#pad_user_data(status, data_hash, all_cols) ⇒ Object



252
253
254
255
256
257
258
259
# File 'lib/tdriver/report/report_grouping.rb', line 252

def pad_user_data(status,data_hash,all_cols)
  if (status=='all' && all_cols!=nil && !all_cols.empty?)
    keys_need_adding = all_cols - data_hash.keys
    keys_need_adding.each do |new_key|
      data_hash[new_key] = "-"
    end
  end
end

#parse_groupsObject



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/tdriver/report/report_grouping.rb', line 169

def parse_groups()
  if @reporting_groups != nil
    reporting_groups_arr=@reporting_groups.split('|')
    reporting_groups_arr.each do |groups|
      groups_arr=groups.split(':')
      if check_duplicate_groups(@main_groups,groups_arr[0])==false
        @main_groups << [groups_arr[0]]
      end
      current_level=0
      groups_arr.each do |group|
        if current_level==1
          if check_duplicate_sub_groups(@main_groups_sub_level_one,groups_arr[0],group)==false
            @main_groups_sub_level_one << [[groups_arr[0]],[group]]
          end
        end
        if current_level==2
          if check_duplicate_sub_groups(@main_groups_sub_level_two,groups_arr[0],group)==false
            @main_groups_sub_level_two << [[groups_arr[0]],[group]]
          end
        end
        if current_level==3
          if check_duplicate_sub_groups(@main_groups_sub_level_three,groups_arr[0],group)==false
            @main_groups_sub_level_three << [[groups_arr[0]],[group]]
          end
        end
        if current_level==4
          if check_duplicate_sub_groups(@main_groups_sub_level_four,groups_arr[0],group)==false
            @main_groups_sub_level_four << [[groups_arr[0]],[group]]
          end
        end
        if current_level==5
          if check_duplicate_sub_groups(@main_groups_sub_level_five,groups_arr[0],group)==false
            @main_groups_sub_level_five << [[groups_arr[0]],[group]]
          end
        end
        current_level+=1
      end
    end
  end
end

#status_select(selection_index, selected_status) ⇒ Object



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/tdriver/report/report_grouping.rb', line 209

def status_select(selection_index, selected_status)
  
  status_selection = "<select name=\"#{selection_index}_status_select\">"
  selection_data=''
  @pass_statuses.each do |status|
    if status==selected_status
      selection_data << "<option selected>#{status}</option>"
    else
      selection_data << "<option>#{status}</option>"
    end
  end
  @fail_statuses.each do |status|
    if status==selected_status
      selection_data << "<option selected>#{status}</option>"
    else
      selection_data << "<option>#{status}</option>"
    end
  end
  @not_run_statuses.each do |status|
    if status==selected_status
      selection_data << "<option selected>#{status}</option>"
    else
      selection_data << "<option>#{status}</option>"
    end
  end
                              
  status_selection << selection_data << "</select>"
  status_selection
end

#tog_list_begin(name, tc_arr, status, main = nil) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/tdriver/report/report_grouping.rb', line 100

def tog_list_begin(name,tc_arr,status,main=nil)
  if main==nil
    test_statistics=tog_list_statistics(tc_arr,name,status)
    if test_statistics != 0
      html_body='<dl class="togList">'<<
        '<dt onclick="tog(this)" style="background-color: #CCCCCC;"><b><span><input id="Button1" type="button" value="Close" class="btn" /></span> '<<
        name.to_s<<
        '</b> '<<
        '</dt>'<<
        '<dt>'<<
        test_statistics<<
        '</dt>'<<
        '<dd>'
    else
      html_body=0
    end
  else
    html_body='<dl class="togList">'<<
      '<dt onclick="tog(this)" style="background-color: #CCCCCC;"><b><span><input id="Button1" type="button" value="Close" class="btn" /></span> '<<
      name.to_s<<
      '</b> '<<
      '</dt>'<<
      '<dd>'
  end
  html_body
end

#tog_list_end(summary = nil) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/tdriver/report/report_grouping.rb', line 126

def tog_list_end(summary=nil)
  if summary == 'main'
    html_body='</dd>'<<
      '<dt>'<<
      '<b style="color: #00FF00"> Passed:</b>'<<
      @main_passed.to_s<<
      '<b style="color: #FF0000"> Failed:</b>'<<
      @main_failed.to_s<<
      '<b style="color: #808080"> Not run:</b>'<<
      @main_not_run.to_s<<
      '<b> Total:</b> '<<
      @main_total.to_s<<
      '</dt>'<<
      '</dl>'<<
      '<hr />'
  else
    html_body='</dd>'<<
      '</dl>'<<
      '<hr />'
  end

  html_body
end

#tog_list_statistics(tc_arr, group, status) ⇒ Object



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
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/tdriver/report/report_grouping.rb', line 64

def tog_list_statistics(tc_arr,group,status)
  status_row=''
  if status=='all'
    cases_in_group=0
    passed=0
    failed=0
    not_run=0
    tc_arr.each do |x|
      if x[1]==group
        cases_in_group+=1
        tc_status=x[7]
        passed+=1 if tc_status=='passed' || @pass_statuses.include?(tc_status)
        failed+=1 if tc_status=='failed' || @fail_statuses.include?(tc_status)
        not_run+=1 if tc_status=='not run' || @not_run_statuses.include?(tc_status)
      end
    end
    if cases_in_group > 0
      status_row = '<b style="color: #00FF00">Passed:</b>'+passed.to_s+' <b style="color: #FF0000">Failed:</b>'+failed.to_s+' <b style="color: #808080">Not run:</b>'+not_run.to_s+' <b>Total:</b>'+cases_in_group.to_s
    else
      status_row=0
    end
  else
    cases_in_group=0
    tc_arr.each do |x|
      if x[1]==group
        cases_in_group+=1
      end
    end
    if cases_in_group > 0
      status_row = '<b>Total:</b>'+cases_in_group.to_s
    else
      status_row=0
    end
  end
  status_row
end