Create Shared Object Repository in QTP

by seetaram on October 4, 2011

As the name suggests, Shared Object Repository can share the objects across various tests. Shared object repository can be created through Object Repository Manager. After creating the shared repository, it needs to be associated with a particular test.  Then the objects stored in the repository are accessible to the associated test / action. The biggest advantage of this type of repository is that if the application undergoes frequent user interface changes then the repository can be updated at only one place instead of updating all the local repositories for each test.

Follow the below steps to create Shared Object Repository:

  1. Open QuickTest Professional
  2. In the QTP window click on Resources –> Object Repository Manager
  3. Click File –> New in Object Repository Manager
  4. Click Objects –> Add Objects
  5. Mouse pointer gets turned to “hand” symbol –> click the object to be added
  6. Added objects are displayed in a tree structure

SharedOR

SharedNewOR

SharedORAddObjects

We will create test scripts for two end-to-end test scenarios:

  1. Login –> Insert New Order-> Logout
  2. Login –>Update Existing Order –> Logout

First, let us go ahead and create a shared object repository (flightshared.tsr)and then associate the repository with both the tests.

To add objects to the object repository we can also follow below steps:

  1. Click on Add Objects
  2. Click on the Main Window / Dialog
  3. Define Object Filter popup comes up
  4. Click on Default object types radio button
  5. Click OK
  6. This adds all the default objects to the Object Repository
  7. Using highlight icon (as shown in the below figure) find out the object on the application
  8. Give a logical name which should be easier to identify the object
  9. Save the object repository

HighLightObject

highlightobject2

CreatedSharedOR

Create a new test in QTP

Save the test as “InsertNewOrder”

Associate the test with newly created Shared Object Repository (flightshared.tsr)

  1. Click on Resources –> Associate Repositories
  2. Click Add button (+)
  3. Select the File (flightshared.tsr)
  4. Click on Arrow button (>) to associate with the action

AssociateOR

AssociateOR2

associateOR3

Write the following code (the process of creating the code is explained in previous post)

'Script "Inserts an Order into the Flight application
'Author - Seetaram Hegde
'Copyrights - All rights reserved

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("AgentName:").Set "admin"
Dialog("Login").WinEdit("Password:").Set "mercury"
Dialog("Login").WinButton("OK").Click
Window("FlightReservation").WinMenu("Menu").Select "File;New Order"
Window("FlightReservation").ActiveX("DateOfFlight").Type "120212"
Window("FlightReservation").WinComboBox("FlyFrom").Select "Denver"
Window("FlightReservation").WinComboBox("FlyTo").Select "Frankfurt"
Window("FlightReservation").WinButton("flights").Click
Window("FlightReservation").Dialog("FlightsTable").WinButton("OK").Click
Window("FlightReservation").WinEdit("Name").Set "Karthik"
Window("FlightReservation").WinRadioButton("Business").Set
Window("FlightReservation").WinButton("InsertOrder").Click
Window("FlightReservation").WinMenu("Menu").Select "File;Exit"

Execute the Script by clicking on “Run” button or F5

This should successfully execute the script.

To demonstrate the usage of this shared object repository, we will add some more objects to the flightshared.tsr which are necessary for the second test.

Follow the above steps to add the additional objects:

  1. SearchResults – Dialog (All the default objects)
  2. OpenOrder – Dialog (All the default objects)

Save the object repository

Create a new test in QTP

Save the test as “UpdateOrder”

Associate the test with newly created Shared Object Repository (flightshared.tsr) as described above.

'Script "Updates an existing Order in the Flight application 
'uses name of the customer to select the record
'Author - Seetaram Hegde
'Copyrights - All rights reserved

SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("AgentName:").Set "admin"
Dialog("Login").WinEdit("Password:").Set "mercury"
Dialog("Login").WinButton("OK").Click
Window("FlightReservation").WinMenu("Menu").Select "File;Open Order..."
Window("FlightReservation").Dialog("OpenOrder").WinCheckBox("CustomerName").Set "ON"
Window("FlightReservation").Dialog("OpenOrder").WinEdit("CustomerName").Set "Arun"
Window("FlightReservation").Dialog("OpenOrder").WinButton("OK").Click
Window("FlightReservation").Dialog("OpenOrder").Dialog("SearchResults").WinButton("OK").Click
Window("FlightReservation").WinRadioButton("Economy").Set
Window("FlightReservation").WinButton("UpdateOrder").Click
Window("FlightReservation").WinMenu("Menu").Select "File;Exit"

Execute the script with Run or F5. This should successfully run the script.  After the execution results window will appear. We will discuss the results window in detail in the future posts.

{ 3 comments… read them below or add one }

deepa April 25, 2013 at 11:43 am

please send me the detailed steps to learn more about QTP

Reply

seetaram August 22, 2013 at 5:37 am

Sure Deepa

Reply

Jayasree August 5, 2015 at 11:03 pm

Hi, Can you please tell me how can we access one script from shared object repository, If there are 100 Scripts

Reply

Leave a Comment

Previous post:

Next post:

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email