SEMrush

What are Object Models in Javascript - Document Object Model or DOM , Test object model TOM , Automation Object Model AOM

Object Models in Javascript


Document Object Model (DOM), a programming interface developed by the World Wide Web Consortium (W3C) to create and modify HTML pages and XML documents.

With the Document Object Model, programmers can create and build documents, navigate their structure, and add, modify, or delete elements and content. Anything found in an HTML or XML document can be accessed, changed, deleted, or added using the Document Object Model. 

The Document Object Model can be used with any programming or scripting languages.
DOM is useful when working with web applications. We go for DOM to access internal properties or methods of a web application. “.Object” property is used to access internal properties or methods. To see available internal methods and properties, go to Object Spy à point to any web object à select Run time object properties radio button.

Msgbox Browser("Google").Page("Google").webedit("q").object.value
Browser("Google").Page("Google").webedit("q").object.focus

Focus is a method and Value is a property for webedit.
Object is a property for every web object to access internal properties or methods.
To access the DOM we use “.object” method for the specific web 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.

The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML, and XML documents. The nodes of every document are organized in a tree structure, called the DOM tree. Objects in the DOM tree may be addressed and manipulated by using methods on the objects.The Document Object Model is an interface(API) which allow programs and scripts to access and update the content continuously, structure and style of documents.(APIs), which similarly define interfaces between program components, but at the source code level.

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 /Selenium is not able to identify an object. Consider the part of page source below for Google search page.

id=gbqfbwa class=jsb>
id=gbqfba aria-label="Google Search" name=btnK class=gbqfba>id=gbqfsa>Google Search
id=gbqfbb aria-label="I'm Feeling Lucky" name=btnI class=gbqfba onclick="if(this.form.q.value)this.checked=1;else window.top.location='/doodles/'">id=gbqfsb>I'm Feeling Lucky

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 byGetElementsbyName method as below

1
Browser("Google").Page("Google").object.getElementsByName("btnK").Item(0).click

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

Set PageObject =  Browser("Google").Page("Google").object

TOM

Test Object Model ( TOM )
There are two types of objects in TOM,

  • Test Object and
  • Run-timobject.
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 usingSetTOProperty.

AOM

QTP provides an interface called the automation object model. This model is essentially a COM interface providing a bunch of objects that can be used to automate QTP. The full object list is available in the QuickTest Professional Automation documentation

QTP AOM (Automation Object Model) can be used to automate QTP Operations. Using the objects, methods, and properties exposed by the Quick Test automation object model,we can execute s 


< Previous                                                                   Next >