Data Driven Testing
****************************************************** *** ''Test Requirement: Data Driven Testing for Login Operation by fetching Test data directly from a text file 'Pre-requisites: 'Test data file 'Test Flow: 'Create an Automation Object 'open the Test Data file using Automation Object 'Read test data and pass values 'Launch the Application 'Generate Statements for Login Operation 'Form Loop for multiple iterations '************************************************** Option Explicit Dim objFso, myFile, myLine, myField Set objFso=CreateObject("[Link]") Set myFile=[Link]("C:\Documents and Settings\gcreddy\Desktop\[Link]") [Link] Do Until [Link]=True myLine=[Link] myField=Split(myLine,",") [Link] "C:\Program Files\HP\QuickTest Professional\samples\flight\app\[Link]" Dialog("text:=Login").Activate Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set myField(0) Dialog("text:=Login").WinEdit("attached text:=Password:").Set myField(1) Wait (2) Dialog("text:=Login").WinButton("text:=OK").Click Window("text:=Flight Reservation").Close Loop [Link]
Set objFso=Nothing ************************************************************* *
2) 'Data Driven Testing for Login Operation by fetching from an excel file Dim objExcel, myFile, mySheet Set objExcel=CreateObject("[Link]") Set myFile=[Link]("C:\Documents andSettings\gcreddy\Desktop\[Link]") Set mySheet=[Link]("Sheet1") Rows_Count=[Link] For i= 2 to Rows_Count step 1 [Link] "C:\Program Files\HP\QuickTest Professional\samples\flight\app\[Link]" Dialog("text:=Login").Activate Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set [Link](i,"A") Dialog("text:=Login").WinEdit("attached text:=Password:").Set [Link](i,"B") Wait (2) Dialog("text:=Login").WinButton("text:=OK").Click Window("text:=Flight Reservation").Close Next [Link] [Link] Set objExcel=Nothing ************************************************ 3) Data Driven Testing by fetching Test data from a Database Dim objCon, objRs 'Creating an Automation object in Database Connection Class, that can be used to connect to Databases Set objCon=CreateObject("[Link]") 'Creating an Automation object in Database Record set class that can be used toperform operations on DB tables(Records) Set objRs=CreateObject("[Link]") [Link]=("[Link].4.0")' Generating Connection string forMS Access Database [Link] "C:\Documents and Settings\gcreddy\Desktop\[Link]" [Link] "Select * from Login",objCon Do While [Link]=False
[Link] "C:\Program Files\HP\QuickTest Professional\samples\flight\app\[Link]" Dialog("text:=Login").Activate Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set [Link]("Agent") Dialog("text:=Login").WinEdit("attached text:=Password:").Set [Link]("Password") Wait (2) Dialog("text:=Login").WinButton("text:=OK").Click Window("text:=Flight Reservation").Close [Link] Loop [Link] [Link] Set objRs=Nothing Set objCon=Nothing *******************************************************
Data Driven Testing using QTP
'Data Driven Testing for Login Operation by fetching Test Data from anexcel file and Exporting Result to the Same file Dim objExcel, myFile, mySheet Set objExcel=CreateObject("[Link]") Set myFile=[Link]("C:\Documents andSettings\gcreddy\Desktop\[Link]") Set mySheet=[Link]("Sheet1") Rows_Count=[Link] For i= 2 to Rows_Count step 1 [Link] "C:\Program Files\HP\QuickTest Professional\samples\flight\app\[Link]" Dialog("text:=Login").Activate Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set [Link](i,"A") Dialog("text:=Login").WinEdit("attached text:=Password:").Set [Link](i,"B") Wait (2) Dialog("text:=Login").WinButton("text:=OK").Click If Window("text:=Flight Reservation").Exist(12) Then Window("text:=Flight Reservation").Close Result="Login Operation Sucessful" [Link](i,"C")=Result Else [Link] Result="Login Operation Failed" [Link](i,"C")=Result
End If Next [Link] [Link] [Link] Set objExcel=Nothing -----------------------------'Data Driven Testing for Login Operation by fetching Test Data from anexcel file Exporting Result and Error message to the same file ' Dim objExcel, myFile, mySheet Set objExcel=CreateObject("[Link]") Set myFile=[Link]("C:\Documents andSettings\gcreddy\Desktop\[Link]") Set mySheet=[Link]("Sheet1") Rows_Count=[Link] For i= 2 to Rows_Count step 1 [Link] "C:\Program Files\HP\QuickTest Professional\samples\flight\app\[Link]" Dialog("text:=Login").Activate Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set [Link](i,"A") Dialog("text:=Login").WinEdit("attached text:=Password:").Set [Link](i,"B") Wait (2) Dialog("text:=Login").WinButton("text:=OK").Click If Window("text:=Flight Reservation").Exist(12) Then Window("text:=Flight Reservation").Close Result="Login Operation Sucessful" [Link](i,"C")=Result Else Error_Message = Dialog("Login").Dialog("Flight Reservations").Static("Agent name must be at").GetROProperty("text") [Link] Result="Login Operation Failed" [Link](i,"C")=Result [Link](i,"D")=Error_Message End If Next [Link] [Link] [Link] Set objExcel=Nothing