Req0003_V5 - WordPress.com

Download Report

Transcript Req0003_V5 - WordPress.com

Requirement - Req0003

Implementation of Requirement Req0003 Dani Vainstein & Monika Arora Gautam 1

Topics covered

    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 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 following :

1 2

Click Dani Vainstein & Monika Arora Gautam 3

Before You Start…

 Before starting the presentation, read about the following topics in QTP help.

  With…End With Statement.

MsgBox Function.

        MsgBox Constants.

PathFinder.Locate Method.

ExitAction Statement.

Parameter Object.

StrComp Function.

DataTable.ImportSheet Method.

CLng, CInt Functions.

Mid Function.

Dani Vainstein & Monika Arora Gautam 4

Requirement Req0003

Dani Vainstein & Monika Arora Gautam 5

Req0003 – Scenario Details

   Step 1 - The user presses OK, without entering any information Step 2  A) Popup dialog is displayed.

   B) Popup title : Flight Reservations C) Message type : Exclamation D) Message text “Please enter agent name” Step 3 – Close the dialog.

Dani Vainstein & Monika Arora Gautam 6

Req0003 – Overview Details

Title = Flight Reservations Icon = Exclamation text = Please enter agent name Displayed And Popup Dani Vainstein & Monika Arora Gautam 7

Process Design – Req0003

Start

Invoke App Dialog Login Yes InvokeApp Function No

Report micFail ExitTest

Dani Vainstein & Monika Arora Gautam Login Press OK

1

8

Process Design – Req0003

Yes Load messages Repository

Report micFail

Failed Req0003b Passed

Report micPass 1

Req0003a?

No

Report micFail Report micFail

Failed Req0003d Passed

Report micPass

Press OK

End

Dani Vainstein & Monika Arora Gautam 9

Process Design – Req0003

     First we need a regular invoke application process ( Already done in InvokeApp function ) Then we need to verify that the invoke app process was done successfully, before accessing the dialog.

If the process failed, it means that the 'Login' dialog was not displayed and hence there’s no point to continue testing.

Then the Req0003 process starts where user leaves all the textboxes blank and hits the [OK] button of 'Login' dialog.

Check if 'Flight Reservation' dialog popped-up -

Req0003a

Dani Vainstein & Monika Arora Gautam 10

Process Design – Req0003

   Load the messages repository   The expected messages will be stored on an MS-Excel datasheet.

We call that datasheet "Messages Repository" Test requirements Req0003b to Req0003d Close the pop-up dialog.

Dani Vainstein & Monika Arora Gautam 11

Implementing Business Req0003

  Open the test busLogin, action busLoginMng Menu : File  Open  Test Dani Vainstein & Monika Arora Gautam 12

Implementing Business Req0003

 Add a new step case “req0003” ( remember to write the string in lower case ) Dani Vainstein & Monika Arora Gautam 13

Implementing Business Req0003

   To generate an error message we have to hit the 'OK' button without entering any data or irrelevant data in 'Login' dialog'.

So we need to implement an “OK” click.

Business layer ( does not actually execute WinButton.Click ) ' ** clicking OK RunAction "guiLogin [guiLogin]" , oneIteration, "OK"  Later, in guiLogin we’re going to actually execute the WinButton( “OK” ).Click action.

Dani Vainstein & Monika Arora Gautam 14

Implementing Business Req0003

 'OK' click will be implemented in the CheckDialog reusable-action, so we add just the call to the existing action.

   Menu : Insert  Call to existing action Select Test guiLogin and reusable-action CheckDialog.

Remember to use the relative path!!

Relative Path Dani Vainstein & Monika Arora Gautam 15

Business Req0003 – Final Look

 Notice that you now have 2 external reusable actions, and 1 internal.

Dani Vainstein & Monika Arora Gautam 16

Implementing OK Step

   Open the guiLogin test, guiLogin reusable-action.

Add the following code.

Case "ok" in lowercase.

Case

