0% found this document useful (0 votes)
33 views

Data Driven Testing

The document discusses different approaches to data-driven testing using QuickTest Professional (QTP). It describes fetching test data from external files like text files, Excel files and databases to perform login operations on an application. The key approaches are: 1. Reading test data from a text file and looping through the data to perform multiple login attempts. 2. Similar to #1 but reading data from an Excel file instead of text file. 3. Connecting to an Access database, retrieving test data from tables and looping through the records. 4. Enhancing #2 to export test results and error messages back to the Excel file after each iteration.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Data Driven Testing

The document discusses different approaches to data-driven testing using QuickTest Professional (QTP). It describes fetching test data from external files like text files, Excel files and databases to perform login operations on an application. The key approaches are: 1. Reading test data from a text file and looping through the data to perform multiple login attempts. 2. Similar to #1 but reading data from an Excel file instead of text file. 3. Connecting to an Access database, retrieving test data from tables and looping through the records. 4. Enhancing #2 to export test results and error messages back to the Excel file after each iteration.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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("Scripting.FileSystemObject") Set myFile=objFso.OpenTextFile("C:\Documents and Settings\gcreddy\Desktop\gcreddy.txt") myFile.SkipLine Do Until myFile.AtEndOfStream=True myLine=myFile.ReadLine myField=Split(myLine,",") 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 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 myFile.Close

Set objFso=Nothing ************************************************************* *


2) 'Data Driven Testing for Login Operation by fetching from an excel file Dim objExcel, myFile, mySheet Set objExcel=CreateObject("Excel.Application") Set myFile=objExcel.Workbooks.Open("C:\Documents andSettings\gcreddy\Desktop\gcreddy.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 Window("text:=Flight Reservation").Close Next myFile.Close objExcel.Quit 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("Adodb.Connection") 'Creating an Automation object in Database Record set class that can be used toperform operations on DB tables(Records) Set objRs=CreateObject("Adodb.RecordSet") objCon.Provider=("Microsoft.Jet.OLEDB.4.0")' Generating Connection string forMS Access Database objCon.Open "C:\Documents and Settings\gcreddy\Desktop\gcreddy.mdb" objRs.Open "Select * from Login",objCon Do While objRs.EOF=False

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 objRs.Fields("Agent") Dialog("text:=Login").WinEdit("attached text:=Password:").Set objRs.Fields("Password") Wait (2) Dialog("text:=Login").WinButton("text:=OK").Click Window("text:=Flight Reservation").Close objRs.MoveNext Loop objRs.Close objCon.Close 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("Excel.Application") Set myFile=objExcel.Workbooks.Open("C:\Documents andSettings\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 anexcel 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 andSettings\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

You might also like