QTP第三方调试器PowerDebug试用手记

今天试用了一下PowerDebug的Beta版本,下面介绍一下PowerDebug的主要功能。

 

1、写Log功能

PowerDebug的输出窗口写Log

例如:

        'Clear the error

        PowerDebug.ClearLog()

        'Don't report Time to the output window

        PowerDebug.ReportTimeInLog = False

        PowerDebug.Log("This is a text Log without Time")

 

        'Report Time to the output window

        PowerDebug.ReportTimeInLog = True

        PowerDebug.Log("This is a text Log with Time")

 

        'Save the log to a file

        PowerDebug.SaveLog("C:/Log.txt")

 

        Dim varLog

        'Returns the current text from the Log

        varLog = PowerDebug.GetLog()

 

2、使用GoTo语句

PowerDebug allow you to use Goto Statements. The Goto method takes input the tag name. The tag need to be present with the Prefix and the Postfix. Consider the below code

(需要用前缀和后缀指定GoTo跳转到的标签位置)

例如:

PowerDebug.GotoPrefix = "':"

PowerDebug.GotoPostfix = ":"

 

PowerDebug.Goto("JumpLocation")

MsgBox("This code should not be executed")

':JumpLocation:

MsgBox("Here after a jump")

 

'Goto statements can also be used to create a continue statement in a loop

For i = 0 To 10

    If i > 5 And i < 8 Then

        PowerDebug.Goto("ForContinue")

    End If

    PowerDebug.Log("Printing Loop counter - " & i)

    ':ForContinue:

Next

 

 

3、查看当前代码运行环境

PowerDebug allows you to access current scope information which can be very useful for debugging information. The code sample below shows different information that can be accessed

 

例如:

Function CallMe()

    'Load the current Scope information

    PowerDebug.LoadInformation()

 

    PowerDebug.Log("Currently inside the function - " & PowerDebug.FunctionName)

    PowerDebug.Log("The function was called by - " & PowerDebug.Caller)

    PowerDebug.Log("The current code is: " & vbCrLf & vbCrLf & PowerDebug.CurrentCode)

    PowerDebug.Log("The current stack trace is: " & vbCrLf & vbCrLf & PowerDebug.StackTrace)

End Function

 

Function IamCallingCaller()

    Call CallMe()

End Function

 

Call IamCallingCaller

 

上面的脚本将输出以下信息:

[19-ËÄÔÂ-10|09:09:11] Currently inside the function - CallMe

[19-ËÄÔÂ-10|09:09:11] The function was called by - IamCallingCaller

[19-ËÄÔÂ-10|09:09:11] The current code is:

 

Function CallMe()

    'Load the current Scope information

    PowerDebug.LoadInformation()

 

 

    PowerDebug.Log("Currently inside the function - " & PowerDebug.FunctionName)

    PowerDebug.Log("The function was called by - " & PowerDebug.Caller)

    PowerDebug.Log("The current code is: " & vbCrLf & vbCrLf & PowerDebug.CurrentCode)

    PowerDebug.Log("The current stack trace is: " & vbCrLf & vbCrLf & PowerDebug.StackTrace)

End Function

 

 

Function IamCallingCaller()

    Call CallMe()

End Function

 

 

Call IamCallingCaller

 

[19-ËÄÔÂ-10|09:09:11] The current stack trace is:

 

CallMe!Line (6):PowerDebug.Log("Currently inside the function - " & PowerDebug.FunctionName)

IamCallingCaller!Line (14):Call CallMe()

VBScript global code!Line (18):Call IamCallingCaller

VBScript global code!Line (1):RunAction "Action1", oneIteration

 

 

4、用Assert语句实现断点

PowerDebug doesn't support QTP's breakpoint. So to pause execution or simulate a breakpoint one needs to use Assert method. Assert method when passed a False value pauses the execution

 

例如:

'Break execution on next statement

PowerDebug.Assert False

 

Print "The execution should be paused here"

 

 

 

5PowerDebugCommand窗口、Watch窗口、Variable窗口、Code窗口、Output窗口、CallStack窗口大大增强了QTP的调试能力和易用性。

 

 

6WaitForAllObjectExist方法

PowerDebug提供的WaitForAllObjectExist方法可以用于判断多个对象是否存在,而仅仅用一个语句:

bool WaitForAllObjectExist(int timeoutInSeconds, object obj1, [object obj2]....)

 

Returns true if all the passed objects exist within specified time, else returns false

 

例如:

Set obj1 = Window("regexpwndtitle:=File1.*")

Set obj2 = Window("regexpwndtitle:=File2.*")

 

'Wait for 10 seconds max for all objects to exist

Msgbox PowerDebug.WaitForAllObjectExist(10, obj1, obj2)

 

还有一个类似的方法是WaitForAnyObjectExist,用于判断指定的若干个对象中是否有任意一个是存在的。关于该方法的使用可以参考PowerDebug的帮助文档,也可以参考作者主页上的文章:

http://knowledgeinbox.com/products/powerdebug/enhancing-scripts-perfomance-using-waitforanyobjectexist/

 

 

 

 

 

 

试用PowerDebugBeta版本发现还不太稳定,有时候会停止响应。

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值