以下代码是在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. ALTER TABLE causes auto_increment resulting key 'PRIMARY'

    修改表为主键的自动增长值时,报出以下错误:mysql> ALTER TABLE YOON CHANGE COLUMN id id INT(11) NOT NULL AUTO_INCREMENT ...

  2. 试图使用未在此报表服务器中注册或此版 Reporting Services 不支持的数据扩展插件“Devart.Data.PostgreSql”

    数据源用的是Postgresql 我在Deploy Report的时候出现这条ErrorMessage Error 2 试图使用未在此报表服务器中注册或此版 Reporting Services 不支 ...

  3. Linux之mount命令详解

    linux下挂载(mount)光盘映像文档.移动硬盘.U盘.Windows和NFS网络共享linux是个优秀的开放源码的操作系统,能够运行在大到巨型小到掌上型各类电脑系统上,随着linux系统的日渐成 ...

  4. edge.js架起node.js和.net互操作桥梁

    今天要介绍的是edge.js这个github上刚兴起的开源项目,它可以让node.js和.net之间在in-process下互操作..net版本在4.5及以上,因为.net4.5带来的Task,asy ...

  5. [MySql] - 解决部署的服务器没有安装MySql Connector

    1. 在C盘安装mysql的位置找到三个DLL,复制到Bin文件夹下. 2. 在配置文件的web下添加引用,PubulishKeyToken 根据版本来. <system.data> &l ...

  6. vagrant在windows下的使用

    vagrant在windows下的使用 下载安装 VirtualBox :https://www.virtualbox.org/ 下载安装 Vagrant :http://www.vagrantup. ...

  7. VBS基础篇 - class

    Class 语句:声明一个类的名称,以及组成该类的变量.属性和方法的定义. Class name '参数name必选项,Class 的名称 statements '一个或多个语句,定义了 Class ...

  8. Android 自定义Toast,不使用系统Toast

    效果图: 创建Toast类 package com.example.messageboxtest; import android.app.Activity; import android.conten ...

  9. oracle 判断是否数字 正则表达式法

     SELECT '-100'    FROM dual   WHERE REGEXP_LIKE('-100','(^[+-]?\d{0,}\.?\d{0,}$)'); REGEXP_LIKE 用法: ...

  10. ExtJS4.2学习(21)动态菜单与表格数据展示操作总结篇2

    运行效果: 此文介绍了根据操作左侧菜单在右面板展示相应内容. 一.主页 先看一下跳转主页的方式:由在webapp根目录下的index.jsp跳转至demo的index.jsp 下面是demo的inde ...