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 Settings\gcreddy\Desktop\data.xls")
Set mySheet=myFile.Worksheets("Sheet1")
Rows_Count=mySheet.usedrange.rows.count

For i= 2 to Rows_Count step 1
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.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 Settings\gcreddy\Desktop\data.xls")
Set mySheet=myFile.Worksheets("Sheet1")
Rows_Count=mySheet.usedrange.rows.count

For i= 2 to Rows_Count step 1
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.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

2 comments:

it is really great artical,thank you so much for providing this information,it is very useful for us,pls provide keyword driven framework with explanatation.

Hi,Im novice ,have been practicing testing fore the past 1 yr ,can u send me relevant docs ,materials for automation testing using QTP.

Post a Comment