Here i have written two functions for adding and removing Object Repositories for an action call these function with object repository path.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Adding Repository to an action
Function AddRepositorytoCurrentAction(RepPath)
Function AddRepositorytoCurrentAction(RepPath)
Dim qtApp,qtRepositories, actName
actName=Environment.Value("ActionName")
Set qtApp = CreateObject("QuickTest.Application")
Set qtRepositories = qtApp.Test.Actions(actName).ObjectRepositories
If qtRepositories.Find(RepPath) = -1 Then
qtRepositories.Add RepPath, 1
End If
If rmvPosition<> -1 Then
Reporter.ReportEvent micPass,"Adding Object Repository","Object Repository is Succesfully Added to the Action "&actName
else
Reporter.ReportEvent micFail,"Adding Object Repository","Object Repository is not Added to the Action "&actName
End If
qtApp= Nothing
qtRepositories= Nothing
End Function
'Remove repository from an action
Function RemoveRepositoryfromCurrentAction(RepPath)
Dim qtApp,qtRepositories, actName
actName=Environment.Value("ActionName")
Set qtApp = CreateObject("QuickTest.Application")
Set qtRepositories = qtApp.Test.Actions(actName).ObjectRepositories
rPosition=qtRepositories.Find(RepPath)
qtRepositories.Remove rPosition
rmvPosition=qtRepositories.Find(RepPath)
If rmvPosition= -1 Then
Reporter.ReportEvent micPass,"Removing Object Repository","Object Repository is Succesfully Removed From the Action "&actName
else
Reporter.ReportEvent micFail,"Removing Object Repository","Object Repository is not Removed From the Action "&actName
End If
qtApp= Nothing
qtRepositories= Nothing
End Function
actName=Environment.Value("ActionName")
Set qtApp = CreateObject("QuickTest.Application")
Set qtRepositories = qtApp.Test.Actions(actName).ObjectRepositories
rPosition=qtRepositories.Find(RepPath)
qtRepositories.Remove rPosition
rmvPosition=qtRepositories.Find(RepPath)
If rmvPosition= -1 Then
Reporter.ReportEvent micPass,"Removing Object Repository","Object Repository is Succesfully Removed From the Action "&actName
else
Reporter.ReportEvent micFail,"Removing Object Repository","Object Repository is not Removed From the Action "&actName
End If
qtApp= Nothing
qtRepositories= Nothing
End Function
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
8 comments:
can you please share a script to add the object in the existing repository while runtime.
Hi,
Yes we can add Objects at runtime to the OR. You would have to open the OR at runtime and in a updatable mode.
Check out this code for the same -
Set QtApp = CreateObject("QuickTest.Application")
Set QtTestResources = QtApp.Test.Settings.Resources
QtTestResources.Load{Path of the Repository to be Opened}, mode
mode would be readOnly or Updatable.
Once you have the OR loaded use,
Add method and pass Obejct as parameter.
Hi,
Can anyone give answer to this question?
On recording how objects will get directly added to Shared Repository and not Local.
Thanks,
Smita
Hi,
Can anyone give answer to this question:
On recording how objects will get directly added to Shared Repository and not Local.
Thanks,
Smita
Hi Smita,
By default QTP makes and uses Local Object Repository. If we create a new blank test and do a recording on it, QTP automatically creates a Local Object Repository for that test or action and stores the information about any object it finds in that corresponding Object Repository.
This is the default that every time we create a new action QTP creates a new corresponding Local Object Repository. It is also true that Object Repositories are associated with actions and no matter how many times we learn or record on the same object in our application in different actions the object will be stored as separate test object in each of the Local Object Repository. Local Object Repository is automatically saved with the test when we save it. The extension of the Local Object Repository is .mtr, but it is not accessible as a separate file as in case of the Shared Object Repository.
So,On recording objects will directly stored in Local OR. Not in Shared OR.
Thanks Rajaputra
How can we delete such local objects created?
I am adding repository at run time but when i use batch runner, it does not open another test and says that "cannot close unsaved data" this is due to repository added. how can i save those settings at runtime?
Post a Comment