Monday, January 9, 2012

QTP : Object Repository

An Object is an element that is present in the application. All the elements of the application are considered as objects. Each object belongs to particular class like List box , edit box , button , image , links etc. Have a look at the Facebook Page below:



Some of the important objects present in the facebook Log In Page and their classes are:


Working with Object Repository: When QTP works on any of the objects in the application it adds the description of the object into the object repository. Object repository acts as a container to store test objects. Test object is the object created by QTP in the test script to represent the object present in the application. To open an Repository choose Resource>Object Repository. Object Repository looks like this:

           
Object Repository along with storing objects, can also be used to add, delete and find the objects. Below is the tool bar of object repository with important icons.


Find: 
To find Object or property value in Object Repository.
Add Objects: 
Add Objects to Local Repository.
Define New Test Objects: 
Defines new test object with given name and properties.
Highlight in Application:
 If an object is selected in repository the same will be highlighted in the application.
Locate Object in Repository: If we show an object in application, the same object will be located in object repository.


Test Object: Test object is the object created  by QTP in the OR (Object Repository). Test object is the representation of the applications actual object in the repository.


For example consider the Log In button is clicked on Facebook. The representation of this Log In button object stored in OR is called test object.


Run Time Object: The actual object that is present in the application on which the QTP performs an operation.


Object Repository Types: Depending on the way objects are stored and used by QTP test scripts , Object Repositories are divided in two types.
  • Local Object Repository
  • Shared Object Repository
Local Object Repository: In Local OR , the objects are stored for a particular action and only that particular action can access the stored objects. An Action is nothing but few lines of code in the QTP script. By default, during recording all objects corresponding to user actions are automatically stored in the corresponding action's local object repository.

Test objects stored in Action 1 local repository can only be accessed by Action 1 of the test object and not by Action 2. Similarly Action 2 repository can only be accessed by Action 2 of the Test.

Shared Object Repository: A shared object repository contains objects  that can be shared by multiple actions of the same test script or different test scripts. A shared object repository stores objects in the form of a file with extension .tsr which stands for test shared repository.


In the above figure, there are two tests which require same objects so instead of creating three local repositories with the same objects, a shared repository is created and accessed by all the three actions.

IMPORTANT:
  • When a test is recorded objects are by default stored in local object repository.
  • A test can use a combination of repository types,test can use both local and shared OR.
  • If an object is located in both Local and Shared OR, the action will use the local object definition.
  • A test can be associated with many shared repositories.
  • It is always preferred to use Shared Repository over Local Repository since every object is present only once and it can be shared by all required actions.
Creating a Local Repository: Test Objects are added to Local OR automatically in recording modeObjects can be added to Local OR manually by following the steps below.
  • Click on the OR button   from the automation toolbar or select
    Resources>Object Repository.
  • Click the Add Objects to Local toolbar button  and select the object to be added to the repository.

                   
QTP creates a new empty local OR for every action in a test, If a child object is added to a local repository and its parent object is in shared repository then its parent objects are automatically added to the local object repository.when you save your test all of the local OR are automatically saved with the test as part of each action within test. The local OR cannot be stored as a separate file.
    Exporting Local Objects to a Shared Object Repository: The first step involved in creating a shared repository is to export the objects from the local repository to a shared repository. This can be done in two ways:
    • Export Local Objects option will export all the local objects to shared file which will be stored in a physical location.
    • Export and Replace Local Objects option will export all the local objects to shared object repository and associates the new shared OR with the action, and automatically deletes the objects in the local object repository of that action.

    Associating Shared OR to Action: Once the shared object repository is created by exporting the local objects, the next step is to add the shared repository to the action.
    1.  Click on Associate Repository button  or select Resources> Associate Repositories

            
    2. To add a shared object repository to the list, click the Add button   and to remove an
      OR from the list ,click the Remove button  .
    Object Repository(OR) Manager: OR manager is used to manage the shared repositories , Using OR manager shared repositories can be created and edited. The operations that can be done are add,delete,rename and move objects of the shared repositories from one repository to another.

    Object Comparison Tool: The object repository comparison tool  is used to compare two repositories for similarities and variations among objects. This tool compares for different object names ,descriptions, properties and values of each object in two repositories. After the compare process the tool generates a report which displays graphical representation of the objects of the repositories. In this report objects that have differences and the objects that are present in one repository are highlighted.



    **************************************************************************************************************************************
    " A lot of people want a shortcut. I find the best shortcut is the long way, which is basically two words: work hard. "






    1 comment:

    1. Thanks Syed for posting such a detailed notes.God bless you :)

      ReplyDelete