Reputation: 70
Suppose I have a Test script developed in qtp,and now my requirement is to check whether this particular test case has a local Object associated with it through VBscript??
Upvotes: 1
Views: 1506
Reputation: 15370
The below funciton in VBScript can check if the current test has an object with a particular name in its Object Repository.
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
EDIT:
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
Upvotes: 2