Method: TDriverReportCreator::TestCaseRun#capture_dump

Defined in:
lib/tdriver/report/report_test_case_run.rb

#capture_dump(take_screenshot = true, arguments = Hash.new) ⇒ Object

This method captures the failed xml dump and image

params

nil

returns

nil

raises



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# File 'lib/tdriver/report/report_test_case_run.rb', line 571

def capture_dump(take_screenshot=true,arguments=Hash.new)
  MobyUtil::Logger.instance.enabled=false
  image_html=Array.new
  state_html=Array.new
  self.set_test_case_execution_log('<hr />')
  begin
    dump_folder=@test_case_folder+'/state_xml'
    if File::directory?(dump_folder)==false
      FileUtils.mkdir_p dump_folder
    end
    TDriver::SUTFactory.connected_suts.each do |sut_id, sut_attributes|

      t = Time.now
      time_stamp=t.strftime( "%Y%m%d%H%M%S" )
      if take_screenshot==true
        begin
          sut_attributes[:sut].capture_screen( :Filename => dump_folder+'/'+time_stamp+'_'+sut_id.to_s+'_state.png', :Redraw => true ) if sut_attributes[:is_connected]
          if arguments[:file]
            base_name=File.basename(arguments[:file])
            base_folder=File.dirname(arguments[:file])
            sut_attributes[:sut].capture_screen( :Filename => "#{base_folder}/#{sut_id.to_s}_#{base_name}", :Redraw => true ) if sut_attributes[:is_connected]
          end
          image_html='<div class="img"><a href="state_xml/'<<
            time_stamp+'_'+sut_id.to_s+'_state.png'<<
            '" target="_blank"><img alt="" src="state_xml/'<<
            time_stamp+'_'+sut_id.to_s+'_state.png'<<
            '" width="10%" height="10%" /></a>'
          if arguments[:text]
            image_html << "<div class=\"desc\">#{arguments[:text]}</div>"
          end
          image_html << '</div>'
          self.set_test_case_execution_log(image_html.to_s)
        rescue Exception=>e
          @capture_screen_error="Unable to capture sceen image #{sut_id}: " + e.message
          self.set_test_case_execution_log(@capture_screen_error.to_s)
        end
      end

      begin
        if sut_attributes[:is_connected]
          original_filter=sut_attributes[:sut].parameter[ :filter_type]
          original_find=sut_attributes[:sut].parameter[ :use_find_object]
          sut_attributes[:sut].parameter[ :filter_type] = 'none'
          sut_attributes[:sut].parameter[ :use_find_object] = 'false'
          sut_attributes[:sut].refresh
          failed_xml_state=sut_attributes[:sut].xml_data()
          File.open(dump_folder+'/'+time_stamp+'_'+sut_id.to_s+'_state.xml', 'w') { |file| file.write(failed_xml_state) }
          state_html='<a href="state_xml/'<<
            time_stamp+'_'+sut_id.to_s+'_state.xml'<<
            '">'+time_stamp+'_'+sut_id.to_s+'_state.xml'+'</a>'
          self.set_test_case_execution_log(state_html.to_s)
        end
      rescue Exception=>e
        @failed_dump_error="Unable to capture state xml #{sut_id}: " + e.message
        self.set_test_case_execution_log(@failed_dump_error.to_s)
      ensure
        sut_attributes[:sut].parameter[ :filter_type]=original_filter
        sut_attributes[:sut].parameter[ :use_find_object]=original_find
      end
  end
  rescue Exception => e
    @capture_screen_error="Unable to capture state: " + e.message
    self.set_test_case_execution_log(@capture_screen_error.to_s)
  ensure
    if  $parameters[ :logging_level, 0 ].to_i > 0
      MobyUtil::Logger.instance.enabled=true
    else
      MobyUtil::Logger.instance.enabled=false
    end
    self.set_test_case_execution_log('<hr />')
  end
end