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
- Test Object Model ( TOM )
- Document Object Model ( DOM )
- Component Object Model ( COM )
- 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.
<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
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
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.
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.
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")
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.
There is a table with 4 columns and 10 rows, how to write the script to display the first column
records using qtp?
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.
yaa yaa very good reply….i also thought that same answer…thank you very much saket
If 2 gmail browsers are opened in our system, how to enter the mail id and password into second
browser by using discriptive program?
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
Action1: I have a value “test” stored in a variable X. I want to use that variable X in Action2 ..
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.
110. How to load a object repository in QTP during runtime?
What is the difference between “call” and “callclose”?
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?
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.
How can we redirect QTP results in to a excel sheet after the execution
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.
158. What is Dif between Test parameters and action parameters ?
Write a script to delete the a specific row in a webtable.
what is the dictionary object
what is dictionary object
Dictionary object is similar to array with the difference that there is an unique is associated with the items.
[…] is a COM objects, it can be instantiated in the same way as any other COM Object. The ProgID for […]
Write a script to delete the a specific row in a webtable.
could you please tell me how to explain datadriven framework in interview
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
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
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.
how to add a object and its physical description to OR in runtime
you will need to Object Repository Utility. you can find more detail in QTP help.
you will need to use this way
Set objOR = Createobject("Mercury.objectrepositoryUtil")
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
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
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:
‘ Mouseover the object.
‘ Wait a second to allow the tooltip to be displayed.
‘ Capture the text of the tooltip object
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.
hi pls giv me detailed information about object & types of objects with real time examples
this has been explained well here http://qtp.blogspot.in/2007/04/explain-test-object-model-test-object_962.html
let me know if you still have any confusions.
how can we save/export the entire DOM in excel?
Hi, I never tried but would like understand the purpose.
I think DOM can be easily converted to xmls and then into Excel.
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
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”
In web table rama is located in so many cells how to count the rama in various cells.
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
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
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.
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.
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.
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.
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.
What does it show on Object Spy? do you have vb add-in enabled?