QTP场景恢复之用例失败自动截图

时间:2022-09-22 10:46:13

以下代码是在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. windows 下双网卡在不同网络切换设置

           首先你的机器需要有两块网卡,分别接到两台交换机上, ine rnet地址:192.168.1.8,子网掩码:255.255.255.0,网关:192.168.1.1 内部网地址:172. ...

  2. java synchronized使用

    java synchronized 基本上,所有并发的模式在解决线程冲突问题的时候,都是采用序列化共享资源的方案.这意味着在给定时刻只允许一个任务访问该资源.这个一般通过在代码上加一条锁语句实现,因为 ...

  3. php的引用

    <?php $var1 = 1; $var2 = 2; function foo(){ global $var1,$var2; $var2 = &$var1; } function te ...

  4. 【PostgreSQL】PostgreSQL语法

    在阅读的过程中有不论什么问题.欢迎一起交流 邮箱:1494713801@qq.com    QQ:1494713801 一.PostgreSQL时间类型转换 --时间类型转成字符类型 select t ...

  5. iOS开发实战-时光记账Demo 网络版

    之前写了一个本地数据库版本 戳这里 现在这个就是增加了后台 登录注册页面以及web的上传记录展示页面 含有少量php有兴趣可以看下 另外demo中包括数据库操作.json.网络请求等都没有用到第三方库 ...

  6. UNIX网络编程——UDP编程模型

    使用UDP编写的一些常见得应用程序有:DNS(域名系统),NFS(网络文件系统)和SNMP(简单网络管理协议). 客户不与服务器建立连接,而是只管使用sendto函数给服务器发送数据报,其中必须指定目 ...

  7. hdu 2955 Robberies &lpar;01背包)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 思路:一开始看急了,以为概率是直接相加的,wa了无数发,这道题目给的是被抓的概率,我们应该先求出总的 ...

  8. Ubuntu常用软件安装(小集合)

    跨平台系列汇总:http://www.cnblogs.com/dunitian/p/4822808.html#linux Linux包系列的知识:https://www.cnblogs.com/dun ...

  9. vue教程2-06 过滤器

    vue教程2-06 过滤器 过滤器: vue提供过滤器: capitalize uppercase currency.... <div id="box"> {{msg| ...

  10. 企业IT架构转型之道 读书笔记-1&period;阿里巴巴集团中台战略引发的思考

    前言 1.为什么选择看这本书 2.Supercell公司的开发模式 3.“烟囱式”系统建设模式弊端,及产生这种现象的原因 4.IT人员在企业信息中心的组织职能 一.为什么选择看这本书 多日没有更新博客 ...