Datatable in UFT.
What is Datatable?
Datatable plays a critical role while executing the automation scripts, it is just like an Microsoft Excel file, which is integrated with UFT.
Let’s understand Datatable in this way, suppose you have a requirement where you want to check the 100 different login for the application.
Now you have 2 choices:-
1.Create 100 Test scripts for 100 different user’si.e. hard code the value of the login details in the script itself.
2.Paste all the login details into the datatable and Create 1 Test script, do the configuration in the test script in such a way that each time it will retrieve the login details from datatable i.e. 1 to 100.
I hope you all agreed with me that the first approach is not at all good to use, due to following disadvantages:-
1.Same code for 100 test scripts will be the same except the login details.
2.High code redundancy or duplicity.
3.The biggest disadvantage is “Code Maintenance”, let’s say that there is a change in one of the steps in the script then to apply this change, I need to open all the test script and do the changes which will take lot of time.
All the above disadvantage you will not find if you opt for 2nd choice.
I hope that now you will be able to the following question:-
1.Why we use datatable?
2.What is the need of datatable?
3.Advantage of using datatable?
Points to remember:-
Datatable is used when we want to check the scripts with multiple set of data values then we use datatable.
The DataTable contains a global sheet and a separate sheet for each action in the test. So here we have two types of sheets in data table.
1. Global sheet: - is the sheet which is available to all the actions in a test.
2. Local sheet: - is available to the corresponding actions.
Points to remember:-
You can add “n” number of actions in one test and when it got added 2 things happen, you get a test pane and a new sheet which will be added in the datatable for that action.
It is recommended that for
Global Sheet: -Keep only those data which can be used across all the actions.
Local Sheet: -Keep only those data which can be used across all the actions.
Types of DataTable:
Design Time DataTable: While creating/editing the test scripts, you enter data directly in the data table displayed. If it is not displayed then select View >> Data Table option in UFT. This will show you the data table at the bottom, that datatable is called Design Time DataTable.
Runtime DataTable: The data table used while running the test is called Runtime DataTable. The data in the runtime data table may be same as design time data table and/or can be entered by importing data from excel sheet, text file etc. The runtime data table can be seen in the Test Results window when run session is ended.
DataTable Parameter:
Each column in global/local sheet of datatable is called a Parameter. We can rename the parameter just by double clicking on the column header and giving the name to it. Data can be entered in the column/parameter simply by clicking on the cell and entering the value.
Parameterizing the test:
Instead of using hardcoded values in the script, we can store the test data in the data table and give reference of same in the script which help perform the same operations on the AUT with multiple sets of data. This all is done through data table methods and properties.
DataTable Methods:
These methods are applied on either DataTable object or DTSheet object or DTParameter object. Here are the methods and their properties:
Points to remember –
UFT works only .xls extension file it won’t work with .xlsx
What is Datatable?
Datatable plays a critical role while executing the automation scripts, it is just like an Microsoft Excel file, which is integrated with UFT.
Let’s understand Datatable in this way, suppose you have a requirement where you want to check the 100 different login for the application.
Now you have 2 choices:-
1.Create 100 Test scripts for 100 different user’si.e. hard code the value of the login details in the script itself.
2.Paste all the login details into the datatable and Create 1 Test script, do the configuration in the test script in such a way that each time it will retrieve the login details from datatable i.e. 1 to 100.
I hope you all agreed with me that the first approach is not at all good to use, due to following disadvantages:-
1.Same code for 100 test scripts will be the same except the login details.
2.High code redundancy or duplicity.
3.The biggest disadvantage is “Code Maintenance”, let’s say that there is a change in one of the steps in the script then to apply this change, I need to open all the test script and do the changes which will take lot of time.
All the above disadvantage you will not find if you opt for 2nd choice.
I hope that now you will be able to the following question:-
1.Why we use datatable?
2.What is the need of datatable?
3.Advantage of using datatable?
Points to remember:-
Datatable is used when we want to check the scripts with multiple set of data values then we use datatable.
The DataTable contains a global sheet and a separate sheet for each action in the test. So here we have two types of sheets in data table.
1. Global sheet: - is the sheet which is available to all the actions in a test.
2. Local sheet: - is available to the corresponding actions.
Points to remember:-
You can add “n” number of actions in one test and when it got added 2 things happen, you get a test pane and a new sheet which will be added in the datatable for that action.
It is recommended that for
Global Sheet: -Keep only those data which can be used across all the actions.
Local Sheet: -Keep only those data which can be used across all the actions.
Types of DataTable:
Design Time DataTable: While creating/editing the test scripts, you enter data directly in the data table displayed. If it is not displayed then select View >> Data Table option in UFT. This will show you the data table at the bottom, that datatable is called Design Time DataTable.
Runtime DataTable: The data table used while running the test is called Runtime DataTable. The data in the runtime data table may be same as design time data table and/or can be entered by importing data from excel sheet, text file etc. The runtime data table can be seen in the Test Results window when run session is ended.
DataTable Parameter:
Each column in global/local sheet of datatable is called a Parameter. We can rename the parameter just by double clicking on the column header and giving the name to it. Data can be entered in the column/parameter simply by clicking on the cell and entering the value.
Parameterizing the test:
Instead of using hardcoded values in the script, we can store the test data in the data table and give reference of same in the script which help perform the same operations on the AUT with multiple sets of data. This all is done through data table methods and properties.
DataTable Methods:
These methods are applied on either DataTable object or DTSheet object or DTParameter object. Here are the methods and their properties:
Points to remember –
UFT works only .xls extension file it won’t work with .xlsx