How to add object repository at runtime in UFT
UFT stores the locators of the application under test in object repositories. There are two types of object repositories.
- Local object repository
- Shared object repository.
The local object repository is associayted within each action, while shared object repository can be saved as a .tsr file and can be carried over any action of the test or even across multiple tests.
Please read further to know How to associate an object repository at runtime in UFT.
The repositories can be added for a specific action.
Dynamic Handling of Object Respositories represents the Finding the path of the object repository, Loading the Object Repository and Removing the Object repository during run time.
Dynamic Handling is very helpful to improve the QTP performance.To do this, QTP is providing an object called “RepositoriesCollection”.
How to load Object Repository at runtime
Use the following code snippet to load a specific Object Repository.
RepositoriesCollection.Add “Path of the repository file”
How to find Object repository at runtime
Use the following code snippet to find a specific object repository.
RepositoriesCollection.Find(“Path of the Object repository”)
How to remove Object Repositories at runtime
Use the following code snippet to remove the Object Repository during run time.
We can remove all the loaded Object Repositories by using the following code snippet.
'This code is to demonstrate resource loading at runtime in UFT/QTP 'with the help of the following inbuilt functions in UFT/QTP. ' 'RepositoriesCollection.Fin(OrPath)- Finds a repository 'RepositoriesCollection.Add(OrPath)- Adds a repository 'RepositoriesCollection.Remove(pos)- Removes a repository 'RepositoriesCollection.RemoveAll- Removes all the repositories 'Path of shared object repository OrPath="C:\AutomationObjectRepositoryLogin.tsr" RepositoriesCollection.Add(OrPath) SystemUtil.Run "C:\Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe" Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set "username" Dialog("Login").WinEdit("Password:").SetSecure "mercury" Dialog("Login").WinButton("OK").Click 'Finds the position of provided object repository pos=RepositoriesCollection.Fin(OrPath) 'Removes the repository found at position pos RepositoriesCollection.Remove(pos) 'Removes all the resources RepositoriesCollection.RemoveAll
more code ?