Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

Object Repositories in QTP:Understanding Types and Collection Object.


Object Repository stores all the objects learned in the application. An Object repository is automatically created when we record in the application. Object can also be added in object repository through object spy and Navigate and Learn objects.

Following are important points to remember about object repositories:

  • Objects are stored in tree structure in OR with child objects linked to parent objects.
  • Objects in Local OR and shared OR can be accessed/modified through Object Repository window and Object repository manager window respectively.
  • Objects in OR can be added through:
o    Recording mode
o    Active screen
o    Using Object Spy
o    Using Navigate and Learn through Object repository window.
  • Objects can be added with expected properties defined manually in OR. This is useful in case application is not ready, but we know the expected property for objects.
  • Copying or moving an object to be a child of a bottom-level object in the object hierarchy is not allowed.
  • Property value and name of object in object repository can be modified.
  • Modifying the name of a test object in the local object repository is automatically updated in both the Keyword View and the Expert View for all occurrences of the test object.
  • We can highlight objects from OR in application.
  • Object from object repositories can be dragged and drop in the expert view. Hierarchy Tree of the object is visible in expert view on dragging object from OR.


There are two types of Object Repositories:


1. Local Repository

Objects are automatically added in Local Object Repository once they are learned from the application.

Following are important points to remember about Local Object Repository:

  • If an object with the same name is located in both the local object repository and in a shared object repository associated with the same action, the action uses the local object definition.
  • Local Object Repository is associated with the action in which it was created. You cannot associate Local object repository with multiple actions. Due to this, they are useful mainly in single action.
  • If child objects are moved from shared OR to local OR, parent objects are also added to Local OR.


2. Shared Object Repository


A shared object repository stores objects in a file that can be accessed by multiple tests (in read-only mode).

Following are important points to remember about Local Object Repository:

  • Same Shared Object repository can be added for multiple actions.
  • Shared OR can be dynamically associated with tests and multiple actions.
  • Shared OS is saved with extension .tsr
  • Objects from local OR can be exported to shared OR.
  • An Action can have multiple Shared object repository associated.
  • A shared repository can be edited by one person at a time and is locked for other user
  • Using OR comparison tool, we can compare the objects in 2 different shared OR
  • Using Object repositories Merge tool, we can merge two shared OR and create a new OR with objects from both the OR’s.

Associating Repositories with Action

We can associate object repositories with action in following ways:

Through QTP Interface


Navigate to Resources>Associate Repositories. Click on + icon and select repositories. Note we can add shared object repository only. Next Select Actions from available Actions and move required actions to Associated Actions.



Associating Repositories with Actions
























Using Object Repositories collection


We can add object repositories using ObjectRepositories Collection

Below code snippet shows how to add ObjectRepositories using QTP AOM

Public Function func_AddORToTest(TestName, ActionName, ORName)
''Create an object of qtp
Set qtApp = CreateObject("QuickTest.Application")
qtApp.Launch
qtApp.Visible = True

qtApp.Open TestName
Set qtRepositories = qtApp.Test.Actions(ActionName).ObjectRepositories


' Add MainApp.tsr if it's not already in the collection
If qtRepositories.Find(ORName) = -1 Then ' If the repository cannot be found in the collection
qtRepositories.Add ORName, 1 ' Add the repository to the collection
End If
'Save the test and close QuickTest
qtApp.Test.Save
qtApp.Quit 


Set qtRepositories = Nothing
Set qtApp = Nothing

End Function

No comments:

Post a Comment