Wednesday, September 15, 2010

RepositoriesCollection utility

RepositoriesCollection utility object introduced in QTP 9.2 allows adding a Object Repository dynamically to a Action. The code shown below demonstrates how to add a object repository at run-time
RepositoriesCollection.Add "C:\Test.tsr"
The code above associates the Object Repository to the current action. But when the same code is added to a library and associate with the test, QTP throws an error “Cannot perform the operation because the action is a read-only action.”.
The reason this error occurs is that library files are loaded first and then the Actions. When the code run inside the library file, QTP tries to associate it with the current action. Since the Actions are not loaded yet the RepositoriesCollection object associates the Repository permanently to the test’s first Action. This is a bug in RepositoriesCollection as it is never supposed to associate the Object Repository permanently.
Fixing the issue
Fixing the issue is pretty simple. We can either move the code from the library file to the Action or we can put the code in a function inside library file and later call the function inside the Action


Inside library file
Function LoadOR()
RepositoriesCollection.Add "C:\Test.tsr"
End Function

'Inside the action
Call LoadOR()

No comments:

Post a Comment