QTP10.com is a new and completely free website that offers help in all the versions of HP QTP (including latest version 10). More importantly, it offers free code for users of HP QuickTest Professioal. This site helps you in learning the basics of QTP and descriptive/advanced programming in (QTP) on various environments like - .Net, Infragistics, Web, Windows, etc.

Note -
This blog is NOT affiliated with HP / Hewlett-Packard in any way. The data/questions come from various sources and we have our own testing questions. I am just another Software Tester like you.

QTP Object Repository automation object model

Share This Post -

Sponsored Links:

Manipulate QTP Object Repositories Using the Object Repository Automation Objects and Methods.
Download the code sample (PDF Version).

Download the code sample (Text file Version).

The QTP Repository automation object model enables you to manipulate QTP shared object repositories and their contents from outside of QTP. The automation object model enables you to use a scripting tool to access QTP shared object repositories via automation.

Automation programs are especially useful for performing the same tasks multiple times or on multiple shared object repositories. You can write your automation programs in any language and development environment that supports automation. For example, you can use VBScript, JavaScript, Visual Basic, Visual C++, or Visual Studio.NET.

Just as you use the QTP object model to automate your QTP operations, you can use the objects and methods of the Object Repository automation object model to write programs that manipulate shared object repositories, instead of performing these operations manually using the Object Repository Manager. For example, you can add, remove, and rename objects; import from and export to XML; retrieve and copy objects; and so forth.

After you have retrieved an object, you can manipulate it using the methods and properties available for that test object class. For example, you can use the GetTOProperty or SetTOProperty methods to retrieve and modify its properties.

Note: You can use the Object Repository automation object model to manipulate shared object repositories saved in the file system. If you want to manipulate a shared object repository stored in Quality Center, you must download the shared object repository and save it to the file system, before using the Object Repository automation object model to manipulate it.

ObjectRepositoryUtil Object

Description: ObjectRepositoryUtil Object enables you to manipulate object repository files (shared and local) from outside of QTP.

Methods:
AddObject
- Adds the specified object to the object repository under the specified parent object.
You can use this method to add a copy of an object that you retrieved from a different object repository.

Tip: Before adding an object to the object repository, you can modify its description properties using the SetTOProperty method.

Syntax: object.AddObject (Object, Parent, [Name])


Convert
- Converts the specified object repository file (version 8.2.1 or earlier) to the current format.

You must convert object repository files from QuickTest Professional 8.2.1 or earlier to the current format before you can use them in QuickTest Professional 9.0 or later.

Note: You do not need to use the Load method to load the object repository before converting it.

Syntax: object.Convert (OldFile, NewFile)


CopyObject
- Creates a copy of the specified object in the object repository.
To copy an object from one object repository to another, first create a copy of the object using this method. Then load another object repository, and use the AddObject method to add the returned (copied) object to the other repository.

Syntax: object.CopyObject (Object)

ExportToXML
- Exports the specified object repository to the specified XML file.
- Only test objects are exported to the XML file. If your object repository contains checkpoint or output objects, they are not exported to the XML file.
- This method can be used only to export shared object repositories (*.tsr files). Local object repositories cannot be exported.
- The object repository you want to export must be in QuickTest version 9.0 or later format. If the object repository is in an earlier format, you can use the Convert method to convert it before exporting it.

Syntax: object.ExportToXML (SourceFile, TargetFile)


GetAllObjects
- Retrieves all objects under the specified parent object.
You can use this method to enumerate the objects in an object repository and retrieve a collection of objects, even if you do not have any information about any of the objects in the object repository.

Syntax: object.GetAllObjects ([Parent])

GetAllObjectsBy
- Class Retrieves all objects of the specified class under the specified parent object.
You can use this method to enumerate the objects in an object repository and retrieve a collection of objects, even if you do not have any information about any of the objects in the object repository.

Syntax: object.GetAllObjectsByClass (Class, [Parent])


GetChildren
- Retrieves all direct children of the specified parent object.
You can use this method to enumerate the objects in an object repository and retrieve a collection of objects, even if you do not have any information about any of the objects in the object repository.

Syntax: object.GetChildren ([Parent])

GetChildrenByClass
- Retrieves all direct children of the specified class under a specified parent.
You can use this method to enumerate the objects in an object repository and retrieve a collection of objects, even if you do not have any information about any of the objects in the object repository.

Syntax: object.GetChildrenByClass (Class, [Parent])


GetLogicalName
- Retrieves the name of the specified object.
Retrieves the name of the specified object.

Syntax: object.GetLogicalName (Object)

GetObject
- Retrieves the object according to the specified path.
This method is similar to the GetObjectByParent method, but it enables you to supply the entire object path (including the parent object information) as a string. This is useful when you do not have access to an object containing the parent.

If you do have access to the parent as an object (rather than a string), it is recommended to use the GetObjectByParent method for better performance.

Syntax: object.GetObject (ObjectPath)


GetObjectByParent
- Retrieves the object according to the specified parent object and object name.
This method is similar to the GetObject method, but enables you to supply an object for the parent argument (if available) rather than a string.

Supplying an object results in better performance.

Syntax: object.GetObjectByParent (Parent, Object)


ImportFromXML
- Imports the specified XML file to the specified object repository.
This method can be used only to import XML files into new shared object repositories (*.tsr files). It cannot be used with local object repositories.
Object repository XML files contain only test objects. They do not contain checkpoint or output objects.

Syntax: object.ImportFromXML (SourceFile, TargetFile)


Load
- Loads the specified object repository file.
You must load an object repository file before performing any other object repository automation steps.
All object repository automation steps in your script that follow a load statement, perform the operations on the loaded object repository file.
If your script contains more than one Load statement on the same RepositoryUtil object, the second Load statement effectively unloads the first repository.

To load more than one repository at once, create multiple RepositoryUtil objects and load the repositories using different objects.


Syntax: object.Load FileName

RemoveObject
- Removes the specified object from the object repository.
You can remove objects from an object repository if they are no longer needed. Removing unnecessary objects helps to simplify maintenance and improves object repository performance.

Syntax: object.RemoveObject Parent, Object

RenameObject
- Renames the specified object in the object repository.
You can rename an object to provide a more descriptive name, which makes it easier to read your test or component steps.

Syntax: object.RenameObject (Object, Name)


Save
- Saves any changes made while running an object repository automation script.
Saves any changes made while running an object repository automation script.

Syntax: object.Save


UpdateObject
- Updates the object repository with any changes made to the specified object.
You should call this method after any object change (for example, rename, copy, and so forth).

Syntax: object.UpdateObject Object

TOCollection Object
A collection of object repository objects, returned by methods of the ObjectRepositoryUtil object.

Example: Manipulate Object Repositories Using the Object Repository Automation Objects and Methods.
The following example retrieves an object repository's objects and properties, looks for specific test objects using several methods, and copies a test object to another object repository.

Download the code sample (PDF Version).

Download the code sample (Text file Version).