ParameterizationTypes of parameterization:We can parameterize tests in several ways in QTP.1. Through Loop Statements2. Dynamic Test Data Submission3. Through Data Table4. Fetching Test Data directly from External files(Flat files & Spreadsheets)5. Fetching Test Data directly from Databases(MSAcess, Oracle etc).6. Getting Test Data from front end objects.
Parameterization1. Through Loop Statements: We can use loop statementsfor passing sequential numbers & Logical Numbers.Note: We can’t generate Strings.For orderno=1 to 10 step 1 for one increment stepkeyword is not mandatoryWindow("Flight Reservation").ActivateWindow("Flight Reservation").WinButton("Button").ClickWindow("Flight Reservation").Dialog("OpenOrder").WinCheckBox("Order No.").Set "ON"Window("Flight Reservation").Dialog("OpenOrder").WinEdit("Edit").Set ordernoWindow("Flight Reservation").Dialog("OpenOrder").WinButton("OK").ClickNext
Parameterization2.Dynamic Test Data Submission: Through Loop Statements we cangive strings also but every time user has to enter data.For x=1 to 3Agent =inputbox("enter an Agent Name")Password=inputbox("enter a password")invokeapplication "C:Program FilesMercury InteractiveQuickTestProfessionalsamplesflightappflight4a.exe"Dialog("Login").ActivateDialog("Login").WinEdit("Agent Name:").Set AgentDialog("Login").WinEdit("Agent Name:").Type micTabDialog("Login").WinEdit("Password:").SetSecure passwordDialog("Login").WinButton("OK").ClickWindow("Flight Reservation").CloseNext
Parameterization3. Through Data Table: QTP adds one data table(Spreadsheet) for every test, we can use DataTable for Data Driven Testing.It has 3 types of usage .a. Entering test data directly into data table and useb. Importing test data from external Flat filesc. Importing test data from external Spread sheetsd. Importing test data from Data bases.
Parameterizationa. Entering test data directly into data table and use.Steps:i) Generate the basic test>open data table(View>Data Table)ii) Click on column header>enter the name of thefield (like this we can create number ofcolumns) > Enter Data>connect the data to test(variable=datatable(“column name”, Sheet id)Example: agent=datatable(“agent”,1)Pass parameters.)iii) Run the test.
Parameterizationb. Importing test data from external files:Open Data Table (view>Data table)>placemouse pointer on data table and rightclick>file>import from file>Click ok>Browswpath of the file (it imports data from the flat file)Connecting Test Data to QTP Test as aboveand run the test.
Parameterizationc. Importing test data from external Spreadsheets:Open Data Table (view>Data table)>place mousepointer on data table and rightclick>file>import from file>Click ok>Browse path ofthe excel sheet (it imports data from the excelsheet)Connecting Test Data to QTP Test as above andrun the test.
Parameterizationd. Importing test data from Data bases:Through Data table we can import Test Data from Databases, but first we have to create /get the DSN(Datasource Name)& we have to use SQL Commands.i) Creating a Test Database: open MS Access (or we canuse any other database).ii) Start programs>MS Office>MS Access>file>new>Select blank Database>enter name of thedatabase>Save with mdb extension.iii) Creating Tables: Select Create table in designview>Enter field name(Agent)and Select data type(text)Like this we can create number of fields>save&entertable name.iv) Entering Data into Tables: Select table>enter thedata.v) Creating DSN & importing data
ParameterizationNavigation:view>data table>Place mouse pointer on Datatable>sheet>import>fromdatabase(Database query wizard opens)>choose ‘specifySQL statements manually>clicknext >click create>click new>select driver type>click next>browse path to store> enterDSN Name>Click Save>click next>clickfinish>select>browse the database& select>clickok>click ok>select DSN>click ok>enter SQL statement(select *from login)>click finish.Note: DSN Creation is one time activity, by using the DSNwe can get data for number oftests.
Parameterization4. Fetching Test Data directly from Flat filesDim fso, myfileSet fso=createobject("scripting.filesystemobject")Set myfile=fso.opentextfile("d:trigun.txt",1)myfile.skiplineWhile myfile.atendofline <> truex=myfile.readlineS=split(x,"@")
ParameterizationFetching Test Data directly from DatabasesOption explicitDim con,rsSet con=createobject("adodb.connection")Set rs=createobject("adodb.recordset")con.provider=("microsoft.jet.oledb.4.0")con.open "C:Documents and SettingspoojaMyDocumentstrigun.mdb"rs.open "select * from login",condo until rs.eof=true
Step GeneratorThe Step Generator enables to add stepseasily, by selecting from a range of context-sensitive options and entering the requiredvalues.User familiar with VBScript, can add andupdate statements and enhance the tests withprogramming.After the test or an Action is recorded, itspower and flexibility can be increased byadding recordable and non- recordableVBScript statements as required for tasks likeCheckpoints, Datatables etc.
Step GeneratorThese additional steps can be added eithermanually or using Insert>Step >StepGenerator.In the Step Generator dialog box steps can bedefined that use:-Test object methods and properties.-Utility object methods and properties.-Calls to library functions, VBScript functions,and internal script functions.
Adding conditional statementsConditional statements enable you to control the flow ofyour Test or component. You use the IF … THEN andELSE statement to incorporate decision-making in yourtests. The IF … THEN statement evaluates whether acondition is true. If the condition is true, the statementsfollowing IF … THEN are executed. If condition is not true,the statementsfollowing the ELSE are executed.If [condition] Then[statement]Else[else statement]End If
Adding conditional statementsif...then...elseif statementif fee="Cash" thenmsgbox "pay cash!"elseif fee="Visa" thenmsgbox "pay with visa."elseif fee="American Express" thenmsgbox "pay with American Express."elsemsgbox "Unknown method of Payment."end If
Custom checkPointsQTP checkpoints are very limiting when itcomes to maintenance and transport ofthe same across scripts. It is always bestto avoid QTP checkpoints wheneverpossible and create your own checkpoint.For doing the custom check points, weuse Reporter.ReportEvent method
Custom checkPointsSyntax is: Reporter.ReportEvent EventStatus, ReportStepName, DetailsThere are 5 EventStatus.micPass – used to display passed events.micFail – used to display Failed events.micDone – No event statusmicWarning – used to display Warning events.micInfo – used to display any information events.
Custom checkPointsReportStepName – Name/Text of node to be shown in the test results tree viewDetails – Text to be shown in the detail column of the report
Custom checkPointsCustom CheckPoints and the Exist MethodThis is an extremely important concept, and it should serve as the base to all CheckPoints. It checks whether an object exists on the page or not, and before we can start verifying an object’s properties, it’s important that we check if it is even available to us to perform our verifications. Also, if the object is found in the applicantion, the Exist method returns true, else, it returns false.Syntax:Object.Exist(Timeout)
Custom checkPointsIn this syntax, Timeout is the amount of time you would like QTP to wait for the object before it returns a boolean output.Case where an object is found.To check if the Text box exists, we can formulate the following code that will wait for a max of 5 seconds before the WebEdit appears on the page:MsgBox Browser("title:=.*Relevant Codes.*").Page("micclass:=Page").WebEdit("name:=txtExistTest").Exist(5)
Custom checkPointsCase where an object is not found.MsgBox Browser("title:=.*Relevant Codes.*").Page("micclass:=Page").WebEdit("name:=txtNotFound").Exist(5) False
Custom checkPointsCustom CheckPoints and the GetROProperty Method.GetROProperty is short for Get- Runtime-Object-Property. In other words, this method can be used to retrieve the value that the object has, at present.Note that, in some dynamic applications, runtime object properties can change on various factors.
Custom checkPointsAlso, with Descriptive Programming (DP), regardless of what property you retrieve, it will always be a runtime property.IfBrowser("title:=.*Relevant.*").WebEdit("name:=t xtMaxLen").GetROProperty("max length")=10 ThenReporter.ReportEvent micPass, "WebEdit MaxLength Text", "Test Passed."ElseReporter.ReportEvent micFail, "WebEdit MaxLength Text", "Test Failed."End If
Custom checkPointsWhen you open your Test Results after the abovestatement executes, you will notice that, the test failed.It will always fail because the maxLength for ourWebEdit is not 10, but 9. When you you use Object spyto retrieve the max length property,you will notice thatit is indeed not 10, but its 9. However, in the real-world,we may not always know the properties these objectswill have at runtime, and most of the times you willcome to find of errors after your regression suitescomplete their execution.
Custom checkPointsLet’s create another CheckPoint, and verify if the Link has the correct color:With Browser("title:=.*Relevant Codes.*").Link("text:=Relevant Codes: Test Color")If .Exist(5) ThenIf .GetROProperty("color") = "#0000ff" ThenReporter.ReportEvent micPass, "RelevantCodes Link", "Correct color."ElseReporter.ReportEvent micFail, "RelevantCodes Link", "Incorrect color."End IfElseReporter.ReportEvent micFail, "RelevantCodes Link", "Link was not found."End IfEnd With
QTP Continued Day4:Report and CommentSplitting ActionVirtual object
QTP Continued Day5:Recovery scenarioOptional stepsFramework ApproachWorking with Dynamic Objects