How can i update several objects attibutes in local Objet Repository (LOR) in QTP?
Question ID: 104699
1
0

The application I test has had a major upgrade to all the objects attributes in QTP local object Repository. The application has change the name attribute. Does anybody know how I can update the local object repository with out manually changing each object in the OR?

Marked as spam
Posted by (Questions: 17, Answers: 5)
Asked on November 14, 2012 11:26 am
97 views
Answers (2)
7
Private answer

There is no real easy way to update Local Object Repository (OR) Here are three options.

A. Have you tried to run the test in Maintenance mode run?
B. QTP 11 does allow you to export import the Object Repository to xml. I have not done it this and not sure if it will work. (NOT RECOMMENDED FOR QTP 10)
...1. Export OR to XML.
...2. do a mass up search and replace of the text that needs to be changed.
...3. Import the xml back into OR

C. Use the QuickTest Automation Object Model (AOM) to write a vbs script to modify the object repository.

I have been able to figure out an example for you. There are some changes that will have to be done to the code so that it can iterate over several actions and tests but this is a start.


Option Explicit 
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'QTP Test ojbect
DIM qtTestActions ' Collection of actions
Dim RepositoryFrom ' Object repository Util 
Dim ToCollection  ' Collection of OR objects
Dim TestObject ' active test object

'Variables 
Dim cn
DIM LORPath  '  Variable to hold path to LOR
DIM i   ' loop variable

Msgbox ''Start''
' Open QuickTest
Set qtApp = CreateObject(''QuickTest.Application'') ' Create the Application object
qtApp.Launch ' Launch QuickTest
qtApp.Visible = True ' Set QuickTest to be visible

' Open a test and get the ''Action1'' action's object repositories collection
qtApp.Open ''Z:UpdateORDemoTest'', False, False ' Open a test
Set qtTest = qtApp.Test
Set  qtTestActions=qtTest.Actions
'Set  qtTestActions(''Action1'').
'msgbox qtTestActions(''Action1'').Type
LORPath=qtTestActions(''Action1'').Location & ''ObjectRepository.bdb''

msgbox LORPath

Set RepositoryFrom = CreateObject(''Mercury.ObjectRepositoryUtil'')

RepositoryFrom.Load LORPath 

Set ToCollection = RepositoryFrom.GetAllObjectsByClass(''Link'')

For i = 0 To ToCollection.Count - 1
	
	Set TestObject = ToCollection.Item(i)
	cn = TestObject.GetTOProperty(''html tag'')
	' msgbox cn
	
	If cn = ''A''  Then
		TestObject.SetTOProperty ''html tag'', ''Blue''
	End If
	
	RepositoryFrom.UpdateObject TestObject
	RepositoryFrom.Save
	
Next
	


'Save the changed repository.
RepositoryFrom.Save

MsgBox ''Completed''
'Save the test and close QuickTest
qtApp.Test.Save ' Save the test
qtApp.Quit ' Quit QuickTest


Set TestObject = Nothing 
Set ToCollection = Nothing 
Set RepositoryFrom = Nothing 
Set qtTestActions = Nothing 
Set qtTest = Nothing 
Set qtApp = Nothing ' Release the Application object
Marked as spam
Posted by (Questions: 2, Answers: 98)
Answered on November 14, 2012 11:36 am
0
Private answer

Full solution:
'This script uses an excel sheet to get a list of local object repositories and then updates them based on the object class and property
'To run the script click the widnows button and type cmd in the search. In the command prompt paste the following:WScript.exe /E:VBSCRIPT [name of sript].vbs

'Turn on error handling
On Error Resume Next

'Variables
Dim RepositoryFrom, ToCollection, ToCollectionP, TestObject, cn, OrArrPath(), OrPath, xlApp, xlWorkBook, xlWorkSheet, ExlRwCnt, ArrSize, ArrSet

'create a new instance of the excel application
Set xlApp = CreateObject (''Excel.Application'')

'make it visible
xlApp.Visible = True

'open the excel file to feed the report paths ie (''C:excelfilename.xls'')
'The values in the excel file should be the full path without any parenthesis
'ie c:[Report Path]Action1ObjectRepository.bdb
Set xlWorkBook = xlApp.Workbooks.Open (''C:excelfilename.xls'')

'set the worksheet
Set xlWorkSheet = xlApp.ActiveWorkBook.WorkSheets(''Sheet1'')

'Use Evaluate function to determine how many rows have a non- blank values
ExlRwCnt = xlWorkSheet.Evaluate(''COUNTA(A:A)'')

'Get the count in the excel worksheet and subtract one to set the array
ArrSize = ExlRwCnt -1

'Set the size of the array
ReDim OrArrPath(ArrSize)

'Set the array counter in order to begin setting each point in the array
ArrSet = 0

'Cycle through each path and update each object in that path
For z = 1 to ExlRwCnt

'Get excel sheet value
Set OrArrPath(ArrSet) = xlWorkSheet.Cells(z,1)

'add a value to the arrsize variable to set the next position
ArrSet =ArrSet +1

Next

'Reset the array counter to update each object
ArrSet = ArrSet -1

'Update all of the object repositories
For x = 0 To ArrSet

'Set the ObjectRepositoryUtil
Set RepositoryFrom = CreateObject(''Mercury.ObjectRepositoryUtil'')

'Grab the first object repository path from the array. Note this probably could be assigned directly from the array.
OrPath = OrArrPath(x)

'Load the path to the ObjectRepositoryUtil
RepositoryFrom.Load OrPath

'If there is an error catch it display it in a message box and exit the script
If Err.Number <> 0 Then
msgbox(OrPath)
WScript.Echo ''Error: '' & Err.Number
WScript.Echo ''Error (Hex): '' & Hex(Err.Number)
WScript.Echo ''Source: '' & Err.Source
WScript.Echo ''Description: '' & Err.Description
Err.Clear
Exit For
End If

'Grab all of the objects with a class ie ''Window''
Set ToCollection = RepositoryFrom.GetAllObjectsByClass(''Window'')

'For each attribute in the collection of objects
For i = 0 To ToCollection.Count - 1

'Grab the object
Set TestObject = ToCollection.Item(i)

'Get the value of this object attribute
cn = TestObject.GetTOProperty(''regexpwndclass'')

'If the value matches then set it to the new attribute
If cn = ''FNWND3120'' Then
TestObject.SetTOProperty ''regexpwndclass'',''FNWND3125''
End If

'save the object in the object repository
RepositoryFrom.UpdateObject TestObject

'save the Object Repository
RepositoryFrom.Save
Next

Next

'save object Repository
RepositoryFrom.Save

'Clear the variables/destroy them
Set RepositoryFrom =nothing
Set ToCollection = nothing
Set ToCollectionP=nothing
Set TestObject = nothing
Set cn =nothing
Set OrPath = nothing
Set ExlRwCnt = nothing
Set ArrSize = nothing
Set ArrSet = nothing

'Close the workbook and terminate our instance of excel
xlWorkBook.Close
xlApp.Quit

'Clear excel variables/destroy them
Set xlWorkSheet = Nothing
Set xlWorkBook = Nothing
Set xlApp = Nothing

'Notify the user the script is finished
msgbox(''Update Finished'')

Marked as spam
Posted by (Questions: 0, Answers: 2)
Answered on November 14, 2012 1:50 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top