Datatables

Datatable is an in-bulit utility of UFT which is used for parametrizing the data driven test cases. It can be attached with multiple Actions and also run a particular test case with multiple set of data. It looks similar to an excel sheet as shown below. Datatable has 2 types of datasheet.

1. Global Datasheet – Data in the sheet can be accessed across all the actions.
2. Action\Local Datasheet – As the name suggests, sheet created with a particular action.Data in the sheet can be accessed across all the available actions. In practical scenario, generally Action sheet contains the data which need to be passed to that action.

Datasheets


 

You can select the no. of iteration for executing a test case. For that we have to change the ‘Run settings’ by going to ‘File -> Settings – >Run(Tab)’.E.g. Suppose you have 10 rows in the datatable, but you want to execute the test case only for 5 rows ,then you can configure the run settings accordingly.

Runsettings

 


There are 2 types of Datatable.

1. Design time datatable – Datatable which you see in UFT.
2. Run Time datatable – Datatable which is getting used at runtime. We can perform operation at run time and this datatable will be stored in the run result viewer at the end of execution.

Datatable methods:

Write datatable and put dot (.) , It will show you all available methods.

Datatable Methods Description
AddSheet Adds the specified sheet to Data Table at run time.
datatable.AddSheet(strSheetName)
DeleteSheet Deletes the specified sheet from Data Table at run time.
Datatable.DeleteSheet(strSheetName)
Export Saves a copy of the run-time Data Table in the specified location.
Datatable.Export(strFilePath)
ExportSheet Exports a specified sheet of the run-time Data Table to the specified file.
DataTable.ExportSheet(FileName, DTSheet)
GetCurrentRow Returns the current (active) row in the first sheet in the run-time Data Table.
Row = DataTable.GetCurrentRow
GetRowCount Returns the total number of rows in the run-time Data Table.
TotalRow = DataTable.GetRowCount
GetSheet Returns the specified sheet object from the run-time Data Table.
Set Mysheet = DataTable.GetSheet (“MySheet”)
GetSheetCount Returns the total number of sheets in the run-time Data Table.
intSheetCnt = datatable.getSheetCount
Import Imports the specified Microsoft Excel file to Data Table at run time.
Datatable.Import(“Filepath”)
ImportSheet Imports a sheet of a specified file to a specified sheet in the run-time Data Table.
DataTable.ImportSheet(FileName, SheetSource, SheetDest)
SetCurrentRow Sets the specified row as the current row in the run-time Data Table.
DataTable.SetCurrentRow(RowNumber) or
DataTable.GetSheet(“Sheet”).SetCurrentRow(4)
SetNextRow Sets the row after the current row as the new current row in the run-time Data Table.
DataTable.SetNextRow or
DataTable.GetSheet(“desiredSheet”).SetNextRow
GlobalSheet Returns the first sheet in the run-time Data Table which is Global sheet.
DataTable.GlobalSheet.AddParameter “Name”, “Shekhar”
LocalSheet Returns the current (active) local sheet of the run-time Data Table.
DataTable.LocalSheet.AddParameter “Name”, “Shekhar”

Datasheet Methods:
These method will perform the operations or event for a particular datasheet like Global sheet or Action sheet.

Datasheet methods Description
AddParameter Adds the specified parameter (column) to the sheet in Data Table at run time as well as sets the value in that column. It can be done in following ways as shown below
DataTable.GetSheet(“dtGlobalSheet”).AddParameter “Name”,”Shekhar”
DataTable.AddSheet(“MySheet”).AddParameter(“Name”, “Shekhar”)
DeleteParameter Deletes the specified parameter from the sheet in the run-time Data Table.
DataTable.GetSheet(“MySheet”).DeleteParameter(“Name”)
GetCurrentRow Returns the row number of the current row in the run-time Data Table sheet.
row = DataTable.GetSheet(“MySheet”).GetCurrentRow
GetParameter Retrieves the specified parameter from the run-time Data Table sheet.
DataTable.GetSheet(“ActionA”).GetParameter(“Date”).RawValue
we can also set the value for a particular parameter.
DataTable.GetSheet(“Action1”).GetParameter(“Destination”).Value=”Delhi”
GetParameterCount Returns the total number of columns in the run-time Data Table sheet.
Colcount = DataTable.GetSheet(“Action1”).GetParameterCount
GetRowCount Returns the total number of rows in in the run-time Data Table sheet.
rowcount = DataTable.GetSheet(“Action1”).GetRowCount

How to enter data at run time datatable?
Suppose, we have a column called “Name” in the Action2 sheet.Now, we will set the value as “Shekhar” to this.

 Datatable.Value("Name","Action2")= "Shekhar"

How to retrieve the value from datatable?
There are several ways to do that. Let’s see how to retrieve the data.

 msgbox Datatable.Value("Name","Action2")
 msgbox Datatable.Value("Name",3)
 msgbox Datatable("Name","Action2")
 msgbox Datatable("Name",3)

GetValueDatasheet


 

If we have data in Excel sheet, we can import the excel in the following ways.

1. Go to File –>Settings –>Resources –> Select other location’. Browse the file from the system and click Apply.
Attach Datatable

2. Another way is that we can import datatable at run time using import method or any particular sheet using ‘importsheet’ method. These syntaxes are provided above.

Note: Note:
First row in the excel file becomes the column in the datatable. The value starts from second row.
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

1 Response

  1. GK says:

    Thank you so much buddy!!! You made so easy to learn and remember in simplest way 🙂