Wednesday, December 23, 2015

Object Modesl - TOM, DOM, COM, AOM




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
  1. Test Object Model ( TOM )
  2. Document Object Model ( DOM )
  3. Component Object Model ( COM )
  4. 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.
The objects which QuickTest creates and stores to represent the object in application, is a test object whereas a run-time object is the actual object in the application on which methods are performed during the run session, i.e the test object object properties are the properties as they are saved in the test object repository. Run time properties refers to the object properties as it appears in the application under test.
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.

the part of the source is for the two buttons at Google search page.

GoogleSearch_buttons

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

You can use GetElementsbyTagName to have all the button objects and then search for the required one as below

I am listing here some important properties and methods that you can use in QTP
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.

CreateObject creates an Automation object of the specified class. If the application is already running, it creates a new instance. Set statement creates the reference between the object variable and the object. once the work is done the object reference should be destroyed as below

You can also use GetObject method which returns a reference to an instance of an object. It can be used in two way with its parameters, the object’s pathname and the object’s ProgID.

or


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.

I hope you enjoyed reading about these object models and this will definitely help you in your automation. 

No comments:

Post a Comment