假设我有一个用qtp开发的测试脚本,现在我的要求是通过VBscript检查这个特定的测试用例是否有一个与之关联的本地对象?
答案 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