Component Object Model in UFT | DOM | TOM & BOM

An object model is a collection of objects or classes through which a program can look at and manipulate it to some extent. The objects can be accessed via object references. To invoke a method in an object, the object reference and method name are given, together with any arguments.

Component Object Model in UFT

The Component Object Model in UFT provides a standard way for applications (.exe files) or libraries(.dll files) to make their functionality available to any COM-compliant application or script. For example, consider Microsoft Word Application. You can open a Word document and write any text, create tables and chars, and do many other things. Now, what if you want to do all these tasks through code ( i.e. without manually opening Word document). This is the situation where you would need a Component Object Model in UFT.

To create a Component Object CreateObject method is used.

CreateObject Function: Creates and returns a reference to an ActiveX object.

Syntax is CreateObject(class,[servername])

Part Description
class Required; Variant ( String ). The application name and class of the object to create.
servername Optional; Variant ( String ). The name of the network server where the object will be created. If servername is an empty string (“”), the local machine is used.

The class argument uses the syntax appname.objecttype and has these parts:

Part Description
appname Required; Variant ( String ). The name of the application providing the object.
objecttype Required; Variant ( String ). The type or class of object to create.

Example – Component Object Model in UFT

Set ObjWord = CreateObject (“Word.Document”)

ObjWord.Content = “Hello”

ObjWord.SaveAs “Doc1.docx”


Set ObjWord = Nothing           

In this example appname is “Word” and objecttype is “Document”

COM Servers and COM Clients

  • Objects that make their functionality available through COM are known as COM Servers.
  • Application or scripts that make use if that functionality is referred to as COM clients.

For example, when you write a script that uses WORD, WORD is the COM server and your script is the COM CLIENT

COM Servers Implementation

COM servers can be implemented in one of two ways:

Out-of-process servers: Out-of-process servers are typically implemented in executable files and run in a different process than the script.

For example, when you start a script for creating a Word Object, an instance of Wscipt.exe begins to run. If you next instantiate a Microsoft Word object, you are then working with two processes, Wscipt.exe and Winword.exe

In-process servers: Libraries(.dll files) are known as in-process-servers because they run in the same process as the application or script that called them.

For example, when you call the FileSystemObject from within a script, no new process is created. This is because the FileSystemObject (which is found in the Scrunn.dll) is an in-process server and thus runs in the same process as the script.

In-process servers typically run faster than Out-of-process servers because the operating system does not have to cross boundaries (from the script process to the object process and then back) to access the object methods and properties.

Nothing Keyword: VBScript includes the Nothing keyword, which can be used to disassociate an object reference and an object. After an object variable is set to Nothing, the variable no longer maintains an object reference and thus can not be used to control the object.

Document Object Model in UFT

A Web Page consists of different objects(like textbox, images, web tables, forms, buttons, etc) is organized in a tree structure. The Document Object Model is an API that allows programs to access and update the content, structure, and style of documents.

These objects can be accessed by using scripts for web pages. The Document Object Model is an interface(API) that allows programs and scripts to access and update the content, structure, and style of documents. The DOM applies to HTML as well XML. The page source of a web page can be accessed by using .object notation.

component object model in uft

How To Access Document Object Model in UFT?

The following are the most common ways to access the Document Object Model (DOM) in UFT.

  •  .Object.all.tags(“tagname”)
  •  .Object.getElementsByTagName(“tagname”)
  •  .Object.getElementById(“html id”)
  •  .Object.getElementsByName(“name”)
  •  .Object.links
  •  .Object.images
Example 1: Consider the following HTML code
To set a value in the userName text box using .Object.all.tags, we can use the following code.

Example 2: To retrieve all hyperlinks in a page and click on a particular link using .Object.links

Example 3: Find all objects with input tags and set a text if the name property is userName using .Object.getElementsByTagName(“tagname”)

Test Object Model in UFT

A Test Object Model (TOM) is a collection of object types or classes used by UFT to represent the objects in a test application. For example, a textbox represents an object of text class.
Each test object class has several properties that can uniquely identify the objects of the particular class and a set of methods to perform specific actions.
The following are two types of objects in TOM
  • Test Object
  • Run-time object.
test object is an object that UFT stores in the Object repository to represent the actual object in a test application. Using SetTOProperty we can update the property of an object that is stored in the object repository.
run-time object is an actual object in the test application on which methods are performed during the run session.GetROProperty is used to retrieve the actual run time property of an object.

Browser Object Model in UFT

The Browser Object Model (BOM) is used to interact with the browser. We can run the JavaScript Code in UFT to interact with the browser.

Setting a value in a text box using a combination of DOM and BOM.

Setting a value in a text box using a getElementsByName if the index of the object is known. In the following example setting value in a text box that is at 0th index.

Recommended Posts

Leave a Reply