QTP场景恢复之用例失败自动截图
2014-01-13 10:59
316 查看
以下代码是在QC里运行QTP来执行脚本过程,当执行过程中发现用例失败后就会自动截图,然后把用例返回到最初始的状态,模拟了场景恢复的机制
View Code
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 2 '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 1 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
View Code
相关文章推荐
- TestNG监听器实现用例运行失败自动截图、重运行功能
- Webdriver+Testng实现测试用例失败自动截图功能
- Testng实现用例失败自动截图
- 执行testng appium用例失败,自动截图
- TestNG监听器实现用例运行失败自动截图、重运行功能
- TestNG监听器实现用例运行失败自动截图、重运行功能
- TestNG实现用例运行失败自动截图和重跑
- Webdriver+Testng实现测试用例失败自动截图功能
- QTP关闭所有的应用程序窗口,场景恢复
- 跳过一些坑,一张图弄明白TestNG多用例执行添加监听失败截图
- QTP场景恢复机制步骤
- robotium 测试用例操作失败自动重跑测试用例方法
- 如何解决testng执行用例失败自动重跑问题
- 扩展Robot Framework,实现失败用例自动再执行(失败重跑)
- 如何解决testng执行用例报错自动截图问题
- QTP的错误恢复场景机制
- QTP恢复场景-处理找不到列表项或菜单的情况
- 【QTP-场景恢复】Post-Recovery Test Run Options Screen
- 解决RobotFramework用例执行失败自动重跑问题
- 修改testNG源码,实现失败用例自动再执行