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

      如果在测试运行时,将每一步的截图都上传至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 oAttachments = QCutil.CurrentRun.Attachments
		Set oAttachment = 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 oErrorCapture = new QCImageErrorCapture
将上述代码直接复制到函数库中并关联当前QTP脚本,那么在运行过程中发生的错误截图就会自动上传至QC。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值