Thursday, July 3, 2008

Quick Test Professional (QTP) - Tutorial

Here is the detailed description of each topic with navigation.......

Test Object Model(TOM):

It is a Set of classes,Environment & Properties.
It helps QTP to record properties for each Test Object.

TOM will supply properties that QTP records for each test object during recording,for every class of the selected environment ,properties will configured in the above given order.

With the help of AD-Ins we have selected in the AD-in s manager screen. QTP will get to know the environment and class name of the object,With this information ,it goes to object identification screens and get the list of properties configured in mandatory list. Imedialty it goes to the application window and records current properties of these values. Now the properties and its current values will be placed in the object repository and a statement will be generated in expert view(Script Editor Window).

During Play back QTP goes to object repository and recollects properties description ,with this it recognizes object in the application window and repeats the operation. Sometimes execution fails and a message will appear saying that “Can not Identifying an Object of Class**”Make sure that Properties available in the application. This may happen due to two reasons

Properties available in the repository in adequate to recognized the object.
Properties description in Object repository does not match with the description in AUT(Application Under Test).

When QTP identifies that the properties in the mandatory list are not enough to uniquely identify an object then it records current values of properties available in Assistive properties list.

Smart Identification is properties intelligent,It is complex and reduces performance of test execution. When test execution is posses because object was found with the help of Smart Identification then a warning message will appear in test results window.

- For window application we need to configure Smart Identification by Manually.
- For Web applications Smart identification will be configured automatically.

In Smart Identification we have to separate list to configure includes “ Base filter properties & Optional filter properties”.


Play Back: Steps

Hit Run ----Expert view –Object repository-- application----Expert view –Application –Result screen


OBJECT REPOSITORY :


It stores : ------ Resource file
-------Test object repository description
------- File extensions .mtr & .tsr

File extension of
-- Per test object rep :- filename.mtr

-- Shared Oject rep :- filename.tsr

---Code file extension id script.mts


The purpose of Logical Name is to identify the object in the repository.The purpose of Properties Description is to identify the Object in the repository.


For each object in the application on which end user perform on application a logical name and Physical description of that object will be place in the object repository. Then a statement will be generated in Expert View.

Purpose of the Logical Name is to identify the object in Object repository. QTP generates a Logical name for test object in the repository and the same logical name will be maintained in the expert view.

During test run QTP takes Logical name from the current line from the expert view and find the match in the object repository. For each logical name properties description has been attached .QTP takes properties description to the identified logical name and recognize the object in the application to repeat same operation.
It means the purpose of the properties description is to identify an object in the application.
By default QTP takes Label name to generate Logical Name. This is the unique within the repository file. When multiple objects in the same application window share similar Logical name then for the second object the logical name would be Label name_2.If the another same object is

Identify name would be label name-3 etc...
When an object in the application does not have any label name then QTP generates Class name of that object as logical name. If multiple objects have the same description the logical name would be Class name_2 etc....

Ex: Vbedit_2, Link_3 ,WinButton_4 ......

We can edit auto generated Logical name to any other meaningful name.But make sure that this new name will updated in test script automatically.

Steps for edit Logical name:

1.Go to Resource ---->Object repository
2.Object repository Window will displaying.
3.Select the required logical name to change and press mouse right button and chose the Rename option or press F2.
4.Specify new logical name and press Enter button.


Note:1 When we edit Logical name in the repository all the occurance of existing logical names in script will be updated at a time,but vise verse is not possible.

Note:2 To delete object description from object repository completely, we need to follow the steps sequences.

Steps for Delete object description:


1.Go to Resource -----> Object repository.
2.Object repository Window will displaying.
3.Select logical name to delete its description
4.Press mouse right click for delete option.

Note :3 : To ensure weather properties description uniquely identifies an object in the description and follow the bellow steps:

1.Go to Resource -----> Object repository.
2.Object repository Window will displaying.
3.Select logical name to ensure its properties description
4.View -----> highlight in the application or click on highlight button from tool bar of QTP.
5.If properties are enough to identify the object the respective object will be highlighted else a pop up window with error message appeared.

Steps to Creates Repository by manually:

1.Make sure that application is invoked and navigated to the desired screen.
2.Resource-------> Object Repository
3.Object repository screen appeared.
4.Object --->

Add object to local
5.Mouse pointer changes to pointing icon
6.select the required object in the application window
7.Object selection dialog box with the selected object and all its assendents (Parent)will appear.
8.Make sure that required object is selected and click on OK button.
9.Select object Logical name and properties description will be placed within the object repository under test object root
10.Repeat the steps 4 to 8 to add more objects into repository.


