我们如何检查QTP中通过vbscript开发的测试脚本中是否存在本地对象?

时间:2014-11-24 11:40:20

标签: vbscript automation qtp hp-uft

假设我有一个用qtp开发的测试脚本,现在我的要求是通过VBscript检查这个特定的测试用例是否有一个与之关联的本地对象?

1 个答案:

答案 0 :(得分:2)

VBScript中的以下函数可以检查当前测试是否在其对象存储库中有一个具有特定名称的对象。

Function CheckIfObjectPresentInOR(ByVal LogicalName)
    Set ObjectRepositoryUtil =  CreateObject("Mercury.ObjectRepositoryUtil") 
    ObjectRepositoryUtil.Load "<Path of the Object Repository>"
    Set TOCOllection = ObjectRepositoryUtil.GetAllObjects
    booFunctionStatus = FALSE
    For i = 0 To TOCollection.Count - 1 
            If ObjectRepositoryUtil.GetLogicalName(TOCOllection.Item(i)) = LogicalName Then
                    booFunctionStatus = TRUE
                    Exit For
            End If
    Next
    Set ObjectRepositoryUtil =  Nothing
    Set TOCOllection = Nothing
    CheckIfObjectPresentInOR = booFunctionStatus
End Function

编辑:

Function CheckIfObjectPresentInOR
    Set ObjectRepositoryUtil =  CreateObject("Mercury.ObjectRepositoryUtil") 
    ObjectRepositoryUtil.Load "<Path of the Object Repository>"
    booFunctionStatus = FALSE
    Set TOCOllection = ObjectRepositoryUtil.GetAllObjects
    If TOCOllection.Count > 0 Then
         booFunctionStatus  = TRUE
    End If
    Set ObjectRepositoryUtil =  Nothing
    Set TOCOllection = Nothing
    CheckIfObjectPresentInOR = booFunctionStatus
End Function