You are on page 1of 3

Load a object repository in QTP during runtime

we can add object repository at runtime in 2 different ways:

1. when u write below syntax in Action1

Syntax: RepositoriesCollection.Add(Path)

Ex: RepositoriesCollection.Add(E:\OR\ObjRes.tsr)

if write in Action1 it will automatically add the Object


Respository to the Action1
(i.e Edit Menu-->Action-->Action Properties-->Associate
Repository tab) at runtime.

no need to add the object repository before running.

2. Add the object repository at runtime by using AOM (Automated Object Model)

Ex:
Dim qtAppn
Dim qtObjRes

Set qtAppn = CreateObject("QuickTest.Application")


qtAppn.Launch
qtAppn.Visible = True

qtApp.Open "E:\Test\Test2", False, False


Set qtObjRes = qtApp.Test.Actions
("Login").ObjectRepositories

qtObjRes.Add "E:\OR\ObjRes.tsr", 1

The above example Add the Object Repository(ObjRes.tsr) to the "Login" action in Test2.

Here also no need to add the object repository in Test2.

3.This code with work definitely...

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

For single Repository:

sTsrMap = "C:Bottom.tsr"

Call LoadUnloadTsr (sTsrMap)

For Multiple Repository

Dim sTsrMap

sTsrMap=Array(“C:1.tsr”,”C:2.tsr”)

For i=0 to Ubound(sTsrMap)

Call LoadUnloadTsr (i)

Next

4. 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)

5.Another way:

' Declare the Application object variable


Dim qtApp 'As QuickTest.Application

Dim qtRepositories 'As QuickTest.ObjectRepositories

' Declare an action's object repositories collection variable


Dim lngPosition ' Open
' Create the Application object
QuickTest Set qtApp = CreateObject("QuickTest.Application")

' Launch
qtApp.Launch

' Set QuickTest to be visible


QuickTest qtApp.Visible = True

' 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
' Add the repository to the collection
qtRepositories.Add "your tsr file.tsr", 1
End If

You might also like