QTP – Create Object Repository (Local / Per-Action OR)

by seetaram on October 3, 2011

Object Repository is a collection of objects (its properties and methods), which can be referred in the automation script. There are two types of object repositories:

  1. Local Object Repository (per action OR)
  2. Shared Object Repository

Local Object Repository:

When a new test is created in QTP, it will be associated with an object repository and this is named as per-action / local object repository. This OR cannot be referred in the other tests / actions.

We will try to create an object repository and use in a test script.

  • Open QTP
  • Create a New Test (File –> New –> Test / Ctrl+N)
  • Save the test (File –> Save As –> Give a name / LoginScript)
  • Open Flight Sample application (Login screen)
  • Click Resources –> Object Repository (ctrl+R)

LocalOR1

AddObjecttoOR

  • Click on the Add Object icon in the Object Repository screen
  • Mouse pointer will turn to a hand symbol
  • Click on the Objects which we need to add one by one(first click on the Agent Name: edit box)
  • Make sure that the application for which we need to create Object Repository should be maximized and available on the desktop

ObjectRepositoryObjects

  • Once the objects are added to the Object Repository, we can see the added objects inside the OR as in the above picture

Change the logical names of each of the objects so that identifying the objects inside the script should be easier.

  • Click on the Cancel button in the Object Repository
  • On the right side, we can see the edit box (Object Properties) provided to edit the name of the object
  • Change the name to btnCancel – btn refers to “Button”
  • Change the name of the OK to btnOK
  • Change Agent Name: to wdtAgentName (wdt – WinEdit)
  • Change Password to wdtPassword

If we use naming convention such as wdt (WinEdit), btn (Button) it will be very much useful when there are a lot of objects to be captured in the Application Under Test. Below is the picture of updated Object Repository.

UpdatedOR

Let us try to create a LoginScript using this newly created Object Repository.

'Script "Login 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("wdtAgentName:").Set "admin"
Dialog("Login").WinEdit("wdtPassword:").Set "mercury"
Dialog("Login").WinButton("btnOK").Click

The above script is not a recorded script but is written. So, follow the below steps to create the script.

SystemUtil.Run is a command used to open any application that is installed on the Operating System (Desktop)

Syntax:

SystemUtil.Run "file name", "directory of the application", "mode"

Directory and mode are optional

Next,

Type the “Dialog(“ then we can see the names of the dialog available in the object repository. Since here there is only one dialog, we will get only “Login”. Just select the Login and then type “.” that shows a list of objects available. Select WinEdit from the list.  Then again, open the bracket that shows list of available edit boxes. Select wdtAgentName and then again type “.”.  This shows list of methods available to be performed on this object. Select “Set” and provide the parameter admin inside the double quotes.

This procedure should be followed to the second and third lines also.  For the first time, this looks very tedious but after getting used to this, becomes very easy.

CreatingScript1

CreatingScript2

CreatingScript3

Repeat this process for other two lines also. I hope this explains well the process of creating a local object repository, adding objects, and using the same to create a test script.

We will discuss creation, addition of objects, and usage of Shared Object Repository in the next post.

Note:

  • Local / Per-Action OR is specific to a particular test / action.
  • Local Object Repository cannot be reused across all the tests in the automation suite.
  • This is the default object repository

{ 8 comments… read them below or add one }

Arun Prasad December 26, 2011 at 11:30 am

Hi Seetharam,

Hoep u r doing good!!
Great Job Seetharam.

Explanation and examples are really simple and easy to understand.
Anyone new to the Topic can easily make out.

Keep rocking with new topics.

Thanks,

Arun Prasad

Reply

sneha May 22, 2012 at 2:11 pm

this is what i wanted 🙂 🙂 so happy………..

Excellent work !!!

Reply

seetaram May 25, 2012 at 3:12 pm

thanks Sneha…

Reply

veera April 9, 2013 at 2:20 pm

Please share the path of the local repository also, so that we will get good expo on the same.

Reply

sharath October 15, 2013 at 2:16 am

Thanq sitaram… great work.. i can say that this the best guide for freshers… The way you explianed was really simple and eazy to understand…

Reply

Keyur Makwana November 7, 2013 at 6:50 am

Really a very good stuff. It’s my first sample application in a QTP and I learnt a lot from your blog. Keep it up

Reply

seetaram November 7, 2013 at 7:48 am

Thanks Keyur

Reply

Jagseer Singh July 5, 2016 at 1:59 pm

Super Explanation.

very informative in easy manner 🙂

Keep it up..

Thanks for sharing all UFT topics..

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