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.

See also  Get a Free Copy of HP UFT (QTP) Certification Questions Pack

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.

<div id=gbqfbwa class=jsb>
<button id=gbqfba aria-label="Google Search" name=btnK class=gbqfba><span id=gbqfsa>Google Search</span></button>
<button 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/'"><span id=gbqfsb>I'm Feeling Lucky</span></button></div>

the part of the source is for the two buttons at 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

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
set ButtonObjects=PageObject.getElementsByTagName("button")

For each button in ButtonObjects 

	If lcase(button.type)="button" Or lcase(button.type)="submit" Then 
		If UCase(button.name)="BTNK" Then 
			button.click 
			Exit For 
		End if 
	End If 
Next

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.

Set PageObject =  Browser("Google").Page("Google").object
Set InputObjects = PageObject.getElementsByTagName("INPUT")

inCount=InputObjects.Length-1
For i=0 to inCount
    If InputObjects(i).Name="q" and InputObjects(i).Type="text" Then
        PageObject.getElementsByName(InputObjects(i).Name)(0).Value="Automated-360"
        Exit For
    End If
Next

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.

x=Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").GetROProperty("x")
y=Browser("name:=Google").Page("title:=Google").WebEdit("name:=q").GetROProperty("y")
Browser("name:=Google").Page("title:=Google").Object.elementFromPoint(x,y).Value="Automated-360"

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
Print Browser("Google").Page("Google").Object.activeElement.name

cookie – Sets or retrieves the string value of a cookie. Find more details on Cookie here

Print Browser("Google").Page("Google").Object.Cookie

documentElement – Retrieves  the root node of the document.

Print Browser("Google").Page("Google").Object.documentElement.innerHTML

readyState – Retrieves a value that indicates the current state of the object. This property can be used for sync in QTP scripts.

Browser("Google").Page("Google").Object.readyState

 

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.

See also  Set Test Setting and Options runtime

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.

Set oFSO = CreateObject("Scripting.FileSystemObject")

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

Set oFSO = Nothing

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.

Set oWord = GetObject("C:\Test\Test1.doc")

or

Set oWord = GetObject("","Word.Application")

 

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. 

Dim UFTApp

Set UFTApp= CreateObject("QuickTest.Application") ' Create the application object

UFTApp.Launch 'Start QuickTest

UFTApp.Visible = True ' Make it visible

I hope you enjoyed reading about these object models and this will definitely help you in your automation. Please let us know your feedback/comments on this.

