Documente Academic
Documente Profesional
Documente Cultură
Whenever you record on any object using QTP, QTP adds the test object to the Object Repository. While
running a test, QTP finds the object in the Object Repository and uses the stored test object¶s description to
identify the object in your application/website. Only after the object is found in the Object Repository, QTP
can perform methods on those objects.
We can also instruct QTP to perform methods on objects without referring to the Object Repository. This is
possible with the help of Programmatic descriptions or descriptive programming.
This implies that descriptive programming is very helpful if you want to perform an operation on an object
that is not stored in Object Repository.
c
is also useful to perform the same operation on several objects with certain
matching properties e.g. suppose there are 8 check boxes on a web page with names as chk_1, chk_2 and
so on. So it¶s not a good idea to put these in an Object Repository. With the help of c
you can Set these check boxes ON or OFF according to your application needs.
If you are dynamically creating test objects during the run session then also c
goes a long way to help you. Suppose in a web site you have to generate a list of all the customer's email
addresses, who brought iPhone from you, based on the geographical information you provided and then
after the email addresses are provided as checkboxes you have to send a rebate letter to them. You don't
know how many check boxes will be there based on the geographical information you provided. So in this
case, you can use a Descriptive programming to instruct QTP to perform a Set "ON" method for all objects
that fit the description: HTML TAG = input, TYPE = check box.
c
Static: We provide the set of properties and values, that describe the object, directly.
Dynamic: We have to add a collection of properties and values to a description object and then provide the
statement with the description object's name.
Static is easier but Dynamic provides more power, efficiency, and flexibility.
We will see examples of both static and dynamic type of descriptive programming in QTP.
This below example uses Descriptive Programming to open Flight Application and does not use object
repository at all. So one of the other advantages is you can copy this script and Run this from any other
machine (other than on which it was created) and it is supposed to work fine.
For this time just read the script and move on, you will better understand it as you read more.
[ I have given Example 1a's recorded version (which uses Object Repository)in Example 1b just for your
comparison of the two so that you can better understand both ]
Note: When using programmatic descriptions from a specific point within a test object hierarchy, you must
continue to use programmatic descriptions from that point onwards within the samestatement . If you
specify a test object by its object repository name after other objects in the hierarchy have been specified
using programmatic descriptions, QTP cannot identify the object.
For example, you can use the following statement since it uses programmatic descriptions throughout the
entire test object hierarchy:
Above line uses Descriptive Programming for all objects like Browser, Page, WebEdit.
You can also use the statement below, since it uses programmatic descriptions from a certain point in the
description (starting from the Page object description):
Above line uses Object Repository for Browser object and Descriptive Programming for Page and WebEdit.
However, you cannot use the following statement, since it uses programmatic descriptions for the Browser
and Page objects but then attempts to use an object repository name for the WebEdit test object:
QTP tries to locate the WebEdit object based on its name, but cannot locate it in the repository because the
parent objects were specified using programmatic descriptions.
If the same programmatic description is being used several times then we can assign the object to a
variable:
E.g. in the above Example 1a script, window("Title:=Login") is being used several times so we do this:
Or
Understand it like this ± A Property Object is a property name and value. We use Description object to
return a Properties collection object containing a set of Property Objects. Then only in place of an object
name, returned properties collection, can be specified in a statement.
Once Property Object (Myvar) is created, statements to add, edit, remove and retrieve properties and
values to or from properties objects can be entered during the run time.
Lets take a complete example of this: [these extra values (height & width) are not important in our example.
Our example can run without height and widthproperties. I have just added those in order to make you
understand this]
There is a ChildObjects method which can be used to get all objects located within a specific parent object
or only those that match some criteria for programmatic description. In short we first of all need to create a
description and then use a particular syntax to retrieve all child objects that match that description and
manipulate them according to our own wish.
Make sure that Flight Reservation window is open (Start- Programs- QuickTest Professional- Sample
Applications- Flight). In this Flight reservation window go to File- Open Order.
We will use this childobjects method to count the checkboxes in this 'Open Order' dialogbox.In the below
script childobjects method is being applied to dialog object and childobjects method uses mydescription
property object we created.
Set mydescription=Description.Create()
mydescription("Class Name").value="WinCheckBox"
Set Checkboxes = window("text:=FLight Reservation").dialog("text:=Open
Order").ChildObjects(mydescription)
a=Checkboxes.count
msgbox(a)
Just try to understand the above code. This is just an example, in real life you can use this count in some
kind of loop.
Run-time value of a specified object property can be compared with expected value of that property by
using programmatic description.
Descriptive programming checks are helpful for the object whose properties you want to check but the
object is not stored in Object Repository.
I will show a small example here which checks if the "Flights.." button in Flight Reservation window is
enable or disable. I have used a message box to show whether it is enable or disable, you can use the
Report.ReportEvent Statement to send the results to the result window of QTP.
For the below script make sure that Flight reservation window is open:
a=window("Title:=Flight Reservation").winbutton("Text:=FLIGHT").GetROProperty("enabled")
msgbox (a)
If a = True Then
msgbox ("button is enable")
else
msgbox ("button is disable")
End If
In the above script GetROProperty method is being applied to 'Flight..' button to check the 'enable' property
of the button.
[you can see an object's properties and methods from QTP help. Definitely there are other ways also to get
these].
c
(A WebElement is a general web object
which can represent any web object.)
As an example, just open the website (http://newtours.demoaut.com/) and make sure the cursor is in the
³User Name´ text box and write the following line in the Expert View of new test:
It will just click the ³Password´ text box which just highlights that text box and places the mouse cursor in
that box.
For all the methods and properties of WebElement object please refer QTP User Guide.
Index property is useful to identify a test object uniquely. QTP also, while learning an object, can assign a
value to test object¶s index property to uniquely identify it. Index property values are specific to an object
and also the value is based on the order in which the object appears in the source code.
The value starts with 0.
If you use Index:=1 with WebEdit test object, QTP will search for the second WebEdit object on a web
page.
As an example, just open the website (http://newtours.demoaut.com/) and write the following line in the
expert view of new test:
This will write ³hello´ in the ³Password´ text box. In the above line if you do Index:=0 then ³hello´ will be
written in the ³User Name´ text box.
On the other hand if you use Index:=2 to describe a WebElement object, QTP will search for the third
object on the page (it can be any, regardless of type) because WebElement object is general object that
applies to all objects.
£
SystemUtil object allows you to open and close application by writing its code manually in the Expert view
of QTP.
Below example shows how to open or close a Notepad using code:
systemutil.Run "Notepad.exe"
wait(3)
SystemUtil.CloseProcessByName("Notepad.exe")
This example uses Run and CloseProcessByName methods to open and close the application (Notepad).
Instead of closing the Notepad with CloseProcessByName method, we can use the below line also which is
mostly used.
window("title:=Untitled - Notepad").Close
For opening the application we can use complete paths also e.g.