Note:1 Place only the required object into the object repository screen to reduce repository size.

Note:2 the max size of the object repository file is 2MB


OBJECT SPY


This tool is used to let us know all the properties with in current values ,completes object hierarchy and available methods.

Steps:
1.Make sure that application is invoked and navigated to the desired screen.
2.Tools-Object spy
3.Object spy screen appears
4.Hit pointing hand icon from object spy window.
5.Mouse pointer changes to pointer icon
6.select the required object
7.Information of the selected object will be displaying within SPY window.
8.Repeat above to Spy on other objects.

Note: Properties and its object values displayed in object SPY window cannot be saved

Run time object properties are the internal properties of a n object given by developer. Its is not necessary that all the objects must have internal properties.

Test Script Template:

Parent1 Object Class name (“Logical Name”).Parent2 Object Class Name(“Logical Name). ------------- .Child object Class Name(“Logical Name”).Method (Arguments).

Test Object:
It is an object which we creates in the test script. All the test objects would be placed in the object repository


Test Object Properties :

All the properties the test object holds are called test object properties. Test object properties would be placed in the object repository along with the logical Name.

Run Time object:
An object exists in the application on which we execute method during test run.

Run Time object Properties :
All the properties developer associated to an object in the application are called run time object properties.

Note: Test properties are a subset of run time object Methods.


TEST OBJECT METHODS:

1.Button Class:
Click : Click is specified object during the test run.
Syntax : object . click ([x],[y],[button]).

Example: Dialog(“Login”).WinButton(“Ok”).click

Note: [] indicates that Optional

Dbclick : It double clicks on object.
Sytax: object .dbclick (x,y,[button]).

2.Edit Box/Text Box

Set: Sets the value of the specified edit object.click
Syntax: Object . set “text”
Example: Dialog (“Login”).WinEdit(Agent Name”).Set “sekhar”

Setcaretpos : Place the cursor at specified edit object.
Syntax: Object . setcaretpos Position
Example :Dialog(“Login”) winedit(“Agent Name”).setcaretpos 4

Set selection : Selects the specified characters of the string within the specified object
Syntax : Object . Selection startpo,end pos
Example:Dialg(“Login”) .winedit (“Agent name”).set selection 0,4
result: S ekha R

Setsecure: Sets the encoded string in to the password edit object.
Syntax: Object .Setsecure Encryptedstring
Example: 1.Dialog(“Login”).Winedit(“Password”).setsecure “***********”

Navigations : Start--> programs--> QTP—>Tools( to encrypt the password by using QTP)

Example: 2: str= crypt.encrypt.encrypt(“Mercury”)

Dialog(“Login”).Winedit(“Password”).setsecure. Str

3.Window:

Maximize: Maximize the window during the test run.

Syn: Object . Maximize
Example: window(“Notepad”).Maximize


Minimize : Minimize the window during the test run.
Syntax: Object . Minimize
Example: window(“Notepad”). Minimize


Activate: Activate the window
Syntax: Object .Activate
Ex: Window(“Notepad”).Activate

Move: Move the window to the specified co ordinates
Syn: Object move x,y
Ex : Window(“Notepad”).move 150,162

Resize: Resizes the window to the specified dimensions
Syn: object. Resize width,height
Ex: Window(“Notepad”). Resize 180,520

Close: close the window
Syn: Object . close
Ex: Window(“Notepad”). close


4.Radio button:

Set: Set the specified radio button object
Syntax: object . set
Ex: Window(“Flight Reservation”).WinRadiobutton(“Economy”).Set


5.Check Box:

Set: Selects/Unselects the specified check box
Syntax: object . Set boolean value --------- >boolean values: ON/OFF

