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
"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.....
ReplyDeleteThis is really good stuff, How ur able to identify that paticular object is present..like the one used ..."Mercury.objectrepoistoryutil" ????
ReplyDeleteHi 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
ReplyDeleteI 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..
ReplyDeleteThe 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.
ReplyDeleteThanx Sudhakar....for the info...
ReplyDeleteDo we have any example on AddObject method of ObjectRepositoryUtil method???
ReplyDeleteits was amazing.i am able to read all objects
ReplyDeleteThanks 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