Dani Vainstein & Monika Arora Gautam 1 Requirement - Req0003 Implementation of Requirement...

Preview:

Citation preview

Dani Vainstein & Monika Arora GauDani Vainstein & Monika Arora Gautamtam

1

Requirement - Req0003

Implementation of Requirement Req0003

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 2

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 GautamDani Vainstein & Monika Arora Gautam 3

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

2Click

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. 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 GautamDani Vainstein & Monika Arora Gautam 5

Requirement Req0003

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 6

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 GautamDani Vainstein & Monika Arora Gautam 7

Req0003 – Overview Details

Title = Flight Reservations

Icon = Exclamation

text =

Please enter agent name

Displayed

And Popup

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 8

Process Design – Req0003

Login Press OK 1

No

DialogLogin

Exists?

ExitTest

Yes

ReportmicFail

Invoke App

Start

InvokeApp FunctionInvokeApp Function

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 9

Process Design – Req0003

No

Req0003a?

Yes

ReportmicFail

End

Req0003b

PassedFailedReportmicFail

ReportmicPass

Req0003d

PassedFailedReportmicFail

ReportmicPass

Press OK

Load message

s

Repository

1

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 10

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 GautamDani Vainstein & Monika Arora Gautam 11

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 GautamDani Vainstein & Monika Arora Gautam 12

Implementing Business Req0003 Open the test busLogin, action busLoginMng Menu : File Open Test

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 13

Implementing Business Req0003 Add a new step case “req0003” ( remember to

write the string in lower case )

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 14

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 GautamDani Vainstein & Monika Arora Gautam 15

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 GautamDani Vainstein & Monika Arora Gautam 16

Business Req0003 – Final Look

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

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 17

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 GautamDani Vainstein & Monika Arora Gautam 18

Implementing CheckDialog

No

Req0003a?

Yes

ReportmicFail

End

1

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 19

Implementing CheckDialog

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

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

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 20

Implementing CheckDialog

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.

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

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 21

Loading an existing data source

Load message

s

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 GautamDani Vainstein & Monika Arora Gautam 22

Creating an external data source Create the following excel datasheet

Rename to Messages

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 23

Creating an external data source

LIB

RA

TESTS

RS

DOC

FR

DAT

SETTING

RES

BATCH

ENV

Automation

BL

GL

FR.xls

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 24

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 GautamDani Vainstein & Monika Arora Gautam 25

Load messages headers

Select from the popup menu : File Import From file.

CheckDialog

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 26

Load messages headers

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 27

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 GautamDani Vainstein & Monika Arora Gautam 28

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 GautamDani Vainstein & Monika Arora Gautam 29

CheckDialog Reusable Action

From Menu Edit Action Action Properties

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 30

CheckDialog Reusable Action

Add input parameter MsgId.

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 31

Insert a new expected message

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 32

Loading the datasheet ( Message Repository )

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.

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

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 33

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 GautamDani Vainstein & Monika Arora Gautam 34

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 GautamDani Vainstein & Monika Arora Gautam 35

Checking the title string

Req0003b

PassedFailedReportmicFail

ReportmicPass

Req0003d

PassedFailedReportmicFail

ReportmicPass

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 36

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 GautamDani Vainstein & Monika Arora Gautam 37

Verification - Implementation

' ** Data verificationIf 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

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.

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 38

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 GautamDani Vainstein & Monika Arora Gautam 39

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 Record Hotkey : F3 Toolbar :

Record

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 40

Inserting a dynamic standard checkpoint Insert a standard checkpoint

Menu : Insert Checkpoint Standard Checkpoint. Hotkey : F12 Toolbar :

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 41

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 GautamDani Vainstein & Monika Arora Gautam 42

Inserting a dynamic standard checkpoint

Type

Text ONLY!!!

Select Parameter

Name = Msg

Checkpoint timeout = 2

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 43

Inserting a dynamic standard checkpoint

Parameter types

DataTable

Name

MsgString

Location in Data Table

Current Action sheet

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 44

Inserting a dynamic standard checkpoint

DataTable( “MsgString”, dtLocalSheet )

After pressing OK

STOP recording!!!

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 45

Checking the Message String

The If DataTable statement is required to verify that MsgString column is not empty, in case we want to test it.

' ** Checking message using standard checkpoint

If DataTable( "MsgString", dtLocalSheet ) <> vbNullString Then

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

End If

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 46

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 GautamDani Vainstein & Monika Arora Gautam 47

Inserting a bitmap checkpointSelect Bitmap Checkpoint…

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 48

Inserting a bitmap checkpoint Select the icon with the finger pointer. In the “Object Selection” dialog, click OK.

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 49

Inserting a bitmap checkpoint

Name : Exclamation

Checkpoint timeout

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 50

Inserting a bitmap checkpoint

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

The Checkpoint command line will be added automatically to the code.

After pressing OK

STOP recording!!!

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 51

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* in this checkpoint for future implementations.

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 GautamDani Vainstein & Monika Arora Gautam 52

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 GautamDani Vainstein & Monika Arora Gautam 53

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.

There's no vbInformation type on

Flight Reservation Application

vbExclamation vbQuestion vbCritical

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 54

Click <buttonId> 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 GautamDani Vainstein & Monika Arora Gautam 55

Click <buttonId> implementation' ** Clicking the button if required according ButtonId

If DataTable( "ButtonId", dtLocalSheet ) <> vbNullString Then

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

Select Case CInt( DataTable( "ButtonId", dtLocalSheet ) )

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

Case vbCancel : .WinButton( "text:=Cancel" ).Click

Case vbAbort : .WinButton( "text:=Abort" ).Click

Case vbRetry : .WinButton( "text:=Retry" ).Click

Case vbIgnore : .WinButton( "text:=Ignore" ).Click

Case vbYes : .WinButton( "text:=Yes" ).Click

Case vbNo : .WinButton( "text:=No" ).Click

Case Else

msg = "invalid ButtonId argument."

Reporter.ReportEvent micWarning, Environment( "Action Name" ), msg

End Select

End With

End If

For more information about the button id values see : Messages Datasheet

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 56

CheckDialog – Final Look ( 1 )

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 57

CheckDialog – Final Look ( 2 )

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 58

CheckDialog – Final Look ( 3 )

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 59

CheckDialog – Final Look ( 4 )

Don’t forget to activate the Check Syntax feature. Menu : Tools Check Syntax or Ctrl + F7

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 60

Create Req0003 Test

Open a new blank Test and save it under Tests\Req0003

Req0003

LIB

RA

TESTS

RS

DOC

FR

DAT

SETTING

RES

BATCH

ENV

Automation

BL

GL

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 61

Test Settings

Modify The Test Settings…

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 62

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 GautamDani Vainstein & Monika Arora Gautam 63

Implementing Test Req0003

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 64

Implementing Test Req0003

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 65

Insert a Call to Existing Action

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 66

Insert a Call to Business Module

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 67

Insert a Call to Existing Action

After the current step

Use relative path

busLogin

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 68

Req0003 Test – Final Look

Do not forget to check syntax before closing action

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 69

Result Req0003

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 70

What’s Next?

Creating a Set using Test Batch Runner Utility.

Creating a Set using Mercury Test Manager.

Dani Vainstein & Monika Arora GautamDani Vainstein & Monika Arora Gautam 71

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 GautamDani Vainstein & Monika Arora Gautam 72 72

Make sure to visit us for: Tutorials Articles Projects And much more

@www.AdvancedQTP.com