0 Shares 4970 Views 45 Comments

All About Object Models in QTP / UFT

Jul 07, 2013
4970 Views 45

ObjectModelsAn 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. Please let us know your feedback/comments on this.

You may be interested

Setting up Web Service Automation Project
Katalon Studio
240 views
Katalon Studio
240 views

Setting up Web Service Automation Project

Saket - Oct 24, 2017

Web services are specific services that can be published and called over the Internet by client applications. Katalon Studio supports functional testing of web services. This topic…

Setting up Mobile Automation Project in MacOS
Katalon Studio
241 views1
Katalon Studio
241 views1

Setting up Mobile Automation Project in MacOS

Saket - Oct 09, 2017

Using Katalon Studio, mobile tester can design automation test for both Android and iOS to run on physical devices, cloud services and emulators. This tutorial explains how…

UFT Jenkins Integration
Unified Functional Testing
795 views
Unified Functional Testing
795 views

UFT Jenkins Integration

Saket - Oct 03, 2017

In our earlier post, we got to know the easy integration of UFT with GIT. This post focuses on integration of UFT and Jenkins. I have also…

45 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.

      Reply
    • 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)

      Reply
    • 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.

      Reply
  1. In a Web appl, on a page, there are student names & details listed.On clicking sort button,details
    are sorted on Names.How do u verify htat sorting is done by using QTP?

    Reply
    • 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.

      Reply
  2. 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.

    Reply
  3. Pingback: Everything about Dictionary Object - Automated360

    • 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.

      Reply
  4. I have a page where there are 10 text boxes(input)..is it possible to dump the values in all the 10 text boxes at a time using QTP

    Reply
    • 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.

      Reply
    • 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

      Reply
  5. 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.

    Reply
    • 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.

      Reply
  6. 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

    Reply
    • 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”

      Reply
  7. 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

    Reply
  8. 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

    Reply
  9. Hi,

    I creating cookie using QTP/UFT,cookie got created but here i want to know whether the stored cookie is persistence cookie or session cookie.

    Regards
    Dharmaraju

    Reply
  10. 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.

    Reply
    • 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.

      Reply
  11. 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?

    Reply
    • 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.

      Reply

Leave a Comment

Your email address will not be published.

Most from this category

Join The Growing Group of 15000+ Test Automation Engineers

Signup for our newsletter and get access to free downloads, as well as tips, tricks and techniques and various test automation resources.
Name
Email Address
Secure and Spam free...