恢复场景或在函数本身中处理大部分场景

发布于 2024-09-14 08:21:20 字数 124 浏览 6 评论 0原文

在执行过程中我可以预期的场景很少,我想了解处理此类运行时错误的最佳实践。

还有一个问题,是否值得在函数加载期间加载所有恢复场景,或者在函数本身中处理异常。

请建议最佳实践以及为什么您建议我们需要这样做。

There are few scenarios which i can expect during my execution, I would like to understand the best practices of handles such run time errors.

One more question, is it worth to load all the recovery scenarios during the load of the functions or handle the exception with in the functions itself.

Kindly suggest the best practices and why you suggest we need to go for that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彼岸花似海 2024-09-21 08:21:24

由于QTP中建立的命名,初学者经常混淆异常和GUI事件。
确实,弹出窗口并不是一个“例外”,即使它“崩溃”了脚本执行。

为了捕获失败的操作并从中恢复,我建议使用“On Error Resume Next...On Error GoTo 0”语句。

为了捕获可能发生也可能不发生的 GUI 事件,您可以使用 QTP 恢复场景,但是,正如 Tom E 提到的,每个激活的恢复处理程序都会使用额外的资源并影响 QTP 性能。
最好的方法是只使用您需要的那些,并保持其余的停用。

举几个例子。

1.捕获异常

这样,如果您有RegEx语法错误,执行将不会停止。

Set objRegEx = New RegExp   
objRegEx.Pattern = strRegEx
On Error Resume Next
boolRC = objRegEx.Test(strSrc) 
intRC = Err.Number
On Error GoTo 0
If intRC <> 0 Then boolRC = False
Set objRegEx = Nothing

2.动态操作恢复处理程序

intPos = Recovery.GetScenarioPosition("API\Exceptions\AppExceptions.qrs", "Recovery_on_Error1")  
''# You can store intPos (position in QTP's qrs file) for all handlers during initialization

Recovery.SetScenarioStatus intPos, boolState ''# Parameterize boolState as True or False  
''# Enable or disable handlers this way. Disabled handler does not consume QTP resources.

谢谢,
阿尔伯特·加里耶夫
http://automation-beyond.com/

Due to naming established in QTP, beginners often confuse exceptions and GUI events.
Truly, pop-up window is not an "exception" even if it "crashes" script execution.

For catching and recovery from failed operations, I recommend using "On Error Resume Next...On Error GoTo 0" statements.

For catching GUI events, that may or may not happen, you can use QTP Recovery Scenarios, BUT, as Tom E mentioned, each activated recovery handler uses extra resources and affects QTP performance.
Best way to use only those of them you would need, and keep the rest deactivated.

A few examples.

1.Catching exceptions

This way, if you have RegEx syntax errors, execution won't stop.

Set objRegEx = New RegExp   
objRegEx.Pattern = strRegEx
On Error Resume Next
boolRC = objRegEx.Test(strSrc) 
intRC = Err.Number
On Error GoTo 0
If intRC <> 0 Then boolRC = False
Set objRegEx = Nothing

2.Dynamically operating Recovery handlers

intPos = Recovery.GetScenarioPosition("API\Exceptions\AppExceptions.qrs", "Recovery_on_Error1")  
''# You can store intPos (position in QTP's qrs file) for all handlers during initialization

Recovery.SetScenarioStatus intPos, boolState ''# Parameterize boolState as True or False  
''# Enable or disable handlers this way. Disabled handler does not consume QTP resources.

Thank you,
Albert Gareev
http://automation-beyond.com/

痴梦一场 2024-09-21 08:21:23

根据我使用 QTP 的经验,最好直接在函数中处理已知的异常场景,并将异常处理机制留给未知或意外的异常。恢复场景会使用额外的计算机资源,并且可能会减慢测试速度,因此仅以有限的方式使用它们来捕获真正异常的场景。

In my experience with QTP, it's best to handle known exception scenarios directly in your functions, and leave the exception handling mechanism for unknown or unexpected exceptions. Recovery scenarios use additional machine resources and can slow down your tests, so only use them in a limited fashion for catching truly exceptional scenarios.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文