47 COMMENTS

    • Hi RamaKrishna. A simple way could be as below Get rowcount for the table Itereate from 1st to last row using for loop Use getcelldata method to retrieve the data from 1st col and iterated rows Hope this helps.

    • Use creation time to identify the different instance of browser opened. Value should be 0 for 1st opened browser, 1 for next and so on. Eg. For second browser it will be like
      Browser(“creation time:=1)

    • There can be different ways for this. One of the ways could be using global variable or environment variable. Another way will be to pass the value of the variable as output parameter from action1 and use the output variable as input for 2nd action.
      You can use datatable as well to store tge value and use it in other actions.

    • first – get all the values(names) in an array, prior to click on sort button.
      then – sort the array using any sort method,
      go through each and every value in the list and compare with sorted array.
      this should give you what is required.

  1. If there is a web table of having row and colmns.a button is placed at 2nd row’s 3rd column which
    is worked for both edit and delete..how to write script for the button to test both operation on the web table using desriptive programing.

    • Conceptually Data driven framework is as below, but I will suggest that you explain with your experience with data framework. preferably with the problem statement and example. like the need of data driven, why it was chosen etc.

      “The framework which is driven by test data is known as data driven framework. In this framework the test scripts should be built in such a way that it should work for different sets of data without any changes to the test script.”

      You should explain the components of data driven framework like
      test scripts, functions, object repository
      Data Source

      You should focus more on how the data will change and test script will utilize to test different scenarios.
      Explain about the possible types of data sources you can use
      data table
      excel
      xml
      text files
      databases (access, sql) .. etc

      explain about how the data will be retrieved from data sources, different methods. for example explain how driver script will read data from excel and check a specific flag and act or call specific function.

      hope this helps.

      Thanks.
      Saket.

    • Do you mean populating data in all text boxes at once? I doubt that can be possible! what is the requirement? does it happen manually?
      Yes, One by one is definitely possible.

    • yes Saket, need to populate data in all the text boxes at a time…my apps home page has 20 fields, so all the 20 fields should get populated at a time picking up the data from datasheet…
      manually, i think it can be possible by autofill option..not sure

  2. I am tring to automate Fusion Charts with UFT 12. Post acknowledging that, UFT doesn’t support fusion chart automation, i am tring to do it by coordinates.So now, i want to mouse over on a particular screen coordinate and retrieve the tool tip which is getting activated. The code which i used is here:

    Browser-based application
    ‘ Mouseover the object.
    Browser(“Browser”).Page(“Page”).Link(“Link 1”).MouseOver
    ‘ Wait a second to allow the tooltip to be displayed.
    wait 1
    ‘ Capture the text of the tooltip object
    txt= Window(“nativeclass:=tooltips_class32”).GetROProperty(“text”)
    msgbox txt

    it is retrieving the tool tip for all the controls except the graph contents.
    Please help, if you find the solution.

    • Hi Sree, its definitely not the usual windows tool tip class. Need to check on the exact object. I think its being set into the xml tooltext tag. Not sure though.
      Can you help me with a sample chart available, to try onto it.

  3. there is a application and a small button in it.When we click on that button another window opens up with contains a web table containing 5 columns and 15 rows.The fifth column is a checkbox.
    We are passing the value of the first column from excel sheet and the script is supposed to fetch it from the excel sheet and find that row containing that ID and check the corresponding checkbox.

    How do we script this using QTP

    • Hi Onkar,
      below should help you to script

      1. Connect to Excel and get the ID from the desired row column in the excel
      variable = ID retreived from excel
      2. Get the desired row in the table
      Row = webtable.getrowwithcelltext(variable)
      Col = 5 (ideally you should get this runtime only, while going through all the columns.)
      3. Get the checkbox with childItem at desired row col and index and Set
      Webtable.ChildItem(Row, Col, “WebCheckBox”,0).Set “ON”

  4. in a webtable i want click the view button in the opposite to name rama and city chennai example given bellow

    name city button
    === ==== ======
    rama hyd view
    krishna chennai view
    rama chennai view
    raju banglore view

  5. When i am using

    Browser(“name:=Cookie for Automation”).Page(“title:=Cookie for Automation”).Object.cookie=sUserCredentials_Reg_Value

    I am dealing with a cookie and I would like to know that whether it is a Session cookie or a Persistant cookie.

    Any document to support

  6. Hi,
    I am working on web application, there is an object if we normally mouseover on that object the remaining links present in that was visible and able to click on the links. But while using object spy on that particular object in application it not showing the links present in that object. can you please help me how to write the script for this.

    • Hi Priyanka,
      if you are asking how to spy the link object – use left CTRL key while spying anf mouseover the menu to show your submenus.
      to implement the same by setting replay type as mouse

      Setting.WebPackage("ReplayType") = 2

      Changing ReplayType to Mouse instructs UFT to replay the actions using Keyboard and mouse simulation. This would simulate a actual user interacting with the browser. It is always a good practice to set it back to events (default – recommended) once you are done with the required.

  7. Hi saket,
    In my application flash objects are modified as HTML objects and are identifying as web element by uft 12.51. Almost all properties are same for every web element. How to differentiate those web elements in UFT. I tried virtual relation identifier as well. But, no use with that approach. So,Can you help me how to validate those pages?

    • I had this problem earlier, and this is a known issue with QTP/UFT. however I have not tried flash with latest version of UFT, but I did not hear any great news on UFT working with flash recently, so I assume its as is.
      I dont recommend UFT to automate flash based application, rather I found testcomplete is the best tool to work with flash/flex application.
      you would like to consider another tool, go with testcomplete.

      if not give it a try with Adobe add-in.

  8. Hi Saket,
    Could you please let me know how to handle window security authentication pop up on launching url.
    I am unable to spy the objects in that pop window.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.