"ok" : Dialog( " Login " ).WinButton( " OK " ).Click

Dani Vainstein & Monika Arora Gautam 17

Implementing CheckDialog

1

Yes Req0003a?

No

Report micFail End

Dani Vainstein & Monika Arora Gautam 18

Implementing CheckDialog

' ** Checking if dialog exist.

If

Dialog(" Login ").Dialog(" FlightReservations ").Exist( 1 ) =

False Then

Reporter.ReportEvent micFail, Parameter.Item( " MsgId " ), "Dialog was not found." ExitAction( micFail )

End If

Dialog(" Login ").Dialog(" FlightReservations ").Activate micLeftBtn Dialog(" Login ").Dialog(" FlightReservations ").CheckProperty " ispopupwindow ",

True

, 1000  popup dialog with title “Flight Reservations” should exist, otherwise test fails and cannot continue.

Dani Vainstein & Monika Arora Gautam 19

Implementing CheckDialog

' ** Checking if dialog exist.

If

Dialog(" Login ").Dialog(" FlightReservations ").Exist( 1 ) =

False Then

Reporter.ReportEvent micFail, Parameter( " MsgId " ), "Dialog was not found." ExitAction( micFail )

End If

Dialog(" Login ").Dialog(" FlightReservations ").Activate micLeftBtn Dialog(" Login ").Dialog(" FlightReservations ").CheckProperty " ispopupwindow ",

True

, 1000    If the 'Flight Reservations' dialog exists, we then check if it is a pop up dialog.

In order to check this we use CheckProperty method of Dialog object.

The property “ispopupwindow” will return True if the dialog is a popup window, else False.

Dani Vainstein & Monika Arora Gautam 20

Loading an existing data source

Load messages Repository    Using OO methodology, we separate data from implementation.

We need to load a message repository.

The message repository is an excel datasheet that holds all the system messages.

Dani Vainstein & Monika Arora Gautam 21

Creating an external data source

 Create the following excel datasheet Rename to Messages Dani Vainstein & Monika Arora Gautam 22

Creating an external data source

Automation FR LIB RA BL GL RS DOC DAT SETTING TESTS RES BATCH ENV Dani Vainstein & Monika Arora Gautam FR.xls

23

Load messages headers

   Select the CheckDialog Data Table in QTP.

If you don’t see the CheckDialog Data Table  Menu : View  Data Table Right-click the table join cell.

CheckDialog Dani Vainstein & Monika Arora Gautam 24

Load messages headers

 Select from the popup menu : File  Import  From file.

Dani Vainstein & Monika Arora Gautam CheckDialog 25

Load messages headers

Dani Vainstein & Monika Arora Gautam 26

Messages Datasheet

   ID – Every message has to have a unique identifier ( id ) for this purpose we'll use the custom format MSGxxxx. i.e MSG0043 ( Message No. 43 ) MsgString – The original string on the popup message box.

IconType – a number representing :  16 : vbCritical    32 : vbQuestion 48 : vbExclamation 64 : vbInformation Dani Vainstein & Monika Arora Gautam 27

Messages Datasheet

  TitleString – The original title of the pop-up message.

ButtonId – a number representing :  1 : vbOK  2 : vbCancel      3 : vbAbort 4 : vbRetry 5 : vbIgnore 6 : vbYes 7 : vbNo Dani Vainstein & Monika Arora Gautam 28

CheckDialog Reusable Action

 From Menu  Edit  Action  Action Properties Dani Vainstein & Monika Arora Gautam 29

CheckDialog Reusable Action

 Add input parameter MsgId.

Dani Vainstein & Monika Arora Gautam 30

Insert a new expected message

Dani Vainstein & Monika Arora Gautam 31

Loading the datasheet ( Message Repository )

'** Loading datasheet frXls = PathFinder.Locate( "DAT\FR.xls" )

If

frXls =

vbNullString Then

msg = "FR.xls was not found under DAT folder." Reporter.ReportEvent micWarning, "Loading Datasheet" , msg ExitAction( micWarning )

