Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Thursday, July 30, 2009

Get Objects from Object Repository

Get Objects from Object Repository Using Object Repository Automation

'***************************************************************************
Dim RepositoryFrom
Dim ParentObject

ObjectRepositoryPath="C:\sudhakar kakunuri\Desktop\OR Automation\SampleOR.tsr"

'Creating Object Repository  utility Object
Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")

'Load Object Repository
RepositoryFrom.Load ObjectRepositoryPath

'Calling a Recursive Function
fnPrintObjectNames ParentObject

Function fnPrintObjectNames(ParentObject)

'Get Objects by parent From loaded Repository
'If parent not specified all objects will be returned

Set fTOCollection = RepositoryFrom.GetChildren(ParentObject)

    For RepObjIndex = 0 To fTOCollection.Count - 1

        'Get object by index
        Set fTestObject = fTOCollection.Item(RepObjIndex)

            'Check whether the object is having child objects
            If RepositoryFrom.GetChildren (fTestObject).count<>0 then

                print "Object Logical Name:= "&RepositoryFrom.GetLogicalName(fTestObject)

                print "**********************************************************"

                    'Get TO Properties List
                    Set PropertiesColl=fTestObject.GetTOProperties
                    
                    For pIndex=0 to PropertiesColl.count-1
    
                                'Print Property and Value
                                Set ObjectProperty=PropertiesColl.Item(pIndex)
                                print ObjectProperty.name&":="&ObjectProperty.value
                                
                    Next
                
                print "**********************************************************"

'Calling Recursive Function
                fnPrintObjectNames fTestObject

            else
            
                print "**********************************************************"
                   print "Object Logical Name:= "&RepositoryFrom.GetLogicalName(fTestObject)
                print "**********************************************************"
                    Set PropertiesColl=fTestObject.GetTOProperties
                    For pIndex=0 to PropertiesColl.count-1
                                Set ObjectProperty=PropertiesColl.item(pIndex)
                                print ObjectProperty.name&":="&ObjectProperty.value
                    Next
                
            End if
    Next

End Function

'*************************************************************************** 

If you want to get Object information from Local Object Repository then Give Object repository path as
ObjectRepositoryPath=Environment("TestDir")&\GetCurrentActionFolderName\ObjectRepository.bdb"

Here GetCurrentActionFolderName function used to get the action folder name from where the test is located.

Note:- If your getting Object information from Local Object Repository make sure that test is saved before running this script.

'*************************************************************************** 
Function GetCurrentActionFolderName()

Dim qtApp
Dim ActionIndex
Dim ActionFolderName

Set qtApp=CreateObject("QuickTest.Application")
For ActionIndex=1 to qtApp.test.Actions.count

    If Environment("ActionName")=qtApp.test.Actions(ActionIndex).name Then
        ActionFolderName="Action"&ActionIndex
        Exit For
    End If
Next

GetCurrentActionFolderName=ActionFolderName

Set qtApp=Nothing
End Function 
'*************************************************************************** 

____________________________________________________________


Please send your Suggestions and Doubts to my yahoo group http://in.groups.yahoo.com/group/qtpsudhakar

9 comments :

  1. "ObjectRepositoryPath=Environment("TestDir")&"\Action1\ObjectRepository.bdb"".......In this the "Action1" is hard coded....to remove that constraint...we can get the Action name as well from the built in environment variables.....

    ReplyDelete
  2. This is really good stuff, How ur able to identify that paticular object is present..like the one used ..."Mercury.objectrepoistoryutil" ????

    ReplyDelete
  3. Sudhakar Reddy KakunuriJuly 31, 2009 at 5:41 AM

    Hi sridhar,Environment("ActionName") winll not work here. Because we can change the action name but not the folder name. How ever i will update this with a solution.Can you elaborate your comment on " How ur able to identify that paticular object is present..like the one used ..."Mercury.objectrepoistoryutil" ????"Regards,Sudhakar

    ReplyDelete
  4. I mean..how do u know that there we can create a object of type Mercury.objectrepoistoryutil....from where we can get that info.....I think u have changed the Action1 to a function call...now its looking good..

    ReplyDelete
  5. Sudhakar Reddy KakunuriAugust 4, 2009 at 5:41 AM

    The source of each and every point which i have discussed in this blog is QTP help.You can find Mercury.objectrepoistoryutil in QTP help doc--> Advanced Reference.

    ReplyDelete
  6. Thanx Sudhakar....for the info...

    ReplyDelete
  7. Do we have any example on AddObject method of ObjectRepositoryUtil method???

    ReplyDelete
  8. its was amazing.i am able to read all objects

    ReplyDelete
  9. Thanks for the nice blog. The above code reads all the property name and values of my object repository. But i want to read the property of the particular object. May i know how to achieve it? May i know what is the use of 'ParentObject' in the function 'fnPrintObjectNames'. Please explain me with an small example.

    ReplyDelete