Ankit Tewari
Ankit Tewari

Reputation: 70

How can we check if local Object exist in test script developed in QTP through vbscript?

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

Answers (1)

vins
vins

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

Related Questions