End If

DataTable.ImportSheet frXls, "Messages" , DataTable.LocalSheet.Name

   If PathFinder.Locate returns the excel path, then the datasheet will be loaded and replace the local sheet.

Every action in QTP has a "Local Sheet" If the excel file was not found, the action is aborted, not the script.

Dani Vainstein & Monika Arora Gautam 32

Find the relevant MsgId

     At this point the datasheet is loaded.

As we continue testing during the project, we’ll have more messages.

To retrieve the particular message from the datasheet, we need the row number.

How do we get the row number?

For this i used a programmatic “trick”.

  The action input parameter ( MsgId ) format is always MSGxxxx, where xxxx is a four digit number ( 0001, 0002 ).

The 4 digit number prefixed with "MSG", will be the message id string.

Dani Vainstein & Monika Arora Gautam 33

Find the relevant MsgId

' ** Retrieving row number rowNo =

CLng

(

Mid

( Parameter.

Item

( " MsgId " ), 4 ) ) DataTable.LocalSheet.SetCurrentRow rowNo    Assuming that “MsgId” = “MSG0001”  Mid( “MSG0001”, 4 )  “0001” Now we convert it to subtype long by using CLng function.

CLng( “0001” )  1 The row number is stored in rowNo variable. Then, we set the working row to rowNo, using SetCurrentRow method.

Dani Vainstein & Monika Arora Gautam 34

Checking the title string

Report micFail

Failed Req0003b Passed

Report micPass Report micFail

Failed Req0003d Passed

Report micPass

Dani Vainstein & Monika Arora Gautam 35

Verification

    At this point we know, that rowNo is 1, and we set the current row to 1.

Before we start accessing the information from row 1, we need to verify that our pointer is in the right “place” We need to verify that column 'ID' from the datasheet, row 1, has the same value of Parameter.Item( "MsgId" ), which in this case will be 'MSG0001'.

So if something went wrong ( you forgot to pass the correct parameter, or forgot to add the MSGxxxx in excel ) the script won’t continue, it will stop and report a warning message.

Dani Vainstein & Monika Arora Gautam 36

Verification - Implementation

   The StrComp function, compares between two string arguments. If the strings are same the return value is 0, otherwise it will be either '-1' or '1'.

For more information please refer to StrComp documentation in QTP help.

The comparison is between the input parameter and the content of ID column.

' ** Data verification

If StrComp

( DataTable( " ID ", dtLocalSheet ), Parameter.

Item

( " MsgId " ) ) <> 0

Then

msg = " Message " & Parameter.

Item

( " MsgId " ) & " was not found." Reporter.ReportEvent micWarning, " ID ", msg ExitAction( micWarning )

End If

Dani Vainstein & Monika Arora Gautam 37

Checking the title string

' ** Checking title using checkProperty checkpoint

If

DataTable( " TitleString ", dtLocalSheet ) <>

vbNullString Then With

Dialog( "Login" ).Dialog( "FlightReservations" ).

.CheckProperty "title", DataTable( "TitleString", dtLocalSheet ), 1000

End With End If

   The If statement provides flexibility to the reusable action. i.e. what if I don’t want to check the title? : no problem, leave it blank in datasheet.

vbNullString represent an empty string in VBScript.

DataTable TitleString is the value in column TitleString .

Dani Vainstein & Monika Arora Gautam 38

Checking the message string

   To check the message string we will use a dynamic standard checkpoint.

Be sure the dialog that contains the text “Please enter agent name” is displayed.

Caution : Only One instance of AUT should be opened while inserting a checkpoint and recording.

   Menu : Automation  Hotkey : F3 Toolbar : Record Record Dani Vainstein & Monika Arora Gautam 39

Inserting a dynamic standard checkpoint

 Insert a standard checkpoint    Menu : Insert  Checkpoint  Hotkey : F12 Toolbar : Standard Checkpoint.

