将QTP运行时的错误截图上传到QC测试集中

上一篇 / 下一篇  2011-03-28 14:49:57 / 个人分类:QTP

 如果在测试运行时,将每一步的截图都上传至QC,那么将大量耗费QC的系统资源。通常,我们只想查看那些发生错误时的截图。当调试和运行失败后,需要查找原因时,这些截图可以迅速帮助定位问题。

      通过下述步骤,可以很简单的实现上述需求。

在公共函数库中创建一个类,并此类的一个实例
在类的析构函数中判断是否发生错误并截图
将截图作为附件上传到QC中当前测试集的实例中。
以下是这个类的完整代码:

' Class: QCImageErrorCapture
' WebSite:  http://KnowledgeInbox.com
' Author: Tarun Lalwani
' Description: This class captures the screen in case the current component fails or the current
'    test fails. This is for QC only
' Parameters: N/A
 
Class QCImageErrorCapture
 Sub Class_Terminate()
  'Check if the current test has failed. If failed then only capture screenshot
  If Reporter.RunStatus = micFail Then
   CaptureAndAttachDesktop
  End If
 End Sub
 
 Private Sub CaptureAndAttachDesktop()
  'QC is not connected
  If QCUtil.IsConnected = False then Exit Sub
 
  'The test is not running from Test Lab
  If QcUtil.CurrentRun is Nothing Then Exit Sub
 
  On error resume next
  'Hide QTP to make sure we don't get QTP in snapshot
  Set qtpApp = CreateObject("QuickTest.Application")
 
  qtpApp.visible = False
  'GIve time for QTP to get hidden
  Wait 2
 
  'Capture the screenshot to the report folder
  Desktop.CaptureBitmap Reporter.ReportPath & "\Report\ErrorImage.png", True
  qtpApp.visible = True
 
  'Add the capture to QC
  Set Attachments = QCutil.CurrentRun.Attachments
  Set Attachment = oAttachments.AddItem(null)
  oAttachment.FileName = Reporter.ReportPath & "\Report\ErrorImage.png"
  oAttachment.Type = 1 'File
 
  'Check if the current test is a QTP Test or Business Component
  Select Case LCase(qtpApp.CurrentDocumentType)
   Case "test"
     oAttachment.Description = "Name: " & qtpApp.Test.Name & vbNewLine & "Error: " & qtpApp.Test.LastRunResults.LastError
   Case "business component"
     oAttachment.Description = "Name: " & qtpApp.BusinessComponent.Name & vbNewLine & "Error: " & qtpApp.BusinessComponent.LastRunResults.LastError
 
     'We can also add the Business COmponent to a User Defined Field
     'QCUtil.CurrentTestSetTest.Field("TC_USER_01") = qtpApp.BusinessComponent.Name
     'QCUtil.CurrentTestSetTest.Post
  End Select  
 
  'Add the attachment
  oAttachment.Post
 End Sub
End Class
 
'Create the object in one of the attached libraries. When the Test or Business component ends
'the screenshot will be captured
Set ErrorCapture = new QCImageErrorCapture将上述代码直接复制到函数库中并关联当前QTP脚本,那么在运行过程中发生的错误截图就会自动上传至QC。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/blizzardlyk/archive/2011/01/21/6157019.aspx


TAG: QC QTP 截图

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-14  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 8467
  • 日志数: 27
  • 建立时间: 2011-03-28
  • 更新时间: 2011-05-12

RSS订阅

Open Toolbar