简体   繁体   English

在QTP UFT中打印VBScript变量

[英]Printing VBScript variables in QTP UFT

How can I check values of my variables at run time when using QTP UFT? 使用QTP UFT时如何在运行时检查变量的值? I simply want to create a variable, do logic and fill it with data, set a breakpoint in the line following the variable and then check or output its value somewhere. 我只想创建一个变量,执行逻辑并用数据填充它,在变量后面的行中设置一个断点,然后检查或将其值输出到某个地方。

I have tried: 我努力了:

print variableName
WScript.Echo variableName

The first produces error: Print function type mismatch 第一个产生错误:打印功能类型不匹配
The second produces error: Object required: "WScript" 第二个产生错误:所需对象:“ WScript”

I'm not sure where the problem lies as I've just started to get into both UFT and VBScript (mostly did C# and javascript and everything is quite different here). 我不确定问题出在哪里,因为我刚开始接触UFT和VBScript(大多数情况下是C#和javascript,这里的一切都大不相同)。 Could someone tell me the correct solution and perhaps also explain these errors to me? 有人可以告诉我正确的解决方案,也可以向我解释这些错误吗?

If you wanted to see all variables use the debug viewer in QTP. 如果要查看所有变量,请使用QTP中的调试查看器。

View -> Debug Viewer 查看->调试查看器

There you can list all the variables you want to watch. 在这里,您可以列出要观看的所有变量。 You should be able to see them in break points. 您应该能够在断点处看到它们。

Note : Ensure you have Windows script debugger installed to use the debug viewer. 注意:确保已安装Windows脚本调试器以使用调试查看器。

You can also add the variable to watch .. Insert a breakpoint>> start the script then right click on the variable under test and add it to watch(Add to Watch) . 您还可以将变量添加到watch ..插入断点>>,启动脚本,然后右键单击被测变量,然后将其添加到watch(添加到Watch)。 After Adding you will see a watch window and the value of the variable will be displayed. 添加后,您将看到一个监视窗口,并显示变量的值。

I obsess over my variables... so much so that I sprinkly my code with print statements... Actually, I abstract print into my own UDF (so that I can optionally add logging to a file if needed)... 我非常迷恋我的变量...以至于我在代码中撒满了print语句...实际上,我将print抽象到了自己的UDF中(以便可以根据需要选择将日志记录添加到文件中)...

Here's my function: (it's actually a sub because it doesn't return anything) 这是我的功能:(它实际上是一个子,因为它不返回任何东西)

Sub say(textToSay)
    If talkative Then 'note that if I set global var "talkative" to false, then the whole log is disabled
            print textToSay
    End If
End Sub

Then, ALL my code typically looks like this... 然后,我所有的代码通常看起来像这样……

say "click submit button"
Broswer("WebSite").Page("Search").WebButton("Submit").click

say "check for result"
if not Browser("WebSite").Page("Results").Exist then
  say "results page didn't appear after exist timeout"
  failtest
else
  say "successfully found results page"
end if

Honestly, I'm shocked that your "print variableName" statement gave an error, print is actually available in the VBScript api, so it should have worked. 老实说,我很震惊您的“ print variableName”语句给出了一个错误,在VBScript api中实际上可以使用print,所以它应该可以工作。

All of my output goes to the Output pane in UFT. 我所有的输出都转到UFT的“输出”窗格中。 I would give my right-arm to find a way to programmatically clear that output pane between runs, but noone seems to know how to do it. 我想让我的右臂找到一种方法,以编程方式清除两次运行之间的输出窗格,但是似乎没人知道如何做到这一点。

The benefit of all this logging is that I can watch my code run and see EVERY branch taken by the code, and I can add statements to print my variables. 所有这些日志记录的好处是,我可以观看我的代码运行并查看该代码占用的每个分支,还可以添加语句来打印我的变量。

Here's an example that shows how I would answer your question: 这是一个示例,显示了我将如何回答您的问题:

result = browser("WebSite").Page("Results").WebElement("Result").GetROProperty("innertext")

say "result:" & result
if result = "Approved" then
  Reporter.ReportEvent micPass, "Check for approved", "Approved!"
else
  Reporter.ReportEvent micFail, "Check for approved", "NOT Approved!"
End If

Notice the say statement in there - I'll be able to see that immediately during code execution without waiting until the results are shown at the end. 请注意其中的say语句-我将能够在代码执行期间立即看到该语句,而无需等到结果显示在最后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM