05_-_Req0002_V3

Download Report

Transcript 05_-_Req0002_V3

Requirement Req0002

Implementation of Requirement Req0002 Dani Vainstein & Monika Arora Gautam 1

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 2

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 3

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 4

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 5

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 6

Req0002 - Overview Details

Label displayed Textbox empty Enabled and focused Label displayed Textbox empty and enabled Command button Enabled.

Logo Command button enabled Command button enabled Dani Vainstein & Monika Arora Gautam 7

Process Design – Req0002

Start

Invoke App Dialog Login Yes InvokeApp Function No

Report micFail Report micFail

Failed Req0002a Passed

Report micPass Report micFail

Failed Req0002h Passed

Report micPass ExitTest End

Dani Vainstein & Monika Arora Gautam 8

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 9

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 10

Analyzing FR Application scenarios invoke

Dialog “Login” Exists

False False True True

Window “Flight Reservation” Exist

False

Activate Executable

True True False True False False

N/A Dani Vainstein & Monika Arora Gautam 11

Activation Conditions

1.

2.

3.

4.

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 12

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 Gautam 13

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 14

InvokeApp Design

Start

Flight Reservation Exists?

No Yes Dialog Login Exists?

Yes No Invoke App Dialog Login Exists?

End

False

End

True

Report micFail End

Dani Vainstein & Monika Arora Gautam False 15

Adding Functionality to existing module

Automation FR LIB RA BL GL RS DOC DAT SETTING TESTS RES BATCH ENV    Open the function library FR.vbs

Menu : File  Open  Function Library Hotkeys : Shift + Alt + O Fr.vbs

Dani Vainstein & Monika Arora Gautam 16

Creating InvokeApp Function

Function Name: InvokeApp Type: Function Scope: Public Description Documentation execVersion By value Dani Vainstein & Monika Arora Gautam 17

InvokeApp – Initialization

'@Description Invokes application flight reservation version xx '@Documentation Invokes application flight reservation 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 18

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 Gautam 19

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 Gautam 20

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 21

InvokeApp Function

If

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 Gautam 22

InvokeApp – Final Look

 Add the function InvokeApp to File library.

  Save the function library You should have 2 functions.

Dani Vainstein & Monika Arora Gautam 23

Creating new step

 Open guiLogin test and add a new step

Case

( remember to write the string in lower case ) “req0002” Dani Vainstein & Monika Arora Gautam 24

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 25

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 26

Inserting a Standard Checkpoint

 Start Recording :    Menu : Automation  Hotkey : F3 Record.

From toolbar as shown below: Record Dani Vainstein & Monika Arora Gautam 27

Insert Standard Checkpoint

   Menu : Insert  Hotkey : F12 Checkpoint Toolbar as shown below:  Standard Checkpoint… Dani Vainstein & Monika Arora Gautam 28

Insert Standard Checkpoint

 With the finger-point select the “Agent Name” WinEdit object.

Dani Vainstein & Monika Arora Gautam 29

Insert Standard Checkpoint

Name : Req0002b enabled = True focused = True text = Timeout = 2 Except property enabled, text and focused, All the other properties must be Unchecked!!

Dani Vainstein & Monika Arora Gautam 30

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 31

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 32

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 33

Req0002e, Req0002f, Req0002g

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   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 34

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 Gautam 35

Inserting a bitmap checkpoint

Select Bitmap Checkpoint… Dani Vainstein & Monika Arora Gautam 36

Inserting a bitmap checkpoint

  Select The Logo with the finger point.

Select the Static and Click OK Dani Vainstein & Monika Arora Gautam 37

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 38

Inserting a bitmap checkpoint

STOP recording ' ** Checking the logo using bitmap checkpoint req0002h Dialog( "Login" ).Static( "Logo" ).Check CheckPoint( " Logo " )  The checkpoint syntax will be inserted automatically at mentioned location.

Dani Vainstein & Monika Arora Gautam 39

Req0002 ( guiLogin ) – Final Look

Dani Vainstein & Monika Arora Gautam 40

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 “” )

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 Gautam 41

Business Req0002 implementation

 

According our design [ Process Design – Req0002

] we need to invoke the application and then call the the test layer GUI process Req0002, We’ll call InvokeApp function from What’s left now, is to call the “Req0002” located in guiLogin.

GUI process Dani Vainstein & Monika Arora Gautam 42

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 43

Create Req0002 Test

Automation FR LIB RA BL GL RS DOC DAT SETTING TESTS RES BATCH ENV  Open a new blank test and save it under TESTS\Req0002 Req0002 Dani Vainstein & Monika Arora Gautam 44

Test Settings

 Modify the test settings… Dani Vainstein & Monika Arora Gautam 45

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 46

Test Header

'*********************************************************************** '@Author : advancedQTP '@Date Created : '@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 , Date: > (Later modification on top) ' <#n-1 By , Date: '*********************************************************************** Dani Vainstein & Monika Arora Gautam 47

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 )

End If

 The Initialization part is exactly the same for all tests.

Dani Vainstein & Monika Arora Gautam 48

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 )

End If

 A call to function InvokeApp is required to activate the executable file.

Dani Vainstein & Monika Arora Gautam 49

Insert a Call to Existing Action

Dani Vainstein & Monika Arora Gautam 50

Insert a Call to Business Module

Dani Vainstein & Monika Arora Gautam 51

Insert a Call to Existing Action

Use relative path busLoginMng After the current step Dani Vainstein & Monika Arora Gautam 52

Req0002 Test – Final Look

Do not forget to check syntax before closing action Dani Vainstein & Monika Arora Gautam 53

Result Req0002

Dani Vainstein & Monika Arora Gautam 54

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 Gautam 55

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 Gautam 56

Make sure to visit us for:

    Tutorials Articles Projects And much more @ www.AdvancedQTP.com

Dani Vainstein & Monika Arora Gautam