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.
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.
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.
Write datatable and put dot (.) , It will show you all available methods.
|AddSheet||Adds the specified sheet to Data Table at run time.
|DeleteSheet||Deletes the specified sheet from Data Table at run time.
|Export||Saves a copy of the run-time Data Table in the specified location.
|ExportSheet||Exports a specified sheet of the run-time Data Table to the specified file.
|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.
|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.
|SetNextRow||Sets the row after the current row as the new current row in the run-time Data Table.
|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”
These method will perform the operations or event for a particular datasheet like Global sheet or Action sheet.
|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
|DeleteParameter||Deletes the specified parameter from the sheet in the run-time Data Table.
|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.
we can also set the value for a particular parameter.
|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.
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)
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.
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.
Thank you so much buddy!!! You made so easy to learn and remember in simplest way 🙂