Search here for all the info you want in this Blog

Data Driven Test

In order to test an application with multiple sets of test data, we need to parametrize the script. And the multiple test data can be drive through an excel sheet called data table.

In order to create a DDT, first we need to create a basic script on the application either by recording or manually writing/ generated. Then we can parametrize the script using the “Data Driver Wizard” or “Data Table Object Methods”.
The test data should be available in the data table to execute a DDT.

Steps to create a DDT using Data Driver Wizard:
1.Create basic script on the application
2.Select Tools --> Data Driver (it automatically displays the values which needs to be parametrized)
3.Select a value to be parametrized & click on parameter button
4.Click on Next --> Click on Parameter options button
5.Provide the parameter name
6.Select the location in the data table as Global sheet
7.Click on OK --> Click on Finish
8.Repeat the above steps for each value to be parametrized

Eg: Window(“Form1”).VbEdit(“Text1”).Set datatable(“num1,dtglobalsheet)
Window(“Form1”).VbEdit(“Text2”).Set datatable(“num2,dtglobalsheet)
Window(“Form1”).VbButton(“Add”).Click

Logic behind DDT:
When we execute a DDT
1. It counts the number of records in the data table
2. It forms a loop internally with the record s count from the data table
3. For each iteration the corresponding record is selected from the data table
4. For each selected record, it will execute all the parametrized values.
Steps to edit data table iteration option:
1. Select File --> Settings
2. Click on num tab
3. Select the required data table iteration option
4. Click on Apply & OK.

Eg:
Invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set DataTable("Uid", dtGlobalSheet)
Dialog("Login").WinEdit("Password:").Set DataTable("Pwd", dtGlobalSheet)
Dialog("Login").WinButton("OK").Click
If Window("Flight Reservation").Exist Then
Window("Flight Reservation").Close
Invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End If
If Dialog("Login").Dialog("Flight Reservations").Exist Then
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
If Dialog("Login").Dialog("Flight Reservations").Exist Then
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
End If
If Dialog("Login").Exist<>true Then
Invokeapplication "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
End If
End If



Data Table Object Methods


AddSheet: This method is used to add a new sheet to the data table.
Syntax: DataTable.AddSheet(“Sheet Name”)
Eg: DataTable.AddSheet(“MySheet”)
Note: All the methods of data table object will have impact only during Runtime

DeleteSheet: This method is used to delete a sheet from the data table.
Syntax: DataTable.DeleteSheet(“” or )
Eg: DataTable.DeleteSheet(“Global”)
(OR) DataTable.DeleteSheet(1)

Import: This method is used to import the contents of an excel file into data table. While importing from an excel file we need to ensure the following things:
1.The number of sheets in excel file & in data table should be equal or more.
2.The sheet names may not be same. (We can modify the sheet names after importing)
3.The parameters names should be same.
Syntax: DataTable.Import(“”)
Eg: DataTable.Import(“D:\QTP\input.xls”)
Steps to import the data manually:
1.Right click --> Import from file --> Click on OK
3.Select the file name from which the data needs to be imported
4.Click on Open

ImportSheet: This method is used to import the data from the specific sheet of the excel file to the specific sheet of the data table.
Syntax: DataTable.ImportSheet “”,
Eg: DataTable.ImportSheet “D:\QTP\input.xls”,2,1

Steps to import manually:
1.Right click in the required sheet of data table
2.Select Sheet --> Import --> From File --> Click on OK
3.Select the required file from which the data needs to be imported
4.Select the required sheet name from the dropdown
5.Click on OK

Export: This method is used to export the contents of the data table to an excel file. Even if the file is not available, it will create the file & export. If the file is available it will over ride.
Syntax: DataTable.Export(“”)
Eg: DataTable.Export(“D:\QTP\output.xls”)

Steps to export manually:
1.Right click in the data table
2.Select File --> Export
3.Provide the File Name --> Click on Save

ExportSheet: 
This method is used to export the contents of a specific sheet of the data table to the excel file.
Syntax: DataTable.ExportSheet “”,
Eg: DataTable. ExportSheet “D:\QTP\output.xls”,2

Steps to import manually:
1.Right click in the required sheet of data table
2.Select Sheet --> Export
3.Provide the File Name --> Click on Save

GetCurrentRow: This method is used to identify the current active row number
Eg: ActRow=DataTable.GetCurrentRow
msgbox ActRow

GetRowCount: This method is used to get the number of records available in the data table.
Eg: RowCnt=DataTable.GetRowCount
msgbox RowCnt
Note: Methods like GetCurrentRow, GetRowCount, etc defaultly works on global sheets.


LocalSheet: 
This method is used to work with the corresponding local sheet from which action we execute the script.
Eg: RowCnt=DataTable.LocalSheet.GetRowCount
msgbox RowCnt

GetSheetCount: This method is used to get the number of sheets available in the data table.
Eg: SheetCnt=DataTable.GetSheetCount
msgbox SheetCnt

SetCurrentRow: This method is used to set the focus to the specified row of the ‘data table-global sheet’.
Syntax: Datatable.SetCurrentRow()
Eg: Datatable.SetCurrentRow(17)

SetNextRow: This method is used to set the focus to the immediate next row of the current active row.
Syntax: DataTable.SetNextRow

SetPrevRow: This method is used to set the focus to the previous row of the current active row.
Syntax: DataTable.SetPrevRow

Value: This method is used for 2 purposes.
1. To read the value from the data table.
Syntax: Val=DataTable.Value(“”,“”)
Eg: Val=DataTable.Value(“Num1”,2)
msgbox Val
Note: We will not define the row number. By default it will pick the value of the current focus row.

2. To write the value into the data table.
Syntax: DataTable.Value(“”,“”)= “Value”
Eg: DataTable.Value(“Result”,”Action1”)=“Pass”
(OR) DataTable.Value(3,2)=“Pass”

Script to perform DDT manually:

DataTable.Import("D:\Practise\QTP Testing\input.xls")
RC=DataTable.GetRowCount
msgbox RC
For i=1 to RC
DataTable.SetCurrentRow(i)
VbWindow(“VbWindow”).VbEdit(“VbEdit”).SetDataTable.Value (“num1”,1)
VbWindow(“VbWindow”).VbEdit(“VbEdit_2”).SetDataTable.Value(“num2”,dtGlobalSheet)
VbWindow(“VbWindow”).VbButton(“Add”).Click
ExpVal=Datatable.Value(“ExpRes”,1)
ActVal=VbWindow(“VbWindow”).VbEdit(“VbEdit_3”).GetROProperty(“text”)
DataTable.Value(“ActRes”,1)=ActVal
If ExpVal=ActVal Then
DataTable.Value(“Result”,1)=”Pass”
Else
DataTable.Value(“Result”,1)=”Fail”
End If
Next
DataTable.Export(“D:\Practise\QTP Testing\output.xls”)

No comments:

Post a Comment