Vous êtes sur la page 1sur 5

Advance Concepts in QTP:

1) Object Models
2) Connect QC from QTP
3) Working with files (txt,excel,xml,pdf etc)
4) Dot net Factory
5) Excel Macros
6) Frameworks

Object Models:

An Object Model is basically the way we use the object properties in a Programming language or
technology.

Object properties means accessing the objects by object references to achieve the objectives like
invoking a particular method of object.

Ex: 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.

Different types of Object Models:

Test Object Model ( TOM )


Component Object Model ( COM )

Automation Object Model ( AOM )

Document Object Model ( DOM )

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 Quick Test 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 properties are the properties as they are saved in the test
object repository. Run time properties refer to the object properties as it appears in the application
under test.

Ex: 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.

Runtime and Test Object properties: RO in GetROProperty and TO in SetTOProperty, 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.

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.

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 ways with its parameters, the objects pathname and the objects 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.

Quick Test 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.
Dim qtApp
Set qtApp= CreateObject ("QuickTest.Application") ' Create the application object
qtApp.Launch 'Start Quick Test
qtApp.Visible = True ' Make it visible

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 allows 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
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
Following are few important properties and methods that we 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.

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

Vous aimerez peut-être aussi