Vbscript UFT-如何检查函数是否在没有错误的情况下执行

Vbscript UFT-如何检查函数是否在没有错误的情况下执行,vbscript,automation,qtp,Vbscript,Automation,Qtp,如果我想验证我调用的函数是否已完全执行,如何编写代码 例如 提前感谢,, P你的问题太抽象,无法给出准确的答案。然而,根据我的理解,我认为以下是可能的解决方案 方法1 Public Function Func_Import() Dim blnReturnValue : blnReturnValue = True If blnReturnValue = True Then blnReturnValue = Do Some Actions If blnReturnValue = T

如果我想验证我调用的函数是否已完全执行,如何编写代码

例如

提前感谢,,
P

你的问题太抽象,无法给出准确的答案。然而,根据我的理解,我认为以下是可能的解决方案

方法1

Public Function Func_Import()
   Dim blnReturnValue : blnReturnValue = True
   If blnReturnValue = True Then blnReturnValue = Do Some Actions
   If blnReturnValue = True Then blnReturnValue = Do Some More Actions
   Func_Import = blnReturnValue
End Function
如果返回值为true,则执行所有其他步骤,有些步骤已中断

方法2

UFT Inbuild方法-GetLastError()语句


这是UFT中的一个经典问题,您如何检测故障,为了正确回答您的问题,我们需要了解以下两种情况

1) 如果您知道在失败时要做什么,或者您的目标是重新启动当前测试/测试迭代的执行,那么您可以使用恢复场景,并将其设置为在每次错误时从函数库调用函数,这将确保在每次失败后调用该函数,然后您可以执行任何您想要的操作

现在,只有当您遵循UFT提供的执行框架,并且只关注错误,而不是执行流失败时,这才有效

2) 如果您已经创建了自己的框架,那么选项1可能对您没有帮助,因为您的测试将由输入表控制,并且您的框架在执行期间必须切换到下一个测试用例。所以我解决这个问题的方法是,我创建了一个隧道函数,所有其他函数调用都是通过这个函数进行的,所以在您的例子中,OpenAUT和Login将是这个隧道函数中的函数调用,如下所示

Public Function CallAppropriateFunctions()

    On Error Resume Next

    Select Case expression
        Case "OPENUAT"
            OpenAut()
        Case "LoginAPP"
            LoginApp()
    End Select

    If Err.Number <> 0 Then
        ''Control will come here on error
    End If

End Function
而您的
调用适当的函数
将变为

Public Function CallAppropriateFunctions()

    On Error Resume Next
    Dim Results
    Select Case expression
        Case "OPENUAT"
            Results = OpenAut()
        Case "LoginAPP"
            Results = LoginApp()
    End Select

    If Err.Number <> 0 Then
        ''Control will come here on error
    End If

    If Results = false then
        '' Your function executed successfully but application produced a different '''''''result
    End If

End Function
Public Function callapprovedfunctions()
出错时继续下一步
模糊结果
选择大小写表达式
案例“OPENUAT”
结果=OpenAut()
案例“LoginAPP”
结果=LoginApp()
结束选择
如果错误号为0,则
''控制将错误地出现在这里
如果结束
如果结果=false,则
“”您的函数已成功执行,但应用程序产生了不同的结果
如果结束
端函数
您可以阅读下面的文章来理解选项2

public function OPenUAT()

    ''Open App
    if APP.Exist then
        OPenUAT = true
    else
        OPenUAT = false
    End If

End Function 
Public Function CallAppropriateFunctions()

    On Error Resume Next
    Dim Results
    Select Case expression
        Case "OPENUAT"
            Results = OpenAut()
        Case "LoginAPP"
            Results = LoginApp()
    End Select

    If Err.Number <> 0 Then
        ''Control will come here on error
    End If

    If Results = false then
        '' Your function executed successfully but application produced a different '''''''result
    End If

End Function