570 likes | 654 Views
Requirement Req0002. Implementation of Requirement Req0002. 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. 2. Click. Topics covered.
E N D
Requirement Req0002 Implementation of Requirement Req0002 Dani Vainstein & Monika Arora Gautam
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 2 Click Dani Vainstein & Monika Arora Gautam
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 Gautam
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 Gautam
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 Gautam
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 Gautam
Req0002 - Overview Details Label displayed Logo Textbox empty Enabled and focused Label displayed Textbox empty and enabled Command button Enabled. Command button enabled Command button enabled Dani Vainstein & Monika Arora Gautam
Failed Failed Passed Passed Report micFail Report micFail Report micPass Report micPass Req0002a Req0002h Process Design – Req0002 InvokeApp Function Start Invoke App Dialog Login Exists? Yes No Report micFail ExitTest End Dani Vainstein & Monika Arora Gautam
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 Gautam
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 Gautam
Analyzing FR Application scenarios invoke Dani Vainstein & Monika Arora Gautam
Activation Conditions • If “Flight Reservation” (main) main window is already displayed, don’t activate the executable file. We want to avoid multiple application instances. • If the “Login” dialog is already displayed, don’t activate. We want to avoid multiple application instances. • If “Login” dialog is NOT displayed AND the “FlightReservation” window is NOT displayed activate Flight4x.exe. • 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 Gautam
Avoid This!!! 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. Dani Vainstein & Monika Arora Gautam
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 Gautam
<version> Start Dialog Login Exists? Flight Reservation Exists? No No Invoke App Yes Dialog Login Exists? Yes Report micFail End End End False False True InvokeApp Design Dani Vainstein & Monika Arora Gautam
Automation FR LIB RA BL GL RS DOC DAT SETTING Fr.vbs TESTS RES BATCH ENV Adding Functionality to existing module • Open the function library FR.vbs • Menu : File Open Function Library • Hotkeys : Shift + Alt + O Dani Vainstein & Monika Arora Gautam
Creating InvokeApp Function execVersion By value Function Name: InvokeApp Type: Function Scope: Public Description Documentation Dani Vainstein & Monika Arora Gautam
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 Gautam
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 ExitFunction EndIf • 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 Gautam
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 ExitFunction EndIf • If the “Login” dialog exists, the dialog will be activated and a general message will sent to the Reporter. Dani Vainstein & Monika Arora Gautam
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 Gautam
InvokeApp Function If Dialog( "text:=Login","nativeclass:=#32770" ).Exist( 5 ) = FalseThen msg = "Dialog 'Login' is not displayed after 5 seconds." Reporter.ReportEvent micFail, "ApplicationException", msg ExitFunction EndIf 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 Gautam
InvokeApp – Final Look • Add the function InvokeApp to File library. • Save the function library • You should have 2 functions. Dani Vainstein & Monika Arora Gautam
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 Gautam
Implementing Req0002a Dialog( "Login" ).Static( "AgentName" ).CheckProperty "visible", True, 1000 ' ** Req0002a • Req0002a uses the CheckProperty method of static, with argument “visible”, value True • The method will auto-report to Reporter object. Dani Vainstein & Monika Arora Gautam
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 Gautam
Record Inserting a Standard Checkpoint • Start Recording : • Menu : Automation Record. • Hotkey : F3 • From toolbar as shown below: Dani Vainstein & Monika Arora Gautam
Insert Standard Checkpoint • Menu : Insert Checkpoint Standard Checkpoint… • Hotkey : F12 • Toolbar as shown below: Dani Vainstein & Monika Arora Gautam
Insert Standard Checkpoint • With the finger-point select the “Agent Name” WinEdit object. Dani Vainstein & Monika Arora Gautam
Insert Standard Checkpoint Name : Req0002b Except property enabled, text and focused, All the other properties must be Unchecked!! enabled = True focused = True text = Timeout = 2 Dani Vainstein & Monika Arora Gautam
Implement Req0002b Dialog( "Login" ).WinEdit("AgentName").Check CheckPoint( "Req0002b" ) ' ** Req0002 • Anytime you can mark the word Checkpoint and see the checkpoint properties. Dani Vainstein & Monika Arora Gautam
Implementing Req0002c Dialog( "Login" ).Static( "Password" ).CheckProperty "visible", True, 1000 ' ** Req0002c • Req0002c uses the CheckProperty method of Static object, with argument “visible”, value True • The method will auto-report to Reporter object. Dani Vainstein & Monika Arora Gautam
Implementing Req0002d Dialog("Login").WinEdit( "Password" ).CheckProperty "enabled", True, 1000 ' ** Req0002d Dialog("Login").WinEdit( "Password" ).CheckProperty "text", vbNullString, 1000' ** 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. Dani Vainstein & Monika Arora Gautam
Dialog( "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 Req0002e, Req0002f, 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 Gautam
Implementing Req002h • After req0002h press ENTER to move to next line. • In the end off the following line press enterDialog("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 Gautam
Inserting a bitmap checkpoint Select Bitmap Checkpoint… Dani Vainstein & Monika Arora Gautam
Inserting a bitmap checkpoint • Select The Logo with the finger point. • Select the Static and Click OK Dani Vainstein & Monika Arora Gautam
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 Gautam
' ** Checking the logo using bitmap checkpoint req0002h Dialog( "Login" ).Static( "Logo" ).Check CheckPoint( "Logo" ) Inserting a bitmap checkpoint STOP recording • The checkpoint syntax will be inserted automatically at mentioned location. Dani Vainstein & Monika Arora Gautam
Req0002 ( guiLogin ) – Final Look Dani Vainstein & Monika Arora Gautam
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>” ) SelectCaseLCase( Parameter.Item( "busCode" ) ) Case "req0001" : Case "req0002" CaseElse msg = "ActionCode parameter not implemented." Reporter.ReportEvent micWarning, "NotImplemetedException", msg ExitAction( micWarning ) EndSelect Dani Vainstein & Monika Arora Gautam
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 Gautam
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 Gautam
Automation FR LIB RA BL GL RS DOC DAT SETTING Req0002 TESTS RES BATCH ENV Create Req0002 Test • Open a new blank test and save it under TESTS\Req0002 Dani Vainstein & Monika Arora Gautam
Test Settings • Modify the test settings… Dani Vainstein & Monika Arora Gautam
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 Gautam
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 Gautam
Implementing Test Req0002 Option Explicit Dim msg Call Initialization() If Reporter.RunStatus = micFail Then msg = "Initialization Process Failed." Reporter.ReportEvent micFail, Environment( "TestName" ), msg ExitTest( micFail ) EndIf • The Initialization part is exactly the same for all tests. Dani Vainstein & Monika Arora Gautam
Implementing Test Req0002 ' ** 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 ) EndIf • A call to function InvokeApp is required to activate the executable file. Dani Vainstein & Monika Arora Gautam
Insert a Call to Existing Action Dani Vainstein & Monika Arora Gautam