Dani Vainstein & Monika Arora Gautam 40

Inserting a dynamic standard checkpoint

  Put the finger point in the message of Flight Reservations dialog.

In the object selection dialog, just press OK.

Dani Vainstein & Monika Arora Gautam 41

Inserting a dynamic standard checkpoint

Name = Msg Type Text ONLY!!!

Select Parameter Checkpoint timeout = 2 Dani Vainstein & Monika Arora Gautam 42

Inserting a dynamic standard checkpoint

Location in Data Table Current Action sheet Parameter types DataTable Name MsgString Dani Vainstein & Monika Arora Gautam 43

Inserting a dynamic standard checkpoint

DataTable( “MsgString”, dtLocalSheet ) After pressing OK STOP recording!!!

Dani Vainstein & Monika Arora Gautam 44

Checking the Message String

' ** Checking message using standard checkpoint

If

DataTable( " MsgString ", dtLocalSheet ) <>

vbNullString Then

Dialog(" Login ").Dialog(" FlightReservations ").Static(" Msg ").Check CheckPoint(" Msg ")

End If

 The MsgString column is not empty, in case we want to test it. If DataTable statement is required to verify that Dani Vainstein & Monika Arora Gautam 45

Checking The message Type

    The most important part of the checkpoint, is the location within the script in which you will insert it.

After checking the title code line, be sure that the cursor is now on a new blank line, after the MsgString code line.

To start recording, the dialog Login must be displayed. Caution : Only One instance of AUT should be opened while inserting a checkpoint and recording.

Dani Vainstein & Monika Arora Gautam 46

Inserting a bitmap checkpoint

Select Bitmap Checkpoint… Dani Vainstein & Monika Arora Gautam 47

Inserting a bitmap checkpoint

  Select the icon with the finger pointer.

In the “Object Selection” dialog, click OK.

Dani Vainstein & Monika Arora Gautam 48

Inserting a bitmap checkpoint

Name : Exclamation Checkpoint timeout Dani Vainstein & Monika Arora Gautam 49

Inserting a bitmap checkpoint

After pressing OK STOP recording!!!

Dialog(" Login ").Dialog(" FlightReservations ").Static(" Icon ").Check CheckPoint(" Exclamation ")  The Checkpoint command line will be added automatically to the code.

Dani Vainstein & Monika Arora Gautam 50

Checking The message Type

      We have captured a bitmap for an exclamation message type ( vbExclamation or 48 ).

Message Boxes supports 3 more different types – vbInformation (64), vbQuestion (32) and vbCritical (16).

We need to add all the options

*

future implementations.

in this checkpoint for Find in the AUT different messages types, to add the bitmap checkpoints.

Don’t forget to change the checkpoint name.

*Remark

: There's no vbInformation type on Flight Reservation Application.

Dani Vainstein & Monika Arora Gautam 51

Checking The message Type

' ** Checking icon using bitmap checkpoint

If

DataTable( " IconType ", dtLocalSheet ) <>

vbNullString Then Select Case CInt

( DataTable( " IconType ", dtLocalSheet ) )

Case vbExclamation

Dialog("Login").Dialog(" FlightReservations ").Static(" Icon ").Check CheckPoint(" Exclamation ")

Case vbQuestion

Dialog(" Login ").Dialog(" FlightReservations ").Static(" Icon ").Check CheckPoint(" Question ")

Case vbInformation

Dialog(" Login ").Dialog(" FlightReservations ").Static(" Icon ").Check CheckPoint(" Information ")

Case vbCritical

Dialog(" Login ").Dialog(" FlightReservations ").Static(" Icon ").Check CheckPoint(" Critical ")

Case Else

msg = "invalid IconType argument." Reporter.ReportEvent micWarning, Environment(" ActionName "), msg

End Select End If

   IconType column will have a numeric number or will be empty.

After checking that the argument is not empty we convert the string value “16” to value 16.

The conversion is done by the CInt Function.

Dani Vainstein & Monika Arora Gautam 52

