Micro Focus QTP (UFT) Forums
Search function in repository - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Search function in repository (/Thread-Search-function-in-repository)



Search function in repository - gbartokai - 04-16-2009

With QTP, the function "Exist" runs only if an object is in the repository.

for example, I have a WebButton named "login" in repository. If I use the Exist function, result is "true" if the object is on screen or "false" if the object is not present on screen.
But if the Webbutton was never identified in repository, the exist function will return an error "object not find in repository"!

I need to create a function to analyse if an object exist in repository.
With this function, i will be able to know if an object exist and after that, I can try to execute an operation.

For example, I developed a ButtonClick function in Web environment. classicaly the command will be

Code:
Function ButtonClick (XXX,YYY,ZZZ)
    Browser("XXX").Page("YYY").WebButton("ZZZ").Click
End Function

But It should be possible that my object is not a WebButton but an image.
In this case the function must be :

Code:
Function ButtonClick (XXX,YYY,ZZZ)
    Browser("XXX").Page("YYY").Image("ZZZ").Click
End Function

How Can I combine this two function in one?
I try this:

Code:
Function ButtonClick (XXX,YYY,ZZZ)
    if  Browser("XXX").Page("YYY").WebButton("ZZZ").exist = true then
         Browser("XXX").Page("YYY").WebButton("ZZZ")
    else
        Browser("XXX").Page("YYY").Image("ZZZ").Click
    end if
End Function

In case of Image exist in repository but not the webbutton with this name, the exist function return error and QTP stop. So I need to know if an object exist in repository, check his different classes and execute action based on different classes.

Someone can help me with this issue?


RE: Search function in repository - Hema - 07-08-2009

Hi ,

I think below code is helpful to search the object in Object Repository
' Here ObjName is Logical Name of Object and ObjProperty is the Class Name of that Object
Code:
Function CheckRepository(ObjName,ObjProperty)

Dim ObjRepository , AllObjects ,iCount , i , TestObject
Set ObjRepository = CreateObject("Mercury.ObjectRepositoryUtil")
ObjRepository.load "C:\Automation_V2\Object Repository\SampleObjectRepository1.tsr"
Set AllObjects = ObjRepository.GetAllObjects(Null)
iCount=AllObjects.Count
For i=0 to iCount-1
    Set TestObject = AllObjects.Item(i)
    If  ObjName=ObjRepository.GetLogicalName(TestObject) Then
        msgbox TestObject.GetTOProperty("Class Name")
        If TestObject.GetTOProperty("Class")=ObjProperty Then
            msgbox "Object Found in ObjectRepository"
            Exit For
        End If
     End If
Next
Set TestObject = Nothing
Set AllObjects = Nothing
Set ObjRepository=Nothing

End Function
---Hema