博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
QTP场景恢复之用例失败自动截图
阅读量:5303 次
发布时间:2019-06-14

本文共 3647 字,大约阅读时间需要 12 分钟。

 

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

1 Class QCImageErrorCapture 2    Dim qtpApp 3    Sub Class_Initialize() 4           Set qtpApp = CreateObject("QuickTest.Application") 5         If qtpApp.CurrentDocumentType = "Test" Then 6             qtpApp.Test.Settings.Run.DisableSmartIdentification = False'False 7             qtpApp.Test.Settings.Run.OnError = "Stop" '"NextStep"      "stop" 8         else 9             qtpApp.BusinessComponent.Settings.Run.OnError = "Stop"10         End If11    End Sub12     Sub Class_Terminate()13         'Check if the current test has failed. If failed then only capture screenshot14         If Reporter.RunStatus = micFail Then 'and qtpApp.CurrentDocumentType = "test" Then15             CaptureAndAttachDesktop16         End If17     End Sub18  19     Private Sub CaptureAndAttachDesktop()20         'QC is not connected21         If QCUtil.IsConnected = False then Exit Sub22  23         'The test is not running from Test Lab24         If QcUtil.CurrentRun is Nothing Then Exit Sub25  26         On error resume next27         'Hide QTP to make sure we don't get QTP in snapshot28 '        Set qtpApp = CreateObject("QuickTest.Application")29 '        qtpApp.Test.Settings.Run.DisableSmartIdentification = True30 '        msgbox "display"31         qtpApp.visible = False32 33         'GIve time for QTP to get hidden34         Wait 235  36         'Capture the screenshot to the report folder37         Desktop.CaptureBitmap Reporter.ReportPath & "/Report/ErrorImage.png", True38         qtpApp.visible = True39 '        Browser("title:=视博云业务全流程管理平台").Close40 41 '        SystemUtil.CloseProcessByName "iexplore.exe"42 '        isFail = True43         44         Reporter.ReportEvent micFail, "失败截图", "失败截图", Reporter.ReportPath & "/Report/ErrorImage.png"45 46         47         If qtpApp.CurrentDocumentType = "Test" Then48             Browser("title:=视博云业务全流程管理平台").Page("title:=视博云业务全流程管理平台").Frame("html id:=FM_Logo").Image("file name:=icon_exit.png").Click49             wait 150             Browser("title:=视博云业务全流程管理平台").Dialog("text:=来自网页的消息", "nativeclass:=#32770").WinButton("text:=确定").Click51         end if52 53         'Add the capture to QC54 '        Set oAttachments = QCutil.CurrentRun.Attachments55 '        Set oAttachment = oAttachments.AddItem(null)56 '        oAttachment.FileName = Reporter.ReportPath & "/Report/ErrorImage.png" 57 '        oAttachment.Type = 1 'File58  59         'Check if the current test is a QTP Test or Business Component60 '        Select Case LCase(qtpApp.CurrentDocumentType)61 '            Case "test"62 '                    print "test"63 '                    oAttachment.Description = "Name: " & qtpApp.Test.Name & vbNewLine & "Error: " & qtpApp.Test.LastRunResults.LastError64 '            Case "business component"65 '                    oAttachment.Description = "Name: " & qtpApp.BusinessComponent.Name & vbNewLine & "Error: " & qtpApp.BusinessComponent.LastRunResults.LastError66 ' 67 '                    'We can also add the Business COmponent to a User Defined Field 68 '                    'QCUtil.CurrentTestSetTest.Field("TC_USER_01") = qtpApp.BusinessComponent.Name69 '                    'QCUtil.CurrentTestSetTest.Post70 '        End Select        71 ' 72 '        'Add the attachment73 '        oAttachment.Post74 '        print "post"75     End Sub 76 End Class77  78 'Create the object in one of the attached libraries. When the Test or Business component ends 79 'the screenshot will be captured80 Set oErrorCapture = new QCImageErrorCapture
View Code

 

转载于:https://www.cnblogs.com/testermark/p/3517063.html

你可能感兴趣的文章
POJ 1015 Jury Compromise(双塔dp)
查看>>
论三星输入法的好坏
查看>>
Linux 终端连接工具 XShell v6.0.01 企业便携版
查看>>
JS写一个简单日历
查看>>
LCA的两种求法
查看>>
Python 发 邮件
查看>>
mysql忘记密码的解决办法
查看>>
全面分析Java的垃圾回收机制2
查看>>
[Code Festival 2017 qual A] C: Palindromic Matrix
查看>>
修改博客园css样式
查看>>
Python3 高阶函数
查看>>
初始面向对象
查看>>
docker一键安装
查看>>
leetcode Letter Combinations of a Phone Number
查看>>
Exercise 34: Accessing Elements Of Lists
查看>>
angular中的代码执行顺序和$scope.$digest();
查看>>
ALS算法 (面试准备)
查看>>
思达BI软件Style Intelligence实例教程—房地产分析
查看>>
Unity 3D 如何修改新建脚本中的 C# 默认创建的 Script 脚本格式
查看>>
Unity 5.4 测试版本新特性---因吹丝停
查看>>