Ex:For i=1 to 4
Window (“Flight Reservation”).Diallog(“Openorder).WinCheckbox(“customer name”).Set “ON”
wait1
Window(“Flight Reservation”).Diallog(“Open order").WinCheckbox(“customername”).Set
“OFF”

6.Combo Box:


Select :
Selects an items from the specified combo box.
Syn: Object .select “ item name/index”
Ex: Window(“Flight Reservation”).WinCombobox(“FlyFrom”).select”London”

Get items Count:
Retrieves the count of max items from specified object
Syn: object . GetitemsCount

Ex:CNT=Window(“Flight Reservation”).WinCombobox(“Fly From”).Get items count

MSGBOX CNT


Get Selection:
Retrieves item name currently selected in the specified object
syn: Object.Getselection
Ex: Msgbox Window(“Flight Reservation”).WinCombobox(“Fly From”).getselection

Get item :
Retrieves item name for specified index value from the object
Syn: Object.get item (Index)

Ex:Msgbox Window(“Flight Reservation”).WinCombobox(“Fly From”).Getitem(10)


Get content:
Names of the all items will displayed for specified object
Syn : Object .Get Content

7.List Box:

Extend select : Adds current selection to the existing items selection.

Syn: Object . Extend select “item name”

Ex: Browser (“JobsAhead”).page(“JobsAhead”).Weblist(“JobLoc”).Select “Bangalore”
Browser (“JobsAhead”).page(“JobsAhead”).Weblist(“JobLoc”).Extend Select “HYD”
Browser (“JobsAhead”).page(“JobsAhead”).Weblist(“JobLoc”).Extend Select “Goa”

Note: we can select at a time list of locations in the list box.


8.Web Table:

Column Count: Returns count of Max columns for the specified row id from the specified web Table.

Syn: Object. Column count(Row id)
Row Count: Returns counts of maximum rows for a specified web table.
Syn. Object. Row count

Set cell date: Sets the values of specified cell within the specified web table.
Syn: Object. Set cell data Row id ,column id,Value

Get cell date: Returns the current value of the specified cell from web table
Syn: Object . getcelldata (Rowid,columnid)

Example:
Column Count=Browser(“JobsAhead”).Page(“JobsAhead”).webTable(“Personal
Details”).Columncount(1)

Row Count =Browser (“JobsAhead”).Page(“JobsAhead”).webTable(“Personal Details”).Row count

Msgbox Column count
Msgbox row count

For i=1 to Row count

For j=1 to column count


Msgbox Browser (“JobsAhead”).Page(“JobsAhead”).webTable(“Personal Details”).Getcelldata(i,j)

Next
Next
---------------*--------------


Get row with cell text: Returns first row id found that contains the cell with the specified text.
Syn : Object . Get row with cell text “ Text”
Ex:Msgbox Browser (“JobsAhead”).Page(“JobsAhead”).webTable(“Personal Details”).Getrow with cell text ( “Mobile number”).


9.Browser

Refresh: Reloads the specified web browser
Syn: Object.Refresh
Ex: Browsers(“Google”).Refresh

Navigate: Navigates the specified browser to the specified URL

Sny: Object.Navigate “URL Path
Ex : Browsers(“Google”).Navigate ”www.globe7.com”

Back: Navigates the browser to its previous page
Sny: Object. Back
Ex: Browsers(“Google”).Back

Forward: Navigates the specified browser to the next page in the history list
Sny: Object .Forward
Example : Browsers(“Google”).Forward


Home:
Navigates the browser to have page specified
Sny: Object.home
Ex:Browsers(“Google”).home

Full screen: Shows the browser in full screen mode
Syn: Object.Full.screen
Example : Browsers(“Google”). Full screen

Stop: Stops the browser request
Syn: Object.Stop
Ex: Browsers(“Google”).Stop


Sync:
Wait until the current browser loads completely (Synchronization)
Syn: Object .sync
Ex: Browsers(“Google”).Snyc

Close: Closes the browser
Syn: Object.Close
Ex: Browsers(“Google”).Close

10.Page:

Waits until the specified page loads completely
Ex:Browser(“Google”.page(“qtp-googleserach”.Sync

Common Methods

1.Capture BitMap: Caputures the specified object from the application has an image(.bmp or .png) and saves in the specified file drop
Syn: Object . capturebitmap “Full file Path” over write existing (TRUE)

Ex: Browser(“Google”).capturebitmap “C:\New.bmp”,True ----To overwrite

2.Child Objects: Retries the child objects of the specified parent object that matches the given description.
Syn:Object . Childobjects (description)

Example: Set desc =Description . Create
desc(“Nativeclass”).value=”edit”
Set coll =Dialog(“Login”).ChildObjects(Close)
Msgbox coll.count

3.Exist: Checks weather the specified object exists in the open application and window and returns between value(True or False).The default time for exist method wait when an object is not available in the open application window is 20Sec.
The default time for web application is 60Sec
Syn: object . Exist [Time out]

4.Getvisible Text: Returns text visible for the specified Object
Syn: Object.getvisible Text

Ex: Msgbox Dialog(“Login”).getvisibletext

Note:This method is not met for web objects

3.GetTOProperty: Returns the current value of specified test object property of the specified object from the repository
Syn: Object.GetTOProperty(“Property Name”)

Ex: MSGbox Dialog(“Login”).GetTOProperty(“Text”)

6.GetTOProperties: Returns properties collection of the specified test Object from Object repository.

Syn: Object.GetToProperties

Ex: Set Props = Dialog("BOLOTOLINE"). GetTOProperties

PropsCount = Props.Count

For i = 0 To PropsCount - 1

PropName = Props(i).Name

PropValue = Props(i).Value

MsgBox PropName & " = " & PropValue

Next


7.GetROProperty: Returns current value of the specified property of an object from the application window.

Syn: Object.GetROProperty(“Propertyname”)

Ex: Msgbox window(“Login”).GetROProperty(“Height”)

Note: GetROProperties is not work for runtime application


8.SetTOproperty: Sets the value of the specified test object property dynamically. This new value is not updated in the object Repository.
Syn: Object . SetTOProperty “Property Name”,Property value”

Ex: Dialog (“Login”).Set To Property “Text”, “Login1”

Note: The scope of the new value is till the end of the execution of the script.


9.Type: Performs the keyboard inputs in to the specified objects

Ex: Dialog(“Login”).winEdit(“Agent Name”) .Type “Quick”
Ex: Dialog(“Login”).Winedit(“Agent Name”) .Type “Test”
Ex: Dialog9”Login”).Type mic AltDwn +mic F4 + Mic All Up
Ex: Dialog(“Login”).Type mic ESC

Note: Type and Set perform same operation for edit field,But Type can also perform Active X edit


10.WaitProperty:

Waits until specified property reaches specified target value.

Syn: Object .waitproperty “Property Name”,”target Value”

Ex: Window(“Flight Reservation”).WinButton(“insert Order”).Waitproperty “Enabled”,False

2 comments:

Unknown said...

Hello,
I've gone through all your posts on QTP scripting that are quite helpful in clearing understanding about QTP framework.
I'll appreciate if you can provide your feedback on some of my queries below
- How to deal with similar object components that are being used in multiple java screens? e.g I am working on a transaction processing system where "Text field A" is used in screen "A" and same "Text field A" also exists in "Screen B" and "Screen C". The properties associated with "Text field A" are similar through out my application.
For regression purposes i want to make a single script that can validate "Text field A" no matter in what screen it is located.
Awaiting for your response
Regards,
Mehar

Anonymous said...

Nice blog for QTP.eBook for learning Software Testing And QTP @ http://qualitypointtech.net/ebook/

Quality Center


Quality Center

A Quality Center project is a database for collecting and storing data relevant to a testing process. For QuickTest to access a Quality Center project, you must connect to the local or remote Web server where Quality Center is installed. When QuickTest is connected to Quality Center, you can create tests and save them in your Quality Center project. After you run your tests, you can view the results in Quality Center.


Quality Center helps you maintain a project of all kinds of tests (such as QuickTest tests, business process tests, manual tests, tests created using other Mercury products, and so forth) that cover all aspects of your application's functionality. Each test in your project is designed to fulfill a specified testing requirement of your application. To meet the goals of a project, you organize the tests in your project into unique groups.

You can instruct QuickTest to automatically submit a defect to a Quality Center project for each failed step in your test. You can also manually submit a defect for a specific step to Quality Center directly from within your QuickTest Test Results window. These options are only available when you are connected to a Quality Center project.

Saving Tests to a Quality Center Project

When QuickTest is connected to a Quality Center project, you can create new tests in QuickTest and save them directly to your project. To save a test, you give it a descriptive name and associate it with the relevant subject in the test plan tree. This helps you to keep track of the tests created for each subject and to quickly view the progress of test planning and creation. In QuickTest, click Save or choose File > Save to save the test. The Save Test to Quality Center dialog box opens and displays the test plan tree.

The Save Test to Quality Center dialog box opens only when QuickTest is connected to a Quality Center project. To save a test directly in the file system, click the File System button to open the Save QuickTest Test dialog box. You can return to the Save Test to Quality Center project dialog box by clicking the Quality Center button.

Submitting Defects to a Quality Center

When viewing the results of a run session, you can submit any defects detected to a Quality Center project directly from the Test Results window.

To manually submit a defect to Quality Center: or click the Choose Tools > Quality Center ConnectionQuality Center Connection button to connect to a Quality Center project. Choose Tools > Add Defect or click the Add Defect button to open the Add Defect dialog box in the specified Quality Center project. The Add Defect dialog box opens. You can modify the defect information if required. Basic information about the test and any checkpoints (if applicable) is included in the description. Click submit button.

To automatically submit defects to Quality Center: Choose Tools > Options or click the Options button . The Options dialog box opens. Click the Run tab. Select the Submit a defect to Quality Center for each failed step check box.