Dani Vainstein & Monika Arora Gautam 1 Requirement Req0002 Implementation of Requirement Req0002.
-
Upload
martha-caldwell -
Category
Documents
-
view
215 -
download
0
Transcript of Dani Vainstein & Monika Arora Gautam 1 Requirement Req0002 Implementation of Requirement Req0002.
Dani Vainstein & Monika Arora GauDani Vainstein & Monika Arora Gautamtam
1
Requirement Req0002
Implementation of Requirement Req0002
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 2
TIP
Fr Project staff have made an improvement to the presentations. Whenever you see QTP code, right click the left bottom part of the
presentation and do the follow :
1
2Click
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 3
Topics covered
Extending functionality on existing modules. Process design of a test. Build a new function. Adding single object to local repository. Checking single and multiple properties on an
object. Standard and bitmap checkpoints. Create an initialization action. Create a generic login procedure. Call to an existing reusable-actions. Build a new test.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 4
Before You Start…
Before starting the presentation, read about the following topics in QTP help. Window/Dialog Object - Exist Property. Window/Dialog Object - Activate Method. Reporter Object. Environment Object. SystemUtil.Run Method. Exit Statement. Const/Dim Statement. Select Case Statement. Desktop.CaptureBitmap Method. CheckProperty Method.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 5
Before You Start…
Before starting the presentation, read about the following topics in QTP help. If…End If Statement. vbNullString Constant. Object CheckProperty Method. WinEdit, WinButton, Static Objects. Standard Checkpoint. Bitmap Checkpoint. Checkpoint Properties. Call to an Existing Action.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 6
Req0002 - Overview
User performs following testing on the ‘Login’ dialog.
Before the user starts to enter any data : Req0002a - Label “Agent Name” is visible. Req0002b - Textbox “Agent Name” should be empty,
enabled and focused. Req0002c - Label “Password” is visible. Req0002d - Textbox “Password” is empty and enabled. Req0002e - Command Button “OK” is enabled. Req0002f - Command Button “Cancel” is enabled. Req0002g - Command Button “Help” is enabled. Req0002h - Logo is displayed.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 7
Req0002 - Overview Details
Label
displayed
Label
displayed
Textbox empty
Enabled and focused
Textbox empty
and enabled
Command button
Enabled.
Command button
enabled
Command button
enabled
Logo
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 8
Process Design – Req0002
End
Req0002a
PassedFailedReportmicFail
ReportmicPass
Req0002h
PassedFailedReportmicFail
ReportmicPass
No
DialogLogin
Exists?
ExitTest
Yes
ReportmicFail
Invoke App
Start
InvokeApp FunctionInvokeApp Function
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 9
Process Design – Req0002
First we need a regular invoke application process Then we need to verify that the “invoke
application” process was done successful, before accessing the dialog.
If the process failed, it means the login dialog wasn’t displayed and hence test is failed so there is no point to continue testing.
Then the Req0002 process starts from Req0002a to Req0002h
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 10
Building a Generic Function - Application Invoke Process
To implement the invoke application process we are going to use a function ( Utils Layer ).
Why a function for invoke application? We are assuming that this process is necessary for all the tests.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 11
Analyzing FR Application scenarios invoke
Dialog “Login”Exists
Window “Flight Reservation” Exist
Activate Executable
FalseFalseTrue
FalseTrueFalse
TrueFalseFalse
TrueTrueN/A
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 12
Activation Conditions
1. If “Flight Reservation” (main) main window is already displayed, don’t activate the executable file. We want to avoid multiple application instances.
2. If the “Login” dialog is already displayed, don’t activate. We want to avoid multiple application instances.
3. If “Login” dialog is NOT displayed AND the “FlightReservation” window is NOT displayed activate Flight4x.exe.
4. Main Flight Reservation window and login are opened. This scenario case can never happened. Dialog “Login” and “Flight Reservation” window can’t be opened at the same time.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 13
Application invoke considerations. The main thing we want to avoid when running
scripts on Flight Reservation, is multiple instances of Flight Reservation application. Therefore we need the InvokeApp Function.
Avoid This!!!
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 14
Application invoke considerations. InvokeApp function covers the following
functionality The function should check that no other instance/s are
already open. The function should contain generic process assuming
that the application instance is probably open and working accordingly.
The function should also check a successful activation of the executable.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 15
InvokeApp Design
No DialogLogin
Exists?
YesReportmicFail
End
Start
<version>
FlightReservation
Exists?Invoke App
False
No
DialogLogin
Exists?
End
False
End
True
Yes
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 16
Adding Functionality to existing module
LIB
RA
TESTS
RS
DOC
FR
DAT
SETTING
RES
BATCH
ENV
Automation
BL
GL
Fr.vbs
Open the function library FR.vbs
Menu : File Open Function Library
Hotkeys : Shift + Alt + O
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 17
Creating InvokeApp Function
Function Name:InvokeApp
Type: Function
Scope: Public
execVersion
By value
Description
Documentation
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 18
InvokeApp – Initialization
'@Description Invokes application flight reservation version xx
'@Documentation Invokes application flight reservation <execVersion>
Public Function InvokeApp( ByVal execVersion )
Dim execPath, msg ' local variables
' initialization
InvokeApp = False
Initialize the function to false, as a default return value of the function
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 19
InvokeApp – Condition 1
' ** condition 1 - Window displayed don't activate executable
If Window( "regexpwndtitle:=Flight Reservation" ).Exist( 0 ) Then
Window( "regexpwndtitle:=Flight Reservation" ).Activate micLeftBtn
msg = "Flight Reservation is already displayed."
Reporter.ReportEvent micDone, "InvokeApp", msg
Exit Function
End If
Since we are using a generic function we are using Descriptive Programming ( DP ).
If the “Flight Reservation” window exists, the window will be activated and a general message will be sent to the Reporter.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 20
InvokeApp – Condition 2' ** condition 2 - Dialog Login is displayed don't activate executable
If Dialog( "text:=Login","nativeclass:=#32770" ).Exist( 0 ) Then
Dialog( "text:=Login","nativeclass:=#32770" ).Activate micLeftBtn
msg = "Dialog Login is already displayed."
Reporter.ReportEvent micDone, "InvokeApp", msg
Exit Function
End If
If the “Login” dialog exists, the dialog will be activated and a general message will sent to the Reporter.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 21
InvokeApp – Invoke executable' ** invoking executable...
execPath = Environment( "ProductDir" ) & APP_PATH ' build path...
SystemUtil.Run execVersion, vbNullString, execPath, "open"
Before using SystemUtil.Run method, we need to build the path of the executable, as the Run method requires this argument.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 22
InvokeApp FunctionIf Dialog( "text:=Login","nativeclass:=#32770" ).Exist( 5 ) = False Then
msg = "Dialog 'Login' is not displayed after 5 seconds."
Reporter.ReportEvent micFail, "ApplicationException", msg
Exit Function
End If
InvokeApp = True ' Application was invoked
Immediately after invoking, we’ll check that “Login” exists, with a max wait of 5 seconds, just in case…
If the dialog didn’t show up after 5 seconds, this can be a defect, we fail the test, and exit the function.
If the dialog exists, the function will return True.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 23
InvokeApp – Final Look
Add the function InvokeApp to File library.
Save the function library
You should have 2 functions.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 24
Creating new step
Open guiLogin test and add a new step Case “req0002” ( remember to write the string in lower case )
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 25
Implementing Req0002a
Req0002a uses the CheckProperty method of static, with argument “visible”, value True
The method will auto-report to Reporter object.
Dialog( "Login" ).Static( "AgentName" ).CheckProperty "visible", True, 1000 ' ** Req0002a
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 26
Implementing Req0002b
Req0002b checks 3 properties on 1 object viz. enabled, focused and text. It is recommended to use checkpoint for this purpose.
However, many QTP developers prefer to use various CheckProperty methods instead of a checkpoint, because of the complexity and portability issue of managing checkpoints.
This problem will be solved on QTP 9.5 Before starting to record, the Login dialog must
be displayed. Make sure that only one instance of Flight Application is opened.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 27
Inserting a Standard Checkpoint Start Recording :
Menu : Automation Record. Hotkey : F3 From toolbar as shown below:
Record
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 28
Insert Standard Checkpoint
Menu : Insert Checkpoint Standard Checkpoint… Hotkey : F12 Toolbar as shown below:
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 29
Insert Standard Checkpoint
With the finger-point select the “Agent Name” WinEdit object.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 30
Insert Standard Checkpoint
Name : Req0002b
enabled = True
text =
Timeout = 2
Except property enabled,
text and focused,
All the other properties
must be Unchecked!!
focused = True
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 31
Implement Req0002b
Anytime you can mark the word Checkpoint and see the checkpoint properties.
Dialog( "Login" ).WinEdit("AgentName").Check CheckPoint( "Req0002b" ) ' ** Req0002
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 32
Implementing Req0002c
Req0002c uses the CheckProperty method of Static object, with argument “visible”, value True
The method will auto-report to Reporter object.
Dialog( "Login" ).Static( "Password" ).CheckProperty "visible", True, 1000 ' ** Req0002c
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 33
Implementing Req0002d
Req0002d uses the CheckProperty method of WinEdit, with argument “enabled” value True, and “text” with value vbNullString ( represents an empty string )
Instead of using checkpoint we can alternatively add 2 CheckProperty methods.
Dialog("Login").WinEdit( "Password" ).CheckProperty "enabled", True, 1000 ' ** Req0002d
Dialog("Login").WinEdit( "Password" ).CheckProperty "text", vbNullString, 1000' ** Req0002d
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 34
Req0002e, Req0002f, Req0002gDialog( "Login" ).WinButton( "OK" ).CheckProperty "enabled", True, 1000 ' ** Req0002e
Dialog( "Login" ).WinButton( "Cancel" ).CheckProperty "enabled", True, 1000 ' ** Req0002f
Dialog( "Login" ).WinButton( "Help" ).CheckProperty "enabled", True, 1000 ' ** Req0002g
The requirement is only to check if they are enabled. don’t check any property that is not required.
The method will auto-report to Reporter object.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 35
Implementing Req002h
After req0002h press ENTER to move to next line.
In the end off the following line press enter Dialog("Login").WinButton("Help").CheckProperty "enabled", True, 1000
Make sure the cursor is on a new blank line, and then start recording.
Before you start recording, make sure dialog Login is displayed. and only one instance of the application is opened.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 36
Inserting a bitmap checkpointSelect Bitmap Checkpoint…
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 37
Inserting a bitmap checkpoint Select The Logo with the finger point. Select the Static and Click OK
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 38
Inserting a bitmap checkpoint Change the name of the checkpoint to “Logo”. Change the checkpoint timeout to 2 seconds. Click OK.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 39
Inserting a bitmap checkpoint
' ** Checking the logo using bitmap checkpoint req0002h
Dialog( "Login" ).Static( "Logo" ).Check CheckPoint( "Logo" )
The checkpoint syntax will be inserted automatically at mentioned location.
STOP recording
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 40
Req0002 ( guiLogin ) – Final Look
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 41
Implement Business Action for Req0002 Open the busLogin test. Select the busLoginMng action. Insert a new test-case after case “req0001”. Use lower-case ( Case “<lower-case>” )
Select Case LCase( Parameter.Item( "busCode" ) )
Case "req0001"
:
Case "req0002"
Case Else
msg = "ActionCode parameter not implemented."
Reporter.ReportEvent micWarning, "NotImplemetedException", msg
ExitAction( micWarning )
End Select
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 42
Business Req0002 implementation According our design [ Process Design – Req0002
] we need to invoke the application and then call the GUI process Req0002, We’ll call InvokeApp function from the test layer
What’s left now, is to call the “Req0002” GUI process located in guiLogin.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 43
busLoginMng – Final Look
As mentioned in previous presentation do not just copy this line of code, a call to an existing reusable action is required.
add the input parameter “Req0002”,while calling the existing action guiLogin.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 44
Create Req0002 Test
Open a new blank test and save it under TESTS\Req0002
Req0002
LIB
RA
TESTS
RS
DOC
FR
DAT
SETTING
RES
BATCH
ENV
Automation
BL
GL
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 45
Test Settings
Modify the test settings…
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 46
Associated function libraries
If you don’t see the LIB\FR.vbs file associated you must to permanently associate the function library; For instructions how to permanently associate function libraries, see previous presentation.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 47
Test Header
'***********************************************************************
'@Author : advancedQTP
'@Date Created : <ddd MMM dd, yyyy>
'@QTP Version : 9.2
'@Description : The test covers the requirement Req0002
'@Input Parameter : None.
'@Out Parameter : None.
'@Ass. Libraries : FR.vbs
'@Addins : ActiveX
'@Modifications : <#n By <Name>, Date: <dd-mmm-yyyy>> (Later modification on top)
' <#n-1 By <Name>, Date: <dd-mmm-yyyy>
'***********************************************************************
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 48
Implementing Test Req0002
The Initialization part is exactly the same for all tests.
Option Explicit
Dim msg
Call Initialization()
If Reporter.RunStatus = micFail Then
msg = "Initialization Process Failed."
Reporter.ReportEvent micFail, Environment( "TestName" ), msg
ExitTest( micFail )
End If
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 49
Implementing Test Req0002
A call to function InvokeApp is required to activate the executable file.
' ** invoking application
Call InvokeApp( Environment.Value( "EXE_FILE" ) )
If Reporter.RunStatus = micFail Then
msg = "Invoke Application Failed."
Reporter.ReportEvent micFail, Environment( "TestName" ), msg
ExitTest( micFail )
End If
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 50
Insert a Call to Existing Action
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 51
Insert a Call to Business Module
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 52
Insert a Call to Existing Action
After the current step
Use relative path
busLoginMng
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 53
Req0002 Test – Final Look
Do not forget to check syntax before closing action
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 54
Result Req0002
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 55
What’s Next?
Implement LoginRegression Test. Req0003. Calling an existing library function. Creating an external data source. Loading an external data source. Create a dynamic standard checkpoint.
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 56
Special Thanks To
Tali Hizkia from Israel, Tel-Aviv. Bharathi Babu from India, Pune. Dalvinder Matharu from USA, San Jose. Mike Manchester from USA, Bolivar
Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 57 57
Make sure to visit us for: Tutorials Articles Projects And much more
@www.AdvancedQTP.com