QTP场景恢复之用例失败自动截图
以下代码是在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场景恢复之用例失败自动截图的更多相关文章
- Selenium2+python自动化67-用例失败自动截图【转载】
前言: 装饰器其实就是一个以函数作为参数并返回一个替换函数的可执行函数 上一篇讲到用装饰器解决异常后自动截图,不过并没有与unittest结合,这篇把截图的装饰器改良了下,可以实现用例执行失败自动截图 ...
- TestNG监听器实现用例运行失败自动截图、重运行功能
注: 以下内容引自 http://blog.csdn.net/sunnyyou2011/article/details/45894089 (此非原出处,亦为转载,但博主未注明原出处) 使用Testng ...
- testng 失败自动截图
testng执行case failed ,testng Listener会捕获执行失败,如果要实现失败自动截图,需要重写Listener的onTestFailure方法 那么首先新建一个Listene ...
- 如何解决testng执行用例失败自动重跑问题
注: 以下内容引自 http://blog.csdn.net/MenofGod/article/details/72846649 看过几个相关问题的帖子,内容类似,不过这篇解决问题的步骤和代码比较清晰 ...
- Webdriver+Testng实现测试用例失败自动截图功能
testng执行测试用例的时候,如果用例执行失败会自动截图,方便后续排查问题 1.首先定义一个截图类: package com.rrx.utils; import java.io.File;impor ...
- TestNG实现用例运行失败自动截图(转载)
转载自:https://blog.csdn.net/galen2016/article/details/70193684 重写Listener的onTestFailure方法 package com. ...
- selenium2入门 断言失败自动截图 (四)
一般web应用程序出错过后,会抛出异常.这个时候能截个图下来,当然是极好的. selenium自带了截图功能. //获取截图file File scrFile= ((TakesScreenshot)d ...
- 【框架】Testng用例失败自动重跑(五)
arrow是testng的一个扩展插件,参考arrow的源代码 1.新建一个工程,结果如图: 2.RetryListener.java的代码 package com.netease.qa.testng ...
- selenium2 断言失败自动截图 (四)
一般web应用程序出错过后,会抛出异常.这个时候能截个图下来,当然是极好的. selenium自带了截图功能. //获取截图file File scrFile= ((TakesScreenshot)d ...
随机推荐
- ios7.0结合storyborad实现页面跳转的总结
折腾了一整天,本文总结一下ios7.0页面跳转有关的内容 storyboard的潜规则 我接触ios很晚,环境已经是xcode5+ios7,所以对以前的IOS开发模式并不了解.在网上查阅了很多资料,发 ...
- NOIP2015 心得
NOIP2015的复赛已经过去一个多星期了,成绩也已经出来了,作为一个大(ruo)山(sheng)东的蒟蒻,在学了一年之后拿到了255的成绩.这个成绩并不是很好,但也算在我的预料之内. 第一天第一题水 ...
- Pomodairo,番茄工作法-应用篇
传统: 选择一个待完成的任务 将番茄时间设为适合自己的固定时间 专注工作,中途不允许做任何与该任务无关的事,直到番茄时钟响 ...
- Careercup - Google面试题 - 5205167846719488
2014-05-03 23:35 题目链接 原题: For a given node in binary search tree find a next largest number in searc ...
- Ui设计哪里有好的素材
刚看到花瓣网,的确不错,以后得多逛逛了.(不喷广告,只留作笔记)
- java集合类(三)About Iterator & Vector(Stack)
接上篇:java集合类学习(二) Talk about “Iterator”: 任何容器类,在插入元素后,还需要取回元素,因为这是容器的最基本工作.对于一般的容器,插入有add()相关方法(List, ...
- 自己的一些 Demo,源码链接
1.指纹解锁(GitHub). 2.JS 与 OC 交互(GitHub). 3.模仿 HTML 下拉菜单(GitHub). 4.OC开发常用类目(GitHub).
- lucas求组合数C(n,k)%p
Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...
- C++字符串分割
//字符串分割函数 std::vector<std::string> split(std::string str,std::string pattern) { std::string::s ...
- getHibernateTemplate()为NUll
getHibernateTemplate()为NUll,困扰好几天了,网上也找了好些方法一直解决不掉15 小弟刚刚开始学SSH,是用的Struts2+Hibernate+Spring,运行的时候发现g ...