Dani Vainstein & Monika Arora GauDani Vainstein & Monika Arora Gautamtam
1
Flight Reservation Module
Implementation of Flight Reservation
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 2
Topics covered
Exporting Data-tables. Checkpoints and CheckProperty method. Testing ActiveX test objects. Mapping objects using filter. Implementation of
Req0010 to Req0015
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 3
Before you start…
Before starting the presentation, read about the following topics in QTP help. WinObject object. ActiveX object. Run-time properties. WinMenu.CheckItemProperty method. ExitActionIteration statement. WinMenu.ExpandMenu property. WinMenu.BuildPath method. DataTable object.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 4 4
guiFR Module
Open a new blank test and save it as “guiFR” under the folder FR\RA\GL
guiFR
LIB
RA
TESTS
RS
DOC
FR
DATSETTING
RES
BATCHENV
Automation
BL
GL
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 5
guiFR - Introduction
We are going to create a new test, classified as a GUI module, and a reusable action.
The module name would be guiFR, because it will handles the “Flight Reservation” window.
This action will be called GuiFR because the reusable action is going to handle all the operations on FR windows .
The guiFR will receive a single input parameter (StepName) of String type.
As you might have noticed in previous presentations all guiXX actions have one and only one input parameter.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 6 6
guiFR Settings
From Menu Edit Action Action Properties
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 7 7
guiFR - General Tab
ChangeActionName
AddDescription
MarkReusable
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 8 8
Parameters Tab – Add StepName Add a new Input Parameter ( Click on + )
AddStepNameInputParameter
TypeString
DefaultLeave Empty
AddDescription
Click OK
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 9 9
Adding Objects to Local Repository Open the Flight Application from Start All Programs
QuickTest Professional Sample Applications Flight. Login to FR.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 10 10
Adding Objects to Local Repository Open the local object repository from
Menu Resources Object Repository. Or just press < Ctrl + R > in QTP application. Click Add objects in toolbar or select Object > Add objects
to local repository from menu-bar. QTP will show an hand icon.
Click Add objects in toolbarOrObject Add objects To
Local…
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 11
Mapping objects
Select The
Window Title
With the point hand
Verify WinObject is unchecked under Miscellaneous
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 12
Mapping Objects
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 13 13
Naming conventions
All the objects will be added to the local repository.
While mapping the FR window we can see how naming conventions can be effective.
Which button is Button_2? and Button_4? Which object is MaskEdBox?
Rename all objects; use the “Highlight in Application” and “Locate in Repository” features.
When an object was located, right-click on the object logical name ( left pane ) and select “Rename”.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 14 14
Naming conventions
Compact View
Extended View
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 15
guiFR Header
'***********************************************************************
'@Author : advancedQTP
'@Date Created : <ddd MMM dd, yyyy>
'@QTP Version : 9.2
'@Description : The guiFR Module Stores all the actions required for the Main screen.
'@Input Parameter : Name:=StepName, Type:=String, Default:=, Description:=The Step code name.
'@Out Parameter : None.
'@Gui Window : Window "Flight Reservation"
'@Addins : ActiveX
'@Modifications : <#n By <Name>, Date: <dd-mmm-yyyy>> (Later modification on top)
' <#n-1 By <Name>, Date: <dd-mmm-yyyy>
'***********************************************************************
Option Explicit
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 16
guiFR Template
Option Explicit
Dim msg
Select Case LCase( Parameter.Item( "StepName" ) )
Case ...
Case ...
Case Else
Reporter.ReportEvent micWarning, "NotImplementedException", Parameter( "StepName" )
ExitAction( micWarning )
End Select
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 17
Implementing Req0010
There are 6 bitmap checkpoints and 6 property checks.
It is not possible to merge a bitmap checkpoint to a Standard checkpoint, so we are going to use the CheckProperty method of the WinButton object.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 18
Implementing Req0010
Add a new “Case” to the Select Case statement. Remember to use lower-case since the Select
Case condition is converted to lower case ( LCase Function )
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 19
Req0010 – Bitmap Checkpoints To insert a bitmap checkpoint we must be in “Record”
mode. Before pressing RECORD, place the cursor below the
Case “req0010” be sure only one instance of “Flight Reservation” application is opened.
Put the cursor on line 19 ( just below case “req0010” )
Avoid This!!!
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 20
Name: Req0010a
Timeout : 2
Inserting a Bitmap Checkpoint Be sure you are in Recording Mode ( Status Bar Message blinking ) Select from menu : Insert Checkpoint Bitmap checkpoint. With the pointing hand, select the “New Order” button. Then without stopping continue to the rest of buttons one after
another.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 21
Req0010 - Implementation
Place the cursor below the last checkpoint and press F7.
You will see the step generator. Category : Test Objects. Click the object icon on right.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 22
Req0010a – Using the Step Generator
Name: NewType: Button
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 23
Req0010a – Using the Step Generator
Operation:
CheckProperty
Documentation:
Click For Documentation
PropertyName:
enabled
PropertyValue
True
Timeout
2000
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 24
Step Generator…
For some reason the Step Generator, converts “Any” values to string. So we need to fix the strings “True” to Boolean True.
Repeat above steps for rest of the bitmap checkpoints.
Fix Manua
lly
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 25
Checkpoints
Place the cursor below the checkpoint created for “req0010b” and press F7.
Repeat Steps discussed from slide # 21 to 24. Repeat above steps for rest of the bitmap
checkpoints. Do not forget to change string “True” to boolean
TRUE and for Delete “PropertyValue” should be FALSE.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 26
Req0010 Case - Modifying
Modify Script for better look and fit to code standards
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 27
Req0010 Case – Keyword View
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 28
Implementing Req0011
Req0011 checks also the properties of the “Date of Flight” field.
The “Date of Flight” field is an ActiveX object we have to test 5 properties.
“Flight From” and “Flight To” has two properties to be tested. To test these 2 properties we will use standard checkpoints.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 29
Implementing Req0011
Press on record, and insert a standard checkpoint for this object.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 30
Implementing Req0011a Rename the checkpoint to “Req0011a” and only check the
required properties
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 31
Modifying Checkpoints
If you find that you made a mistake on selecting properties you can always edit you checkpoints.
Select the word “Checkpoint” and right-click. In the popup menu select “Checkpoint Properties…”
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 32
Implementing Req0011b and Req0011c. Add a standard checkpoint for “Fly From” and “Fly To”. Give the name “Req0011b” and “Req0011c” respectively.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 33
Implementing Req0011d
Since Req0011d checks only one property, we will insert the checkProperty method manually or via “Step Generator” .
Use QTP intellisense when typing.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 34
Implementing Req0012
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 35
Implementing Req0012
All the fields from “a” to “i” except “e” are disabled all the time, they are just information fields.
The thing that we need to test here is not that fields should be enabled but that fields are not displaying any data, all fields should be empty.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 36
Implementing Req0013
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 37
Implementing Req0013
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 38
Implementing Req0013 – Menu Defaults We are checking the WinMenu object. To check a menu item, we are going to use the CheckItemProperty
method because it is not supported by any standard checkpoint. Menu item exists.
Window( “FR” ).WinMenu( “Menu” ).CheckItemProperty “<item>”, “Exists”, True, 2000
Menu item enabled. Window( “FR” ).WinMenu( “Menu” ).CheckItemProperty “<item>”, “Enabled”, True, 2000
Menu item index. Window( “FR” ).WinMenu( “Menu” ).CheckItemProperty “<item>”, “Index”, <n>, 2000
Menu item label. Window( “FR” ).WinMenu( “Menu” ).CheckItemProperty “<item>”, “Label”, <label>, 2000
Menu item SubMenuCount. Window( “FR” ).WinMenu( “Menu” ).CheckItemProperty “<item>”, “SubMenuCount”,
< count >, 2000
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 39
Implementing Req0013 – Menu Defaults We need to “check” 15 menu items and 7 properties each
( 105 lines of code ). We can repeat the code ‘7’ times, for each menu item; that
will work, but, it will require a lot of coding, and if, in the future, something changes in Menu, then it will require more time in maintenance.
For this specific requirement I have chosen a “smart” method.
I will create an excel sheet with the expected results and use the QTP iteration mechanism, so now, the only thing left is to maintain an excel-sheet, and not the code.
Earlier we learned how to import an excel sheet, now we’ll see how to export an excel sheet.
Select the Local Sheet “guiFR”
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 40
Req0013 Process Design
<n> Rows
Exists?Y
Start
Exists
Loop
<rows>
Enabled?
Failed
Y
Label?
Enabled
Label
Index? Index
Y
HasSubMenu? HasSubMenu
SubMenuCount? SubMenuCountY
Y
Y
< CHECK >Index :
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 41
Req0013 Process Design
<n> Rows
Exists?Y
Start
Exists
Loop
<rows>
Enabled?
Failed
Y
Label?
Enabled
Label
Index? Index
Y
HasSubMenu? HasSubMenu
SubMenuCount? SubMenuCountY
Y
Y
< CHECK >Index :
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 42
Exporting a Data-Sheet If you don’t see the Data Table select from menu View Data Table
Or from the toolbar as shown below.
View Data Table
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 43
Inserting a new Data-Column
You can insert/change the name of a column for a parameter by double-clicking the column heading cell.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 44
Inserting a new Data-Column
Add the follow columns : “itemPath”, “menuItem”, “Exists”, “Enabled”, “HasSubMenu”, “Index”, “Label”, “SubMenuCount”
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 45
Exporting Data Table
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 46
Modifying Datasheet Open FR\DAT\FR.xls Delete line no. 2 ( remove the cell frames ) Rename sheet to “MenuDefaults” You can optionally remove “Sheet2” and “Sheet3”
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 47
Entering Data
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 48
Excel Options
When I first wrote the excel file and run it, I found something very strange. My checkpoint failed with the following message :
If you have a sharp eye you can notice a minor difference..
If you still didn’t notice the difference, I'll tell you; the expected 3 dots, are wider than the actual 3 dots...mmmm
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 49
Excel Options I researched, and almost got crazy, but then I found a
solution. The last 3 dots are NOT 3 characters, “those” are actually a
single “symbol” character.
And why is it a 'single symbol' character? Because that is the way microsoft has designed it.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 50
Excel Options
If you just type the string “Open Order...” in MS-Excel and press ENTER, you will see the following difference:
And not
The difference can be seen in better in “Courier New” font. That’s the main reason that I recommend to use the
“Courier” or “Courier New” fonts. The AutoCorrect feature is defined by default to change
the 3 dots. Select in Excel menu : Tools > AutoCorrect Options... >
AutoCorrect Tab Uncheck the option “Replace text as you type”.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 51
Implementing Req0013
Add a new Case “req0013”. Remember to use lower-case.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 52
Implementing Req0013
Notice that we have left some cells empty in the excel sheet. According to SRS document the properties that we don't need
to check are left empty. The idea is to “check” data, only if the content of the cell is
not empty.
If DataTable( "< column name >", dtLocalSheet ) <> "" Then
' ** CheckItemProperty...
End If
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 53
Implementing Req0013
Declare the variables that we’re going to use. Reporting the current checked menu item. Activate the FR Window.
Case "req0013"
Dim itemPath, bExists
Reporter.ReportEvent micDone, "Menu Item", DataTable( "menuItem", dtLocalSheet )
Window( "FR" ).Activate micLeftBtn
QTP Help : "Note: For better performance when running your test, you may want to set the ExpandMenu property to False"
Window( "FR" ).WinMenu( "Menu" ).ExpandMenu = False
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 54
Implementing Req0013
Retrieving the item path.
itemPath = Window("FR").WinMenu("Menu").BuildMenuPath( DataTable("itemPath",dtLocalSheet))
First, we want to verify if we need to check the property “Exists”, by checking if column “Exists” is not empty.
Instead of vbNullString you can use " ". I think that vbNullString is more “elegant”.
If DataTable( "Exists", dtLocalSheet ) <> vbNullString Then
End If
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 55
Implementing Req0013 - CheckItemProperty
Put the cursor after the If statement and press F7 to open the Step Generator.
Select Menu
Test Objects
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 56
Implementing Req0013 - CheckItemProperty
CheckItemProperty 1. Parameter = Constant
2. itemPath
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 57
Implementing Req0013 - CheckItemProperty
CheckItemProperty 1. Parameter = Constant
2. Constant = Exists
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 58
Implementing Req0013 - CheckItemProperty
CheckItemProperty 1. Parameter = DataTable
2. Current action sheet
3. Name = Exists
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 59
Implementing Req0013 - CheckItemProperty
1. Timeout = 2000
2. Return value = bExists
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 60
Modifying...
"itemPath" is a variable not a string. Manually modify the value.
Similarly change string “itemPath” to variable itemPath for the rest of the properties or insert the statements manually using QTP intellisense.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 61
Applying With…End With Statement
It is possible to apply “With....End With” statements automatically to the scripts.
However it is not recommended, because QTP’s intellisense feature does not work then.
This is a bug in QTP. However you can try to apply “With....End With” by selecting from menu Edit Advanced Apply with "With" to script, or just press < Ctrl + W >. see what happens!
You can restore to previous state by typing < Ctrl + Shift + W > If you have to apply “With....End With” to a specific area, you
will have to do it manually. If intellisense would also works with “With....End With”
statement, it will be a great advantage, as the statements make code more readable.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 62
Requirement Req0013 – Final Look
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 63
Requirement Req0014 and Req0015
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 64
Implementing Req0014
In the Summary Frame we need to check 2 objects. Those are 2 CheckProperty methods.
Use QTP intellisense to complete the commands.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 65
Implementing Req0015
Req0015 is just a bitmap checkpoint to the image. Since the image is not in the repository we need to add it. To open the local repository type Ctrl + R.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 66
Inserting a single object to Local Repository
Add objects to Local
Select with the finger point the image.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 67
Inserting a single object to Local Repository
Change "Static" to "Image"
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 68
Implementing Req0015
Insert a bitmap checkpoint. Start recording, and remember, only one instance of the Flight Reservation application should be opened.
Stop recording after inserting the bitmap checkpoint.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 69
Req0015 – Final Look
A good practice is to Activate the window before a bitmap checkpoint.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 70
What’s Next?
We have already seen how to implement a single test for each requirement.
In next presentation we are going to learn a different method; To test a group of requirements ( GUI Defaults ) in a single test.
We call it the Keyword-Data Driven method.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 71 71
Make sure to visit us for: Tutorials Articles Projects And much more
@www.AdvancedQTP.com
Top Related