Object Repository in UFT
The post will cover the following topics Details of Object Repository in UFT, Details of Object Repository in QTP, add object repository in QTP,add object repository in uft, what is object repository in UFT explain, what is object repository in UFT explain, object repository in UFT with examples, object repository in UFT with examples, Object Repository in UFT,Object Repository in QTP. Apart from these you will also able to learn how to work export object repository to Excel and Automatic Object model to handle Object Repository.
Object Repository:
It is a storage place of UFT or QTP where we can store the objects information those are required for testing and it also acts as the interface between the test script and the AUT to identify the objects during execution.
So Object repository is a collection of objects and their properties. As it acts as an interface, with these properties QTP/UFT will be able to be to identify the objects and work on them. Similarly, if UFT/QTP cannot identify the objects, it will not be able to work on these objects.
In a simple term, an object is a graphic user element in an application and object repository is a graphical representation of the objects.
Object:
The object is something, which has structure and properties. Mostly this concept is based on OOPs hierarchy of Objects.It consists of data that describes the object [properties] and Functions that can be performed on that object[methods].
In OOPs an object is an instance of a class and in QTP or UFT, the objects are defined by the class. Like a go button in web, context is an instance of a web button.
Software objects:
We call windows, WebPages, buttons, edit boxes, check boxes, etc.. as software objects.
Types of Object in QTP:
There are four types of object available in QTP.
- Run time objects
- Test objects
- Utility objects
- Automation objects/User-defined objects.
Run time objects:
During execution, the actual objects are called Runtime objects. The runtime objects are not present in the object repository. The objects present in the AUT. Ex: Buttons, links, etc…This is another important thing to learn on object repository in UFT with examples.
Test Objects:
Test objects are the replica of the actual objects(or controls) fetched from the application under test. It can be said test objects are references of Run time objects. They are UFT/QTP’s representation of the objects. This is another important thing to learn on object repository in UFT with examples.
Ex: WinEdit, WinButton, WebButton, Link, etc.
Note:
Test objects names vary from one environment to another.
Ex:
Run time objects | Test objects in Windows Environment | Test objects in VB Environment |
Test objects in web Environment |
buttons | WinButton | VBButton | WebButton |
Edit box | WinEdit | VBEdit | WebEdit |
Checkbox | Wincheckbox | Vbcheckbox | Webcheckbox |
Utility objects
They are QTP/UFT reserved objects used for testing and result reporting. This is another important thing to learn on object repository in UFT with examples.
Ex:
- SystemUtil for launching/closing the application.
- The reporter for defining results.
- Services for inserting transaction points
- Environment for using environment variables
Automation objects/User-defined objects
User can create objects; those can be used for performing specific operations. Ex: Creating objects in file system object class, adodb.connection class, dictionary object class, excel. Application class etc. This is another important thing to learn on object repository in UFT with examples.
More on User-defined Object:
If UFT/QTP refuses to recognize an object from the application(maybe standard classes does not support the object), UFT/QTP, in that case, will recognize the object as WinObject.
It is different than the common convention that you need to open UFT/QTP first then the application, otherwise, UFT/QTP will not be able to recognize the general objects and they will be identified as WinObjects.
The second reason why you may go to user-defined objects is that we want UFT/QTP to work an object just like another object. Like if we want to use combo box as button or link or any other control.
Navigation to create user-defined objects in UFT/QTP
- Click on Tool.
- Click on Object Identification.
- Object Identification window activates.
- Select Environment as a standard window.
- Click on User-defined.
- Let the object mapping window open.
- Click on the class name or use hand symbol to identify the object.
- Click on the Map to drop-down to select any other control.
- Click on add to create one more or click on OK to close the Object Mapping
This is how you create user-defined objects in UFT/QTP.
In general, there are two types of repository available in QTP/UFT
- Local repository (.MTR extension-Module Test Repository )
- Shared repository(.TSR extension- Test Shared Repository)
Local Repository:
For each action based test, the UFT will create and manage the individual repository. It is good when the test is small. It is local to test action. It is automatically saved in a test whenever we record a test. It resides in the bdb folder in action subfolder.File extension is .mtr(modular test repository). As this is local to any action, it can not be used for any other action or test. By default, QTP/UFT saves its objects to the local repository. This is another important thing to learn on object repository in UFT with examples.
How to locate the Local Object Repository?
- Open any test
- Navigate to Resource
- Click on Object Repository(Shortcut Ctrl+R)
Locate local Object repository - QTP/UFT creates a Local Repository for every action automatically during Recording. That cannot be shared among tests.
- User can add some more objects to Local repository
- User can perform rename, delete operations in the local repository. As it is QTP/UFT’s internal file, the user no need to save modifications. In other words, it is auto-saved.
- User can have multiple shared object repositories along with local object repository.
- You can export the local object repository to the shared object repository.
In case if your test has shared object repository and local object repository attached to it, If you add a child object to local object repository and the parent of that object stays in the shared object repository, UFT/QTP will automatically move the parent to the local object repository.
Export OR to XML If you add the same object from your application to two different actions, UFT will treat them differently as each action has its local repository.
Components of Local object Repository
If you open the Local object Repository, the first thing you notice the action drop down. As the local object repository is a private property of an action, you have to select an action to catch hold of the respective object repository.
Once you have selected the Action, you will get the test object tree. The lowest element of the tree is often referred to as an object. In general, every node of the tree is an object. Once you click on any node, you will get the object properties in the right-hand side.
The Object details pane will have:
- Name- Object Identifier- Name of the object
- ClassName- Object Class name coming from add-ins or UFT/QTPs class selection mechanism. This field is not editable.
- Repository- Local- The location of the Object Repository. This field is not editable too. It just tells where the object is in the repository.
Now the lower pane shows the Object details:
Description Properties:
Each object comes with mandatory properties and assistive properties. By default UFT/QTP provides some properties here, but we can customize this as per our need.
- NativeClass-Edit
- Attached Text- The attached text retrieved from the application.
Visual Identifier- You can use it to enhance the object identification. That may reduce the chance to wrong object identification. This can be used to identify the object relative to other nearby objects.
- Visual relation Identifier- Visual Identifier or visual relation identifier settings
- Ordinal Identifier- Ordinal Identifier if any- mostly Type and value
- Additional details- Enable smart identification
- Comment
Advantage of local object repository:
- It is not an overhead.
- Very Fast.
- Object conflict will not occur.
- Objects can be edited from the repository only
The drawback of local object repository:
- Difficult to maintain
- The duplicate entry of Objects to a repository is possible.
How to add objects to the local repository?
You can record while interacting with the application, UFT/QTP will automatically add objects to the Object Repository. You can also add objects manually to the Object Repository.
How to Navigate:
- Click Resource
- Click on Object Repository
- Click on Objects
- Click on Add objects to Local
- Show the object
- Click ok
OR Filter to add object You may also get three options to filter from
- Only selected object(adds the selected object)
- Selected Object and it’s all its direct children
- Selected Object and all its descendants
How to add Objects repositories to an action?
if we miss to add object during recording time but we need that we can add objects using add object feature. We can also work with object spy to identify the required object.
How to rename the object in the local object repository?
We can rename the object in the object repository. Navigation will be as below:
- Click on Resources
- Click on Object repository
- Select the object which you want to rename
- Right-click on that object
- Rename
- Type the correct name
- Select some other object
It will automatically rename the previous object.
Object Repository view Local How to delete objects from Object repository?
We can delete the object in the object repository. Navigation will be as below:
- Click on Resources
- Click on Object repository
- Select the object which you want to delete
- Right-click on that object
- Click delete
- Click on confirm delete option
- Close repository.
Shared Object Repository
It’s central storage where the object information associated with multiple tests can be stored. So a Shared object repository is shared resource among multiple actions. After creating the repository we should associate that repository to your action and then perform Testing. This is another important thing to learn on object repository in UFT with examples.
Object Repository Manager can be used for this. The file extension is .tsr (Test shared repository). When we associate a shared object repository, we make the test asset available to the local action.
Export Local object to Shared Object User (Test Engineer) creates a shared repository by adding objects. That can be shared among the number of tests. Using this method user can perform modifications on objects easily Navigation:
- Go to Resource
- Go to the Object repository manager
- Select Object
- Click on Add Objects
- Show the window/objects
- Click ok or File->Save
- The selected object only-It stores only one object
- Default object types-It stores all default objects
- All objects types-All default objects with static objects
- Selected object types-It stores objects along with Object class. in this case, we can add more class.
Step-1&2
Locate shared Object repository Step-3
Add Objects to Shared Object Repository Step-6 Save a Shared Object Repository
Save Shared Object repository Notes on Shared Object Repository:
- You can not add an object to the shared object repository if the object is already present.
- You can not add a checkpoint to the shared object repository.
- You can certainly export the shared object repository to an XML file or Excel file.
- You can merge one shared object repository to other shared object repository. This will create a 3rd object repository containing elements of both shared objects repositories contents.
- You can add multiple test objects by enabling the option to Navigate and Learn.
- You can not add output values to the shared object repository.
- You will get a question mark if you have not installed properly add-ins in your machine. This also happens if the proper environment is not installed on your machine.
Advantage of shared object repository:
- Easy to update hence easy to maintain.
- Consumes less memory as we can avoid multiple copies of the same object.
- Highly reusable.
The disadvantage of shared object repository
- Object repository size will be huge
- Execution will be slow if the shared object repository is too big.
- Object conflict needs to be handled properly.
- Many test engineers may use shared object repository, hence it is very tough to edit concurrently.
- any change in the shared object repositories will affect the associated test case.
- In case of property identification, if UFT/QTP does not get a proper match, it will activate smart identification that may also slow down the execution.
When to use the Shared Object Repository?
When we know that the application is not stable and may change it’s object or object properties frequently (and we do not want to use descriptive programming),it makes sense to use shared object repository. We need to change in one place and that can reflect in all other test dependant on the same shared object repository.
How to make shared Object repository editable?
This is another important thing to learn on object repository in UFT with examples.
We have to open Object Repository Manager- another tool which enables us to make shared object repository editable.
- Click on Resource
- Go to the Object repository manager
- Click on File
- Click on Open
- Click on the browse button to browse path of the repository file
- Select file
- Enable editing
How to rename the object in the shared object repository?
- Click on Resource
- Go to the Object repository manager
- Click on File
- Click on Open
- Click on the browse button to browse path of the repository file
- Select file
- Enable editing
- Select object
- Right-click on the object
- Choose rename
- Change the name
- Click on the other object
- The last object name automatically changed
- Save the file
- Close repository manager
Enable editing for shared object How to delete the object in the shared object repository?
- Click on Resource
- Go to the Object repository manager
- Click on File
- Click on Open
- Click on the browse button to browse path of the repository file
- Select file
- Enable editing
- Select object
- Right-click on the object
- Choose delete
- Confirm deletion
- Save the file
- Close repository manager.
Options after Enabling Shared repository Priority Logic for repository selection
This is another important thing to learn on object repository in UFT with examples.
In case one local object repository and one shared object repository has the same object
In case an object is mentioned in the Local object repository and shared object repository, during execution the corresponding action will give priority to Local object repository and pick up values from there to identify the object.
In case two shared object repositories have the same object
In this case, it depends on the sequence of association. In case the first repository is associated before the second one, the action will consider the first one. Just in case the first object repository is associated after the second object repository, the action will pick up the second one.
Can we change Local object repository to shared object repository or vice versa?
Yes, we can!!. we can switch between local object repository or shared object repository at any given point of time. The navigation is Test->Settings->Resources
Here we have to choose as per our need. This is called switching of the repository.
When to use a Shared Object repository?
In case we are in a large project and many test engineers are working on different functionalities but use the same object, in that case, it is good to use Shared Object Repository. This is another important thing to learn on object repository in UFT with examples.
How to associate the shared object repository to the UFT/QTP test?
We can associate the shared object repository in three different ways:
Associate Shared Object Repository to test Select the Shared Repository to Associate Step-1 Using code:
This is the most favourite and convenient way to associate object repository to a test. The code is as follows:
repositoriesColleaction.add "path&repositoryName"
Step-2 Using Action Property
- Go to Expert view
- Right-click on Expert view of UFT/QTP editor
- Select Action
- Click on Action properties
- Click on Associate Repository
- Click on Add
- Provide path and identify the repository(You can also use the browse button to do the same)
- Click on Open
- Click on OK
Step-3 Using Associate repository
- Click on Resource
- Click on Associate Repository
- Click on Add
- Provide path and identify the repository(You can also use the browse button to do the same)
- Click on Open
- Associate with the target Action
- Click on OK
What is the difference between Local object repository and a shared Object repository?
This is another important thing to learn on object repository in UFT with examples.
Local Object Repository Shared Object Repository Local object repository is associated by default to an action we create. We have to explicitly associate a shared object repository
to one or more actions.Local object repositories are locally editable. Shared Object repositories are by default read-only. We have
to edit shared object repository by Object Repository ManagerNobody except the action owner can edit Local object repository. Shared object repository can be edited by anybody. Extension of local object repository is .mtr and stored in a .bdb file Extension of the shared Object repository is .tsr Local Object Repository is useful when a few tests are working on a screen. Shared Object repository is useful when multiple tests are using a particular screen. Renaming the Object in Local object repository does not affect any other script. Renaming the Object in Shared object repository may have serious failures in other scripts Changes to Local object repository are local hence all scripts need to be changed in case object changes. Changes to Shared object repository are global hence changes reflect in all scripts. Mostly no risk associated while working on Local object repository. The shared object repository may grow big and regular backup is required in
order to avoid corruption to the file.What are the advantages and disadvantages of having an Object Repository?
This is another important thing to learn on object repository in UFT with examples.
The advantages of having an Object Repository
- Sync with GUI front end of the application.
- Highlight capability makes easier to Crosscheck.
- During it is very easy to identify which object gets changed.
- If it stores with the logical name of the object, it is extremely easy to maintain the OR file.
- Scripts are untouched if the object property gets changed. we need to check the OR file that’s it!!
- Modern scripting tools allow modifying the OR file separately.
The disadvantages of having an Object Repository
- you need to check out the file size.
- Object conflict may occur when adding individual OR files.
- Sometimes extra objects get added and it makes the OR file heavy in size.
- The OR files are private to the scripts. So concurrent update to the file is not possible
- It became overhead while developing large projects.
- Even though I like to use OR..but I cannot say descriptive programming is not required. Can you???
- There are many things which can not be recorded. like-Sub Menu, Objects changing its position
How objects are stored in UFT or QTP?
It is a collection of objects stored in the XML file. Objects will have their properties by which QTP/UFT will identify the objects uniquely. During recording, this entry to this file is automatically done by QTP /UFT. This is another important thing to learn on object repository in UFT with examples.
Object Repository is a place for scripts to store information/properties about objects. Object repository is maintained in XML format. It is the place where UFT stores all information what it learned during the recording phase. It contains
- name
- set of identifiers
- object description
This information can be dependent on how UFT is going to recognize an object uniquely. They may differ from instance to instance, objects to objects.
Object repository is a tree view that shows the components in the current action, test or script.
It enables us to view or modify the test objects or add a new one.
The values populated here the default properties. UFT internally verifies and determines the classification of the object class. If the default properties are not enough to identify the object uniquely, UFT keeps adding other supportive properties like assistive properties or special identifiers(ordinal) to accomplish the goal.
The entry will have a logical name about the object and physical description about the object in the right side pane. We can perform several operations:
- Rename the logical name.
- Moving objects from one hierarchy to others
- Change the object description
- Delete object
- Highlight selected object
- Locating an object
- Update physical description
- Filtering object etc.
Overview:
Most of the objects, we encounter day by day, may have few or may have many properties. For better understanding let us sat properties as attributes.But when it comes for recognizing objects via QTP/UFT.Qtp recognizes object using 2 0r 3 important properties.
Before UFT understands the object, It has a mechanism to set the context.Context is nothing but to help UFT to identify the application under test. We set this context via Add-ins. Add-ins give UFT the correct files to be loaded to identify the objects properly.
Qtp has default object identification configuration for every environment, if we feel that configuration is not sufficient for recognizing objects in our application, we can configure some moreObject Identification Types
a) Normal identification1) Mandatory properties
2) Assistive propertiesb) Smart identification
1) base filter properties
2) optional filter propertiesc) Ordinal identifier
1) location
2) index
3) creation time(only for browser)QTP learns information in the following in case of normal identification:
First of all the UFT learns all the mandatory properties at a time and tries to identify the object, with these properties uniquely.If it feels sufficient then it stops learning.If otherwise, it learns first assistive property and once again stops and tries to identify the object.like this UFT learns all required properties one by one. If the list of properties is enough to identify an object uniquely.It just stops.Now there might be the situation, where, with all the assistive properties, UFT is not able to identify an object uniquely. Then UFT goes to Ordinal Identifier.
UFT learns information in the following in case of Smart Identification:
Smart identification is an optional feature if we feel normal identification is not sufficient for any object, and then we configure Smart Identification for that object, to avoid Ordinal Identifier.
After normal identification, if uft feels not satisfied then it goes to smart identification. in smart identification 2 types of properties available, the first uft learns all base filter properties at a time and tries to identify the object uniquely. If it feels sufficient, then it stops learning otherwise it goes to Optional Filter Properties and learns one by one. Still, it feels not satisfied finally it goes to Ordinal Identifier.Ordinal identifiers:
There are 3 types of ordinal identifiers available
1) Location: is based on object location in the AUT, location starts from zero, Zero(x,y coordinate)
2) index: it is based on the sequence of the programs, the index starts from zero
3) Creation time: it is based on the loading time of the web objects. UFT generates 0,1,2 like numbers.Tool Settings Globalization:
As QTP is an I-tier(Stand-alone) application, making Tool settings globally is not possible.
For making tool settings global, QTP is providing a special feature called “Generate Script”.STEPS:
1) Settings are available in 3 areas.
a) File->Settings
b) Tools->Options
c) Tools->Object Identification2) Perform required settings and generate Scripts
3) Share Script files to team members and ask them to execute those scripts.What are the advantages of XML format export option?
You can modify the object properties without opening UFT/QTP tool. Your favourite XML editor can open the object repository and enable you to change the objects.
How Object repository can affect execution performance?
There are several approaches in the market to generate your script and the framework implementation. But we need to think a manner where script development time, script maintenance time becomes less. Most importantly we need to find an approach where the execution time also becomes less. This is another important thing to learn on object repository in UFT with examples.
What is the importance of downing the execution time?
Well, I am inspired by a philosophy that automation test engineers should not lose time by executing the test script. All the test script should be configured once and should be able to run unmanned manner.
Moreover, these scripts will run in a computer-assisted environment. The computer is not that intelligent as we are. If you insert enough intelligence into the script it might slow down the process and on the other side intelligence is less.
There is a chance that the script will error out. So what are the best approaches to automate your script that will serve long without issue is a question?
Object repository is a place where your testing tool uses to store information about objects under test for flow. This may be the .tsr file or a straight XML file. During the run, time script takes reference to this file and identify the objects.
It is seen if the OR size is less that means test engineers are doing more descriptive programming. Descriptive programming is very powerful but it is a time-consuming process. Hence it will slow down the process.
On the other hand, if the OR file is big. The seek time will be high. There might be a scenario where object conflict will occur. This also slows down the process.
Here this picture shows if OR files grow high in Size how the response time of the scripts increases.
As per experience, An O.R file should be between 5 to 12 MB..Above that or below that performance is not as good as we expected to be.
How to Load Object Repository Dynamically in QTP/UFT?
When automation test engineers design a framework, always the target to run the script uninterruptedly. Even if entry-level record and framework need an uninterrupted run!!! So for uninterrupted flow execution, one important aspect is to choose and execute a set of predefined scripts. Sounds good!!! This is another important thing to learn on object repository in UFT with examples.
Automation test engineers tried a lot and succeed by using excel or data loading logic. Yes…the power of automation viz coding logic. Excel was having several columns along with an executable column.
Where automation test engineers use to mentioned like yes or no. Based on that value the framework uses to use to pick the correct row to execute which intern calls correct subscripts to run.
One more sophisticated way to run through batch execution. More can be found here…
With this approach their ware flaws.
1. It was not dynamic enough.
2. It was very slow as the framework used to load all the object repositories at a time or used to load a shared object repository.
3. The execution was frequently struck by object identification errors.In this article, I want to venture how an automation engineer team has overcome these problems.
Well, after analysis, automation engineers saw that if we can control the Object repository and supply the same as and when required basis to the framework, we will be able to solve the huge shared object repository.
This is kind of divide and conquers rule!!!.From this concept, automation test engineers came up with the incorporation of dynamic object repository loading concept.
Let us look into the code…Here is a small function or a method that will load the Object Repository Dynamically.Function Load_OR(sPath) '/This is the path where the OR is situated. 'msgbox sPath Set objnew = CreateObject("QuickTest.Application") objnew.Test.Settings.Resources.ObjectRepositoryPath =sPath Set objnew= Nothing End Function
This function is written in QTP 8.2.Don’t Know if it can be used in QTP 9 and aboveboard the same but another technique is given below……The interesting point is the here the path is also dynamic.
Public Sub proAddRepository(ByVal strRepName) Dim App Dim qtRepositories Set App = CreateObject("QuickTest.Application") ' Create the Application object App.Launch ' Launch QuickTest App.Visible = True ' Set QuickTest to be visible Set qtRepositories = App.Test.Actions(Environment("ActionName")).ObjectRepositories 'If the repository cannot be found in the collection If qtRepositories.Find(strRepName) = -1 Then Wait(1) qtRepositories.Add strRepName, 1 End If Set qtRepositories = Nothing Set App = Nothing End Sub
Let’s see an example….
Dim qtApp 'As QuickTest.Application ' Declare the Application object variable Dim qtRepositories 'As QuickTest.ObjectRepositories ' Declare an action's object repositories collection variable Dim lngPosition ' Open QuickTest Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object Set qtRepositories = qtApp.Test.Actions("Login").ObjectRepositories ' Get the object repositories collection object of the "Login" action ' Add MainApp.tsr if it's not already in the collection repositorypath=InputBox("Enter the abosolute path along with the Repository name to attache") If qtRepositories.Find(repositorypath) = -1 Then ' If the repository cannot be found in the collection qtRepositories.Add repositorypath, 1 ' Add the repository to the collection End If ' Set the new object repository configuration as the default for all new actions qtRepositories.SetAsDefault ' Set object repositories associated with the "Login" action as the default for all new actions 'Save the test and close QuickTest qtApp.Test.Save ' Save the test qtApp.Quit ' Quit QuickTest Set qtRepositories = Nothing ' Release the action's shared repositories collection Set qtApp = Nothing ' Release the Application object
The code has placed the automation one step further. The framework has been improved.
Shared object repository concept has been removed forever!How to Convert the test shared repository to XML in AOM or VBScript?
Below is the code to convert the test shared repository to XML: This is another important thing to learn on object repository in UFT with examples.
Set myObj=CreateObject("Mercury.ObjectRepositoryUtil") myObj.ExportToXML([source of the .tsr file],[destination of the file]) like- myObj.ExportToXML "C:\test\demo.tsr","C:\test\demo.xml" set myObj=Nothing
Alternatively, you can export using the object repository Manager
Path:
Resources ->Object Repository Manager
File ->open to open the .tsr file
File ->Export to XMLThe above-written solution works fine from UFT/QTP but fails when we save this code as.VBS file with an Error code- “ActiveX component can’t create the object, Mercury.ObjectRepositoryUtil”
Error code-800A01AD
How to Resolve this?
- Open Command prompt
- type %System Root%\syswow64\csscript\[path of the script]
- Click enter
This works great!! But this only works if you have UFT installed on your machine. Just in case, you move your test script to another machine where the UFT is not present, the script will fail.
The exact issue has been listed in StackOverflow. User 2034602 has given a possible solution for this.
- Register RepositoryUtil.dll with REGSVR32
- Use CSSCRIPT.exe under syswow64 to run the script.
How to export a shared object repository to Excel?
In his blog post qtpsudhakar has shown a nice way to export object repository to excel. This is another important thing to learn on object repository in UFT with examples.
'############################################ 'Description : Exporting Object Repository to Excel 'What Concepts used : Object Repository Model, Excel Object Model 'Required Parameters: Object Repository, Excel Path (Creates Excel File) 'Required Software : QTP/UFT Installed 'Developed By : Sudhakar Kakunuri 'Modified By: Animesh '############################################ 'Declare Variables '************************************ Dim srcRepository Dim ParentObject Dim excel, workbooks, rIndex, objRange Dim ObjectRepositoryPath,orExcelPath '************************************ 'Specify file Paths '************************************ 'OR must be created before executing this 'You can use .TSR, .XML and .BDB Object Repositories 'An excel file will be created automatically with the name excel.xls ObjectRepositoryPath="C:\Test\OR\createrequest.tsr" orExcelPath="D:\excel.xls" '************************************ 'Load Object Repository '************************************ 'Creating Object Repository utility Object Set srcRepository = CreateObject("Mercury.ObjectRepositoryUtil") 'Load Object Repository srcRepository.Load ObjectRepositoryPath '************************************ 'Create Excel file with columns, colors and Autofit '************************************ 'Create Excel Object Set excel=createobject("excel.application") 'Add New Workbook Set workbooks=excel.Workbooks.Add() excel.Cells(1,1).value="ParentObjectLogicalName" excel.Cells(1,2).value="ParentObjectProperties" excel.Cells(1,3).value="ObjectLogicalName" excel.Cells(1,4).value="ObjectProperties" Set objRange = Excel.Range("A1:D1") objRange.Font.Bold = True objRange.Font.ColorIndex = 1 objRange.Interior.ColorIndex=15 ' rIndex variable used to enter values row by row rIndex=2 '************************************ 'fnExportORtoExcel will get objects and properties from OR '************************************ 'Calling a fnExportORtoExcel Function fnExportORtoExcel ParentObject '************************************ 'Auto Fit all other columns & save excel '************************************ 'Autofit all columns excel.Worksheets("Sheet1").UsedRange.Columns.AutoFit With excel.Worksheets("Sheet1").UsedRange.Borders .LineStyle = 1 .Color = vbblack .Weight = 2 End With 'Save Work Book workbooks.saveas orExcelPath,true 'Close Work Book workbooks.Close 'Quit from Excel Application excel.Quit '************************************ 'Release Variables '************************************ Set workbooks=Nothing Set excel=Nothing Set srcRepository=Nothing '************************************ msgbox "Exporting Completed. Open "&orExcelPath&" to view the Excel Object Repository" '************************************ Function fnExportORtoExcel(ParentObject) 'Get Objects by parent From loaded Repository 'If parent not specified all objects in OR will be captured Set fTOCollection = srcRepository.GetChildren(ParentObject) For RepObjIndex = 0 To fTOCollection.Count - 1 'Get object by index Set fTestObject = fTOCollection.Item(RepObjIndex) Props="" 'Check whether the object is having child objects If srcRepository.GetChildren (fTestObject).count<>0 then 'Get TO Properties List Set PropertiesColl=fTestObject.GetTOProperties For pIndex=0 to PropertiesColl.count-1 'Store properties in a variable with a comma delimiter Set ObjectProperty=PropertiesColl.Item(pIndex) Props=Props&","&ObjectProperty.name&":="&ObjectProperty.value Next If InStr(1,Props,",")=1 Then Props=Mid(Props,2) End If 'Write Logical name and Properties in Excel Sheet excel.Cells(rIndex,1).value=srcRepository.GetLogicalName(fTestObject) excel.Cells(rIndex,2).value=Props 'Color the cells based class name If InStr(LCase(Props),"micclass:=browser")<>0 Then Set objRange = Excel.Range("A"&rIndex&":B"&rIndex) objRange.Font.Bold = True objRange.Font.ColorIndex = 1 objRange.Interior.ColorIndex=36 ElseIf InStr(LCase(Props),"micclass:=page")<>0 Then Set objRange = Excel.Range("A"&rIndex&":B"&rIndex) objRange.Font.Bold = True objRange.Font.ColorIndex = 1 objRange.Interior.ColorIndex=35 ElseIf InStr(LCase(Props),"micclass:=frame")<>0 Then Set objRange = Excel.Range("A"&rIndex&":B"&rIndex) objRange.Font.Bold = True objRange.Font.ColorIndex = 1 objRange.Interior.ColorIndex=40 End If 'increase rIndex to enter data in next lines of excel rIndex=rIndex+1 'Calling Recursive Function fnExportORtoExcel fTestObject else 'This else block will execute when the object is not having any childs 'Get TO Properties List Set PropertiesColl=fTestObject.GetTOProperties For pIndex=0 to PropertiesColl.count-1 'Store properties in a variable with a comma delimiter Set ObjectProperty=PropertiesColl.item(pIndex) Props=Props&","&ObjectProperty.name&":="&ObjectProperty.value Next If InStr(1,Props,",")=1 Then Props=Mid(Props,2) End If 'Write Logical name and Properties in Excel Sheet excel.Cells(rIndex,3).value=srcRepository.GetLogicalName(fTestObject) excel.Cells(rIndex,4).value=Props 'increase rIndex to enter data in next lines of excel rIndex=rIndex+1 End if Next End Function '************************************
How to Insert Web Service Test Objects to the Object Repository?
In order to add web service objects, we need to enable web service to add in. Once the web service add-in is enabled, we can now add web service objects to the Object Repository.
Once we have successfully added web service objects, we will be able to access all its supported operations. These operations can be seen in the expert view (Intellisense or Step generator) in keyword view under the operations column.
Steps to insert Web service Test Object to the Object Repository
- Navigate to Repository toolbar button(Resource-> Object repository)
- Navigate to web service add object button.
- Specify the web service add object button.
- Specify the WSDL(if you want WSDL automatic screening and automatic object addition)
- Specify the service screen-selective service to create the test object.
How to compare two Object Repositories?
UFT/QTP provides object repository comparison tool to find out the difference between objects of two different repositories. This is another important topic to learn object repository in UFT with examples.
Steps to compare two object repositories:
- Go to Resource
- Click on Object Repository Manager
Object repository comparison tool -
- Click on Tool
- Click on Object Repository Comparison Tool
Object repository comparison tool Option -
- Once the comparison tool opens
- Provide the first file and second file along with the path(you can also choose to click on browse button to locate the object repository files)
Object repository comparison OR Options -
- Click on OK
- The tool will compare the objects and displays the result as an easy human-readable way.
Object repository comparison report - You can also use three filter properties.
The filter properties are as follows:
- Identical Objects
- Unique Objects
- Partial matched Objects
How to Merge two Object Repositories in UFT/QTP?
UFT/QTP provides another important tool to merge two repositories. The name of the tool is Object Repository Merge Tool
Steps to merge two repositories
- Go to Resource
- Click on Object Repository Manager
Object repository comparison tool - Click on Tools
- Click on Object Repository Merge Tool
Object Repository Merge Tool - Once the Merge Tool window opens provide the primary file and secondary file along with the path.(You can choose to click on the browse button to locate the files)
Object Repository Merge Tool-comparison box - Click on OK
- The tool will merge and provide the result in a human consumable way.
You can also use filter properties like
- Show all objects
- Show only conflicting objects
When you merge objects from two different sources(two different repositories), UFT/QTP will create a third repository containing all pieces of information. This will ensure the source repositories are unchanged and no unwanted data goes inside them.
How do we get conflict during Object Repository Merge?
While merging two object repositories, If UFT/QTP determines two objects with the same name and same test object class but their descriptions are different, UFT/QTP will highlight the object in the repository and declare it as conflict.
second possible cause is if two objects have the same name but different contents and they belong to different repositories.
The third possible cause is if two objects have different names and their properties are the same but they belong to two different repositories.
The last well-known cause of merge conflict if the two objects have the same name but few of their properties are also the same but not all. In that way, they look identical but actually, they are not.
If you get conflict, you need to manually resolve the conflicts.
Do not worry if you have to manually resolve it. UFT/QTP will also provide possible solutions for conflict resolution.
How to export local object repository to the shared object repository?
- Open object repository window. Select Action as Local Object repository is private to Action.
- Now Select-Object Repository
- Go to file
- Export local objects
- Select location
- Click on save
This will export the local object repository to the shared object repository.
Can we update the shared object repository from the local object repository?
There are the below ways to update the shared object repository from the local object repository:
Way-1- The best way
- Do not open any test.
- Open object repository manager
- Click on Tool
- Click on Update from the Local repository
- Choose the test, who’s Local object repository needs to be referenced.
- Update the selected object or update all.
- Click on Save
This will automatically pull all local objects to shared objects repository.
Way-2 By clearing the read-only checkbox
- Go to the Object Repository Manager.
- Clear the read-only checkbox- clear the lock
- Create a new test(A new local object repository will be attached to the test.)
- Associate a shared object repository into the test.
- Update the local object repository by adding new items to it or modifying properties of an existing item.
- This will enable you to update the shared object repository from the local object repository.
Export local objects vs export and replace vs local objects vs copy objects to local
If we choose to export local objects, the local objects are exported to the .tsr file. it is not associated with any test. So if any test is executing, it keep referencing to the old object repository.
If we choose to export and replace local objects, the newly created shared object repository(.tsr) file is associated with our test. The current object repository becomes out of order (in other words, it is deleted).
The only issue with this approach is that new enforced shared object repository can not be edited. Our current test starts referring the new shared object repository file(.tsr).
Copy Objects from shared repository to the local object repository lets us use the older repository file with updated contents from shared object repository.
While mapping repository parameters, what if you have more than one repository parameter with same name in different shared object repositories that are associated with the same test?
Before you map repository parameters, if you have more than one repository parameter with the same name in different shared object repositories that are associated with the same test, the repository parameter from the shared object repository with the highest priority is used. After you map the repository parameters, UFT/QTP uses the mapping you have defined. In addition, changing the priority or default values has no effect after the parameters are mapped.
Good read- What to do if UFT/QTP does not recognize the object?
Please visit this website to understand what should you do if UFT/QTP does not recognize the objects.
Is possible to write code without Object repository?
Yes, it is possible to write code without Object repository but in that case, you have provided the properties in the code itself for an object.
- Once the Merge Tool window opens provide the primary file and secondary file along with the path.(You can choose to click on the browse button to locate the files)
-
-
-