简体   繁体   English

UFT / QTP中的错误处理

[英]Error Handling in UFT/QTP

I've a framework where the methods are called inside an action from Function Libraries. 我有一个框架,在函数库的操作中调用方法。 I'm trying to do error handling to avoid errors thrown by code written inside the function Libraries. 我正在尝试进行错误处理,以避免函数库中编写的代码引发错误。

Below is my action code: 以下是我的操作代码:

on error resume next
call TestMe()
if err.number Then: msgbox err.description
on error goto 0

And here is the function inside function library: 这是函数库中的函数:

Function TestMe()
   x = 1/0
End Function

When I execute my test, on error resume next doesn't seems to be working as I get an error pop-up for division by zero inside the function TestMe(). 当我执行测试时,由于我在函数TestMe()中得到一个除以零的错误弹出窗口,因此似乎无法on error resume next执行on error resume next

How can I get these error handled without moving the code? 如何在不移动代码的情况下处理这些错误?

Surprisingly with all the time using QTP/UFT never came up against such case. 令人惊讶的是,始终使用QTP / UFT从未遇到过这种情况。 Was quite intriguing as well. 也很有趣。 I Found out (or so it seems at first glance) that the scope of on error resume next is limited to its level (Library/Action) and couldn't be carried over to either. 我发现(或乍一看) on error resume next的范围仅限于其级别(库/操作),并且不能转移到任何一个。

You might wanna try something like: 您可能想尝试类似的方法:

Action Code: 动作代码:

Call Test3()

Function Library: 功能库:

Function Test1()
      x = 1/0
End Function

Function Test2()
   Call Test1()
   MsgBox "Test2"
End Function

Function Test3()
   On Error Resume next
   Call Test2()
   MsgBox err.Description
End Function

The execution using this statement continues until it finds a handler. 继续执行此语句,直到找到处理程序。 So you may set up a condition where ever you deem fit. 因此,您可以设置一个您认为合适的条件。

Another alternative is to use a flag (could be an environment variable) like 另一种选择是使用标志(可以是环境变量),例如

Environment("Flag") = True

Whose condition can be checked directly in action code 可以在操作代码中直接检查谁的状况

Hope this helps. 希望这可以帮助。 I'll still try to dig up more about this 我仍将尝试对此进行更多挖掘

Check the below article. 检查以下文章。 This is explaining the same issue in detail 这正在详细解释相同的问题

https://sumeetkushwah.com/2014/08/12/implementing-try-catch-functionality-in-qtpuft/ https://sumeetkushwah.com/2014/08/12/implementing-try-catch-functionality-in-qtpuft/

on error resume next

call TestMe()

on error goto 0

if err.number Then: msgbox err.description

Function TestMe()

   x = 1/0

End Function

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

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