How to load a .tsr file(object repository) in QTP thru code as it is in the Winrunner like, gui_load. Is there any script exist in QTP8.2

Showing Answers 1 - 29 of 29 Answers

SG

  • Mar 6th, 2006
 

This might be helpful....

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTestResources 'As QuickTest.Resources ' Declare a Resources object variable

' Specify an external Data Table file and a shared object repository
qtTestResources.DataTablePath = "C:\Resources\Default.xls"
qtTestResources.ObjectRepositoryPath = "C:\Resources\Resource.mtr"
' Make this shared repository the default for all new tests
qtTestResources.SetObjectRepositoryAsDefault

  Was this answer useful?  Yes

Konka Ravi Krishna

  • Mar 27th, 2006
 

HI,

' I don't think so above code is working fine?

Just copy paste this code it will work fine:

******************************************************
testsai("C:\Default.tsr")
 
Dim a
Function testsai(a)
 Dim App 'As Application
 Set App = CreateObject("QuickTest.Application")
 App.Test.Settings.Resources.ObjectRepositoryPath = a
End Function

******************************************************

Regards,
Ravi Konka

  Was this answer useful?  Yes

Shafi

  • Sep 10th, 2006
 

ObjectRepositoryPath property is no longer supported.

Now how to load the object repository while running the script?

  Was this answer useful?  Yes

chakri

  • Sep 18th, 2006
 

Appreciate for the code...but can yu explain me how to go about it.

******************************************************
testsai("C:Default.tsr")
 
Dim a
Function testsai(a)
 Dim App 'As Application
 Set App = CreateObject("QuickTest.Application")
 App.Test.Settings.Resources.ObjectRepositoryPath = a
End Function

-----

my question is i copy this code and paste in notepad and save it as Default.tsr and go to QTP and shared repository and take the path where this notepad is. Then go to QTP expert view and call the .tsr file. Iam not able to get this at all. can yu elaborate in detail. It would really help me a lot.

thnx a lot

Chakri

  Was this answer useful?  Yes

Hari

  • Oct 18th, 2006
 

Hi,

 Did any one got the answer for this , i am also facing the same problem can some one help how to load objects through code like we do gui_load in win runner TSL scripting.

Thanks,

Hari

  Was this answer useful?  Yes

mnukala

  • Feb 2nd, 2007
 

Add this code at the begining of a script, or you can copy it to a .vbs file and call that file at the begining of a scriptDim qtApp 'As QuickTest.Application ' Declare the Application object variable Dim qtRepositories 'As QuickTest.ObjectRepositories ' Declare an action's object repositories collection variable Dim lngPosition ' Open QuickTest Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object qtApp.Visible = True ' Set QuickTest to be visible ' Gget the that action's object repositories collection Set qtRepositories = qtApp.Test.Actions("action_name").ObjectRepositories ' Get the object repositories collection object of the specified action ' Add MainApp.tsr if it's not already in the collection If qtRepositories.Find("your object repository.tsr") = -1 Then ' If the repository cannot be found in the collection qtRepositories.Add "your object repository.tsr", 1 ' Add the repository to the collection End If

  Was this answer useful?  Yes

mnukala

  • Feb 2nd, 2007
 

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable Dim qtRepositories 'As QuickTest.ObjectRepositories ' Declare an action's object repositories collection variable Dim lngPosition ' Open QuickTest Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object qtApp.Launch ' Launch QuickTest qtApp.Visible = True ' Set QuickTest to be visible ' Get the action's object repositories collection Set qtRepositories = qtApp.Test.Actions("action_name").ObjectRepositories ' Get the object repositories collection object of the action ' Add MainApp.tsr if it's not already in the collection If qtRepositories.Find("your tsrfile.tsr") = -1 Then ' If the repository cannot be found in the collection qtRepositories.Add "your tsr file.tsr", 1 ' Add the repository to the collection End If

  Was this answer useful?  Yes

josephA

  • Mar 28th, 2007
 

This works perfectly for me:

Dim qtApp
Set qtApp = CreateObject("QuickTest.Application")
Dim qtRepositories
Set qtRepositories = qtApp.Test.Actions("Main").ObjectRepositories
qtRepositories.Add("C:VS.tsr")

Manish Bansal

  • Aug 13th, 2007
 

The following example clears the run-time list of associated shared object repositories and then use the Add method to add the specified object repository to that list.

RepPath = "\MercurySORSMySharedObjectRepository.tsr"

RepositoriesCollection.RemoveAll()

RepositoriesCollection.Add(RepPath)

Pos = RepositoriesCollection.Find(RepPath)

RepositoriesCollection.Remove(Pos)

RepositoriesCollection.Add(RepPath)

Window("Microsoft Word").WinObject("Microsoft Word Document").Click

Pos = RepositoriesCollection.Find(RepPath)

  Was this answer useful?  Yes

This code with work definitely...

sTsrMap = "C:Bottom.tsr"

Public Function LoadUnloadTsr(sTsrMap)
 Dim qtApp, qtRepositories
 Set qtApp = CreateObject("QuickTest.Application")
 ActionName = Environment("ActionName") ' am just getting the action name
 Set qtRepositories = qtApp.Test.Actions(ActionName).ObjectRepositories 
' just creating an object in order to access repositories of the above said action.
  qtRepositories.RemoveAll ' removing all previously associated repositories.
  qtRepositories.Add sTsrMap,1 ' Action the repositort.
 Set qtApp = Nothing
End Function

LoadUnloadTsr sTsrMap

  Was this answer useful?  Yes

Sarfaraz Alam

  • Feb 28th, 2012
 

Simply use this code...it will work fine:
Repositarycollection.Add"filepath.tsr"

  Was this answer useful?  Yes

Klaudia

  • Feb 4th, 2016
 

To refresh the topic, because maybe someone still is looking for the help.
All above solutions did not work for me. I have implemented the replacement of OR like below:
Replace the Object Repository of the BS
Set qtApp = CreateObject("QuickTest.Application")
Set qtRepositories = qtApp.Test.Actions("ActionName").ObjectRepositories
IngPosition = qtRepositories.Find("Path To Old Repository.tsr")
qtRepositories.Remove IngPosition
qtRepositories.Add "Path To New Repository.tsr"
Set qtApp = Nothing

  Was this answer useful?  Yes

Puneet Punj

  • Sep 6th, 2017
 

Hi Klaudia, Does this code add OR during run time only? or it physically associates with the mentioned action. Like how we do in Object Repository Manager.
Thanks,
Puneet

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions