以下代码是在QC里运行QTP来执行脚本过程,当执行过程中发现用例失败后就会自动截图,然后把用例返回到最初始的状态,模拟了场景恢复的机制

 Class QCImageErrorCapture
Dim qtpApp
Sub Class_Initialize()
Set qtpApp = CreateObject("QuickTest.Application")
If qtpApp.CurrentDocumentType = "Test" Then
qtpApp.Test.Settings.Run.DisableSmartIdentification = False'False
qtpApp.Test.Settings.Run.OnError = "Stop" '"NextStep" "stop"
else
qtpApp.BusinessComponent.Settings.Run.OnError = "Stop"
End If
End Sub
Sub Class_Terminate()
'Check if the current test has failed. If failed then only capture screenshot
If Reporter.RunStatus = micFail Then 'and qtpApp.CurrentDocumentType = "test" 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.Test.Settings.Run.DisableSmartIdentification = True
' msgbox "display"
qtpApp.visible = False 'GIve time for QTP to get hidden
Wait 'Capture the screenshot to the report folder
Desktop.CaptureBitmap Reporter.ReportPath & "/Report/ErrorImage.png", True
qtpApp.visible = True
' Browser("title:=视博云业务全流程管理平台").Close ' SystemUtil.CloseProcessByName "iexplore.exe"
' isFail = True Reporter.ReportEvent micFail, "失败截图", "失败截图", Reporter.ReportPath & "/Report/ErrorImage.png" If qtpApp.CurrentDocumentType = "Test" Then
Browser("title:=视博云业务全流程管理平台").Page("title:=视博云业务全流程管理平台").Frame("html id:=FM_Logo").Image("file name:=icon_exit.png").Click
wait
Browser("title:=视博云业务全流程管理平台").Dialog("text:=来自网页的消息", "nativeclass:=#32770").WinButton("text:=确定").Click
end if '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"
' print "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
' print "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场景恢复之用例失败自动截图的更多相关文章

  1. Selenium2+python自动化67-用例失败自动截图【转载】

    前言: 装饰器其实就是一个以函数作为参数并返回一个替换函数的可执行函数 上一篇讲到用装饰器解决异常后自动截图,不过并没有与unittest结合,这篇把截图的装饰器改良了下,可以实现用例执行失败自动截图 ...

  2. TestNG监听器实现用例运行失败自动截图、重运行功能

    注: 以下内容引自 http://blog.csdn.net/sunnyyou2011/article/details/45894089 (此非原出处,亦为转载,但博主未注明原出处) 使用Testng ...

  3. testng 失败自动截图

    testng执行case failed ,testng Listener会捕获执行失败,如果要实现失败自动截图,需要重写Listener的onTestFailure方法 那么首先新建一个Listene ...

  4. 如何解决testng执行用例失败自动重跑问题

    注: 以下内容引自 http://blog.csdn.net/MenofGod/article/details/72846649 看过几个相关问题的帖子,内容类似,不过这篇解决问题的步骤和代码比较清晰 ...

  5. Webdriver+Testng实现测试用例失败自动截图功能

    testng执行测试用例的时候,如果用例执行失败会自动截图,方便后续排查问题 1.首先定义一个截图类: package com.rrx.utils; import java.io.File;impor ...

  6. TestNG实现用例运行失败自动截图(转载)

    转载自:https://blog.csdn.net/galen2016/article/details/70193684 重写Listener的onTestFailure方法 package com. ...

  7. selenium2入门 断言失败自动截图 (四)

    一般web应用程序出错过后,会抛出异常.这个时候能截个图下来,当然是极好的. selenium自带了截图功能. //获取截图file File scrFile= ((TakesScreenshot)d ...

  8. 【框架】Testng用例失败自动重跑(五)

    arrow是testng的一个扩展插件,参考arrow的源代码 1.新建一个工程,结果如图: 2.RetryListener.java的代码 package com.netease.qa.testng ...

  9. selenium2 断言失败自动截图 (四)

    一般web应用程序出错过后,会抛出异常.这个时候能截个图下来,当然是极好的. selenium自带了截图功能. //获取截图file File scrFile= ((TakesScreenshot)d ...

随机推荐

  1. 通过FTP将一个数据文件从A服务器下载到B服务器的整个过程

    现在的环境如下: 服务器A :192.168.1.104 服务器B:192.168.1.138 需要将A服务器上的某个数据文件下载到B服务器上,传输方式为:FTP 那么,要怎么去实现呢? 首先,需要添 ...

  2. Linux 挂载存储方法

    申请的虚拟机因总宕机,处理完之后多分配了我100G空间,还是狠讲究的嘛,挂载方法如下: 初始磁盘挂载情况:[root@wmstest ~]# df -hFilesystem Size Used Ava ...

  3. 转载 -- C# 中的委托和事件

    原文地址:http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx C# 中的委托和事件 引言 委 ...

  4. 视频学习_css基础学习

    块状元素 block element 容器元素  设置高宽 width height  可以容纳 文本 内脸 和其他块状 霸道  独占一行 特例:form  只容纳 块状元素 常见元素 http:// ...

  5. Maven--(一个坑)在settings.xml文件中添加mirrors导致无法新建Maven项目

    这是用新电脑第一次创建Maven项目--当然是一个测试项目.已经差不多忘了该怎样做,所以参考我的博客:http://www.cnblogs.com/wql025/p/4996486.html,这应该是 ...

  6. Matlab找二维数组最大值

    1.m先max(x)求出每列最大值,返回行向量,再max对行向量求出最大值,就是max(max(x)). 注意:max(x),不管x是行列向量,只要是向量,那么就返回一个值. 2.先x(:)转为按列的 ...

  7. 剑指offer--面试题14--收获

    按照作者的说法,作为应届毕业生的我来说,如果能写出初级程序员的参考代码来解决面试题14就可认为过关了... 参考代码如下: void ReorderOddEven_1(int *pData, unsi ...

  8. 剑指offer--面试题12

    题目:打印从1~最大的n位数 分析:知道陷阱在哪,即n很大时若用通常的int,long会溢出:想到用字符串解决,这涉及到字符转数字及反过来. 刚开始纠结于字符串怎么加1,想了片刻,觉得应该取出最后一位 ...

  9. 使用JAVA反射初始化数组(转)

    在做JSON解析时,遇到了在不知道数组类型的前期下,需要转化为具体类型数组的问题.可以使用JAVA的反射来做. JSONArray jsonArray = (JSONArray) entry.getV ...

  10. C#操作config文件

    以下是app.config或web.config的定义,定义了一个参数,键为Isinit,值为false <?xml version="1.0"?> <confi ...