Sunday, March 1, 2009

RepositoriesCollection Object

It is a collection object through which you can programmatically manage Shared Object Repositories at run time.

What is RepositoriesCollection object used for?

You can use the RepositoriesCollection object to associate or disassociate shared object repositories with an action during a run session. This in turn allows you to perform steps on test objects that are stored in that repository without recording on the object or permanently associating the repository with the action.

Name the Methods and Properties associated with RepositoriesCollection object.

Methods: Add, Find, MoveToPos, Remove, RemoveAll
Properties: Count, Item

Example of an Add method of RepositoriesCollection object
[Adds an object repository file to the specified index position in the run-time collection of shared object repository files associated with the current action.]

Follow steps 1 to 9 of this post.

In the 7th step above, I named the shared object repository as Repository1.tsr

Make sure that the Login window of Flight application is still open.

In a new test type one line of code:

Dialog("Login").WinButton("OK").Click

Now run the test. It will show the below shown error. (because we did not record)



Now in the above test add two more lines so the final code looks like this:

Repository_Path = "C:\Program Files\HP\QuickTest Professional\Repository1.tsr"
RepositoriesCollection.Add(Repository_Path)
Dialog("Login").WinButton("OK").Click

Now run the test.
It will click on the OK button.

It is clicking on the OK button in this above code because we are associating the shared object repository, created above, with this action (see RepositoriesCollection.Add statement). If you comment first two lines and then run the test, it will fail. You can also go to Edit-> Action-> Action Properties to verify that this action has no associated shared object repositories there and this Repository1.tsr is associated only at the run time.


Example of Find method of RepositoriesCollection object

In the above code add two more line so the final code becomes:

Repository_Path = "C:\Program Files\HP\QuickTest Professional\Repository1.tsr"
RepositoriesCollection.Add(Repository_Path)
Pos = RepositoriesCollection.Find(Repository_Path)
Msgbox (Pos)
Dialog("Login").WinButton("OK").Click

Now run the test and it will show the index position of the specified object repository file within the run-time collection of shared object repository files associated with the current action.



Example of Count Property of RepositoriesCollection object
[It counts the number of object repository files in the run-time collection of shared object repository files associated with the current action.]
Repository_Path = "C:\Program Files\HP\QuickTest Professional\Repository1.tsr"
RepositoriesCollection.Add(Repository_Path)
repo_count = RepositoriesCollection.Count
Msgbox (repo_count)
Dialog("Login").WinButton("OK").Click



Example of an Item Property of RepositoriesCollection object
[Returns the path of the object repository file located in the specified index position within the run-time collection of shared object repository files associated with the current action.]
Repository_Path = "C:\Program Files\HP\QuickTest Professional\Repository1.tsr"
RepositoriesCollection.Add(Repository_Path)
Msgbox (RepositoriesCollection.Item(1) )
Dialog("Login").WinButton("OK").Click



In this way you can add more object repositories and try other methods of RepositoriesCollection object on your own in order to understand better.