720 likes | 735 Views
Requirement - Req0003. Implementation of Requirement Req0003. Topics covered. Calling an existing library function. Creating an external data source. Loading an external data source. Create a dynamic standard checkpoint. TIP. Fr Project staff have made an improvement to the presentations.
E N D
Requirement - Req0003 Implementation of Requirement Req0003 Dani Vainstein & Monika Arora Gautam
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
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
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
Requirement Req0003 Dani Vainstein & Monika Arora Gautam
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
Displayed And Popup Req0003 – Overview Details Title = Flight Reservations Icon = Exclamation text = Please enter agent name Dani Vainstein & Monika Arora Gautam
InvokeApp Function Start Invoke App Dialog Login Exists? Yes No Report micFail ExitTest Process Design – Req0003 1 Login Press OK Dani Vainstein & Monika Arora Gautam
Load messages Repository Yes Failed Failed Passed Passed Report micFail Report micFail Report micPass Report micPass Req0003a? Req0003b Req0003d 1 No Report micFail Press OK End Process Design – Req0003 Dani Vainstein & Monika Arora Gautam
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
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
Implementing Business Req0003 • Open the test busLogin, action busLoginMng • Menu : File Open Test Dani Vainstein & Monika Arora Gautam
Implementing Business Req0003 • Add a new step case “req0003” ( remember to write the string in lower case ) Dani Vainstein & Monika Arora Gautam
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
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
Business Req0003 – Final Look • Notice that you now have 2 external reusable actions, and 1 internal. Dani Vainstein & Monika Arora Gautam
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
Yes Req0003a? 1 No Report micFail End Implementing CheckDialog Dani Vainstein & Monika Arora Gautam
Implementing CheckDialog ' ** Checking if dialog exist. If Dialog("Login").Dialog("FlightReservations").Exist( 1 ) = FalseThen Reporter.ReportEvent micFail, Parameter.Item( "MsgId" ), "Dialog was not found." ExitAction( micFail ) EndIf 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
Implementing CheckDialog ' ** Checking if dialog exist. If Dialog("Login").Dialog("FlightReservations").Exist( 1 ) = FalseThen Reporter.ReportEvent micFail, Parameter( "MsgId" ), "Dialog was not found." ExitAction( micFail ) EndIf 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
Load messages Repository Loading an existing data source • 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
Creating an external data source • Create the following excel datasheet Rename to Messages Dani Vainstein & Monika Arora Gautam
Automation FR LIB RA BL GL RS DOC DAT SETTING TESTS RES BATCH ENV Creating an external data source FR.xls Dani Vainstein & Monika Arora Gautam
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
Load messages headers • Select from the popup menu : File Import From file. CheckDialog Dani Vainstein & Monika Arora Gautam
Load messages headers Dani Vainstein & Monika Arora Gautam
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
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
CheckDialog Reusable Action • From Menu Edit Action Action Properties Dani Vainstein & Monika Arora Gautam
CheckDialog Reusable Action • Add input parameter MsgId. Dani Vainstein & Monika Arora Gautam
Insert a new expected message Dani Vainstein & Monika Arora Gautam
Loading the datasheet ( Message Repository ) '** Loading datasheet frXls = PathFinder.Locate( "DAT\FR.xls" ) If frXls = vbNullStringThen msg = "FR.xls was not found under DAT folder." Reporter.ReportEvent micWarning, "Loading Datasheet", msg ExitAction( micWarning ) EndIf 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
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
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
Failed Failed Passed Passed Report micFail Report micFail Report micPass Report micPass Req0003b Req0003d Checking the title string Dani Vainstein & Monika Arora Gautam
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
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 IfStrComp( DataTable( "ID", dtLocalSheet ), Parameter.Item( "MsgId" ) ) <> 0 Then msg = "Message " & Parameter.Item( "MsgId" ) & " was not found." Reporter.ReportEvent micWarning, "ID", msg ExitAction( micWarning ) EndIf Dani Vainstein & Monika Arora Gautam
Checking the title string ' ** Checking title using checkProperty checkpoint If DataTable( "TitleString", dtLocalSheet ) <> vbNullStringThen With Dialog( "Login" ).Dialog( "FlightReservations" ). .CheckProperty "title", DataTable( "TitleString", dtLocalSheet ), 1000 EndWith EndIf • 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 valuein column TitleString. Dani Vainstein & Monika Arora Gautam
Record 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 : Dani Vainstein & Monika Arora Gautam
Inserting a dynamic standard checkpoint • Insert a standard checkpoint • Menu : Insert Checkpoint Standard Checkpoint. • Hotkey : F12 • Toolbar : Dani Vainstein & Monika Arora Gautam
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
Inserting a dynamic standard checkpoint Name = Msg Type Text ONLY!!! Select Parameter Checkpoint timeout = 2 Dani Vainstein & Monika Arora Gautam
Parameter types DataTable Location in Data Table Current Action sheet Name MsgString Inserting a dynamic standard checkpoint Dani Vainstein & Monika Arora Gautam
Inserting a dynamic standard checkpoint DataTable( “MsgString”, dtLocalSheet ) After pressing OK STOP recording!!! Dani Vainstein & Monika Arora Gautam
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 ) <> vbNullStringThen Dialog("Login").Dialog("FlightReservations").Static("Msg").Check CheckPoint("Msg") EndIf Dani Vainstein & Monika Arora Gautam
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
Inserting a bitmap checkpoint Select Bitmap Checkpoint… Dani Vainstein & Monika Arora Gautam
Inserting a bitmap checkpoint • Select the icon with the finger pointer. • In the “Object Selection” dialog, click OK. Dani Vainstein & Monika Arora Gautam
Inserting a bitmap checkpoint Name : Exclamation Checkpoint timeout Dani Vainstein & Monika Arora Gautam
Dialog("Login").Dialog("FlightReservations").Static("Icon").Check CheckPoint("Exclamation") Inserting a bitmap checkpoint After pressing OK STOP recording!!! • The Checkpoint command line will be added automatically to the code. Dani Vainstein & Monika Arora Gautam