How to set QTP Object Repositories at runtime

As you all know we can set Shared Object Repository path for our test scripts by associating repositories using QTP option. The only drawback here is that if you are using an absolute path for the Shared Object Repository then this becomes a dependency in case you are delivering the scripts to the client or in case you want to run the scripts from another machine.

As long as you are maintaining the path as same then we don't face any issues.

Else what you need to do to set the Object Repository path at run time?

You need to create or get an handle to the QTP APP object

Create a collection of QTP Repositories

Make sure that both the above variables are global in nature - accessible to all actions

Example: This will work in QTP 10

Set colQTPRepositories = App.Test.Actions(Environment("ActionName")).ObjectRepositories
colQTPRepositories.Add "SORPath", 1

It is even better if you read the SOR Path from a configuration file.

Ensure that you set the created objects to nothing as appropriate

Please leave a comment to know more on this.

No comments: