Sunday, January 11, 2009

Script for adding and ramoving Object repository to an action

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)

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

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

8 comments:

Sandeep Kashyap said...

can you please share a script to add the object in the existing repository while runtime.

RAJAPUTRA said...

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.

Unknown said...

Hi,

Can anyone give answer to this question?
On recording how objects will get directly added to Shared Repository and not Local.

Thanks,
Smita

Unknown said...

Hi,

Can anyone give answer to this question:
On recording how objects will get directly added to Shared Repository and not Local.

Thanks,
Smita

RAJAPUTRA said...

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.

Unknown said...

Thanks Rajaputra

Anonymous said...

How can we delete such local objects created?

Anonymous said...

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?

About Me

My photo
Hi all,I am Arun Singh Rajaputra. I am working as a Project Lead in a reputed organization in Hyderabad, AP, India. I have little bit knowledge on Quick Test Professional and like to share my knowledge to all through this blog.

Subscribe to get updates on this blog

Enter your email address:

NOTE

Some of the posts posted in this blog are collected and most of them have been prepared by me. If any one have objections regarding any copied posts. Please mail me so that I can take a necessary action on that post.