Checking The message Type

    We learn to capture the bitmap checkpoint for an exclamation message type (vbExclamation or 48).

There will be 3 more bitmap checkpoints need to covered:  vbInformation ( 64 ), vbQuestion (32) and vbCritical (16).

Add the remaining 3 checkpoints as explained.

Don’t forget to change the checkpoint name.

vbQuestion vbCritical vbExclamation There's no vbInformation type on Flight Reservation Application Dani Vainstein & Monika Arora Gautam 53

Click implementation

    A standard dialog box can have 7 different command buttons.

Our reusable action will have to “deal” with all 7 types, because it is a generic reusable action.

The button we need to press is defined in buttonId column, which is a constant MsgBox number.

For this implementation we will use Descriptive Programming ( DP ).

Dani Vainstein & Monika Arora Gautam 54

Click implementation

' ** Clicking the button if required according ButtonId

If

DataTable( "

With

ButtonId Dialog( " Login ", dtLocalSheet ) <> " ).Dialog( "

vbNullString Then

FlightReservations

Select Case CInt

( DataTable( "ButtonId", dtLocalSheet ) )

Case vbOK

: .WinButton( "text:=OK" ).Click

Case vbCancel Case vbAbort Case vbRetry Case vbIgnore Case vbYes

: .WinButton( "text:=Cancel" : .WinButton( : .WinButton( "text:=Retry" : .WinButton( : .WinButton( " ) "text:=Abort" "text:=Ignore" "text:=Yes"

Case vbNo

: .WinButton( "text:=No"

Case Else

msg = "invalid ButtonId argument." ).Click

).Click

).Click

).Click

).Click

).Click

Reporter.ReportEvent micWarning, Environment( "Action Name"

End Select End With End If

), msg For more information about the button id values see :

Messages Datasheet

Dani Vainstein & Monika Arora Gautam 55

CheckDialog – Final Look ( 1 )

Dani Vainstein & Monika Arora Gautam 56

CheckDialog – Final Look ( 2 )

Dani Vainstein & Monika Arora Gautam 57

CheckDialog – Final Look ( 3 )

Dani Vainstein & Monika Arora Gautam 58

CheckDialog – Final Look ( 4 )

  Don’t forget to activate the Check Syntax feature.

Menu : Tools  Check Syntax or Ctrl + F7 Dani Vainstein & Monika Arora Gautam 59

Create Req0003 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\Req0003 Req0003 Dani Vainstein & Monika Arora Gautam 60

Test Settings

 Modify The Test Settings… Dani Vainstein & Monika Arora Gautam 61

Associated function libraries

 Pls. Verify the associated library relative path is defined in the resources tab. Otherwise see presentation no.5 topic Associating function libraries Dani Vainstein & Monika Arora Gautam 62

Implementing Test Req0003

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 63

Implementing Test Req0003

' ** 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 64

Insert a Call to Existing Action

Dani Vainstein & Monika Arora Gautam 65

Insert a Call to Business Module

Dani Vainstein & Monika Arora Gautam 66

Insert a Call to Existing Action

Use relative path busLogin After the current step Dani Vainstein & Monika Arora Gautam 67

Req0003 Test – Final Look

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

Result Req0003

Dani Vainstein & Monika Arora Gautam 69

What’s Next?

  Creating a Set using Test Batch Runner Utility.

Creating a Set using Mercury Test Manager.

Dani Vainstein & Monika Arora Gautam 70

Special Thanks To

        Tali Hizkia from Israel, Tel-Aviv.

Paul Grossman from USA, Chicago.

Dalvinder Matharu from USA, San Jose.

Mike Manchester from USA, Bolivar.

Joydeep Das from India, Hyderabad.

Prakash Kumar from India, Pune.

Richi Sharma from USA, New Jersey Bharathi Babu from India, Pune Dani Vainstein & Monika Arora Gautam 71

Make sure to visit us for:

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

Dani Vainstein & Monika Arora Gautam