Data Driven Scripts

 Data Driven Testing using QTP
‘Data Driven Testing for Login Operation by fetching Test Data from an excel file and Exporting Result to the Same file
Dim objExcel, myFile, mySheet
Set objExcel=CreateObject(“Excel.Application”)
Set myFile=objExcel.Workbooks.Open(“C:Documents and SettingsgcreddyDesktopdata.xls”)
Set mySheet=myFile.Worksheets(“Sheet1″)
Rows_Count=mySheet.usedrange.rows.count
For i= 2 to Rows_Count step 1
SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”
Dialog(“text:=Login”).Activate
Dialog(“text:=Login”).WinEdit(“attached text:=Agent Name:”).Set mySheet.Cells(i,”A”)
Dialog(“text:=Login”).WinEdit(“attached text:=Password:”).Set mySheet.Cells(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”
mySheet.Cells(i,”C”)=Result
Else
SystemUtil.CloseDescendentProcesses
Result=”Login Operation Failed”
mySheet.Cells(i,”C”)=Result
End If
Next
myFile.Save
myFile.Close
objExcel.Quit
Set objExcel=Nothing
——————————
Data Driven Testing for Login Operation by fetching Test Data from an excel file
‘Exporting Result and Error message to the same file
Dim objExcel, myFile, mySheet
Set objExcel=CreateObject(“Excel.Application”)
Set myFile=objExcel.Workbooks.Open(“C:Documents and SettingsgcreddyDesktopdata.xls”)
Set mySheet=myFile.Worksheets(“Sheet1″)
Rows_Count=mySheet.usedrange.rows.count
For i= 2 to Rows_Count step 1
SystemUtil.Run “C:Program FilesHPQuickTest Professionalsamplesflightappflight4a.exe”
Dialog(“text:=Login”).Activate
Dialog(“text:=Login”).WinEdit(“attached text:=Agent Name:”).Set mySheet.Cells(i,”A”)
Dialog(“text:=Login”).WinEdit(“attached text:=Password:”).Set mySheet.Cells(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”
mySheet.Cells(i,”C”)=Result
Else
Error_Message = Dialog(“Login”).Dialog(“Flight Reservations”).Static(“Agent name must be at”).GetROProperty(“text”)
SystemUtil.CloseDescendentProcesses
Result=”Login Operation Failed”
mySheet.Cells(i,”C”)=Result
mySheet.Cells(i,”D”)=Error_Message
End If
Next
myFile.Save
myFile.Close
objExcel.Quit
Set objExcel=Nothing

 

Comments