Source: http://automated-360.com/qtp/advanced-concepts/all-about-object-models-in-qtp-uft/
All About Object Models in QTP / UFT
An Object Model is basically the way we use the object properties in a Programming language or technology. When we say usage of object properties, it means accessing the objects by object references to achieve the objectives like invoking a particular method of object. For example, object model of MS Excel, which enables other program to control it via different methods and properties.
A collection of objects or classes through which a program can examine and manipulate some specific parts of its world. In other words, the object-oriented interface to some service or system. Such an interface is said to be the object model of the represented service or system.
In this post we will discuss about the four different types of Object Models
- Test Object Model ( TOM )
- Document Object Model ( DOM )
- Component Object Model ( COM )
- Automation Object Model ( AOM )
Test Object Model ( TOM )
A collection of object types or classes which represents the different objects in the application. For Example a button object or edit box object in an application are the objects of and represent Button class or Edit box class. These test object class has a several properties to uniquely identify the objects of the particular class and methods to perform specific actions.
There are two types of objects in TOM,
- Test Object and
- Run-time object.
for example, a button with one of the properties “enable” is “true” in the object repository, which can be enable/disable at run time depending on certain conditions.
with this we can understand that the test object properties does not require your application to open and can be modified whereas a run-time object property requires the application to be open and it cannot be modified.
If you have ever wondered about the RO in GetROProperty and TO in SetTOProperty, now you know that RO is for Run-time Object and so GetROProperty is used to retrieve the value of the object at run time. TO is for Test Object and so the value of an object in object repository can be modified using SetTOProperty.
Document Object Model ( DOM )
Web Pages are organized into different objects like document, tables etc using the properties and methods available for the objects. These objects can be accessed by using scripts for the web pages. The Document Object Model is an interface(API) which allow programs and scripts to access and update the content, structure and style of documents. This is not only applicable for web pages (HTML) but for XML as well.
The objects in the document are in a hierarchy. DOM helps QTP to access this hierarchy of a web page directly by scripting. To access the DOM we use “.object” method for the specific web object.
For example, you can use DOM to identify an object when QTP is not able to identify an object. Consider the part of page source below for Google search page.
If you need to click on the Google Search button using DOM, you will have to look into the source. For the button there are certain properties like id, name etc, you can find in the source above. These properties can be used to identify the object and do the action. If we take the Name property, this can be used by GetElementsbyName method as below
GetElementById Method – returns a list of objects with specified id. If the id for the objects are not unique it take the first object with the specified value of the ID attribute.
ElementFromPoint Method – returns the object at specific coordinate on the page. for example the below code finds the search text box as per x and y coordinate and sets the value.
Some useful Properties which can be used for different purposes
activeElement – Retrieves the object that has the focus when the parent document has focus. Get the name of the text box which has the focus during runtime
cookie – Sets or retrieves the string value of a cookie. Find more details on Cookie here
documentElement - Retrieves the root node of the document.
readyState - Retrieves a value that indicates the current state of the object. This property can be used for sync in QTP scripts.
Component Object Model ( COM )
It is used to enable interprocess communication and dynamic object creation in a large range of programming languages. COM is the basis for several other Microsoft technologies and frameworks, including OLE, OLE Automation, ActiveX, COM+, DCOM, the Windows shell, DirectX, and Windows Runtime.COM is basically used by developers to make the things simpler and easier to build and link by creating reusable components. The objects can be accessed by the interface (properties and methods) provided by COM for a particular class. Basically the properties and methods of an object can be the interface of the object and accessed by taking the reference of the object.
COM objects can be used with any tool that supports COM automation. And since VBScript supports COM automation, It becomes very easy to use in QTP scripting. But we cannot use all the COM objects, we can use only those objects that expose a string called a programmatic identifier (ProgID). Although not all COM objects have a ProgID, all COM objects have a 128-bit number called a class identifier, or CLSID. If a COM object has a ProgID, you can use VBScript to instantiate the object, invoke its methods and properties, and destroy the object.
To use a COM object in a script, you must first create an instance of the object. You can do this by calling the CreateObject or GetObject method.
Automation Object Model ( AOM )
An Object Model is a structural representation of objects that comprise the implementation of a system or application. Automation enables software packages to expose their unique features to scripting tools and other applications. Usually Automation uses the Component Object Model (COM). A critical aspect of COM is, how client and servers interact. A COM server is any object that provides services to clients; these services are in the form of COM interface implementations like Properties, Methods, Events and their relationships. Which can be called by any client that is able to get a pointer to one of the interfaces on the server object.
QuickTest Professional is also a COM Server and its different methods and properties are exposed by its COM interface which can be accessed by other applications and scripting tools to control it from outside. In this post, we will see how to interact with QTP from outside via Automation Object Model.
Find more detail in the post Automation Object Model : QuickTest Professional by Anurag . It is same for UFT as well without any changes. Below code snippet illustrates the launch of UFT.
No comments:
Post a Comment