This Post Also talks about How To Work With Datatable In UFT:
If we are working on QTP/UFT for quite a few time the immediate question comes like how to parametrize my test? How to check a scenario with multiple sets of data.Unlike other automation tools QTP/UFT also provide data driven or data oriented concept called data-table to parametrize our tests.
So data book or databank is used to pass the inputs to the script and also to capture output or live data from the script during run time.so basically using of data table is required when we want to run a test multiple time with multiple data.
the basic example could be to test login module. In login we will provide several user id and password and test if it is working fine or not.
For every test by default there would be 2 sheets
just by clicking the different sheets we can acess these tables.
Global sheet is neutral for all actions. If we want some data to be available all actions in our test, we will be using Global data.This is a default data table. So if you create your test and create your test data in excel, you can rename the test data excel file as global and paste it in the data table folder, those values will populate.
1. Mostly we will be using MS-Excel for QTP. There are two methods to invoke one excel file to your test.
1.1. Save your test to a specific folder.
1.1.1. Open that folder via window explorer.
1.1.2. Find Default.xls
1.1.3 Rename it as Default-old.xls
1.1.4 Now rename your datasheet as “Default.xls”
1.1.5 Paste it here.
1.1.6. Reopen your script viz test.
you can find the excel is populated in the datatable area with exact sheetnames given in that excel.
2. Otherwise you can dynamically add excel file through code.
I would say this is very good method. Every time you invoke a excel file that will load into your primary memory . So it is going to consume the primary memory. It is better to load files whenever required.
If we are using different actions,We can store data in the action’s tab but scope is for current action only.
if your underlying data source is Excel , there might be some formula inbuilt in it. QTP has an ability to learn those formula and value from it.
So based on our scope for testing we might pass different datasource.
Datatables are of 2 types in Quick Test
- Design Time Datatable:-The table that is associated with the test before and after the test execution. During execution this got transformed to runtime data
- RunTime Datatable:- The table that is associated with the test during the test execution and will be present in the “Results” after test execution.A live dataset.
by default datatable will be stored by QTP under testname–>Datatable folder. If we want to use some other source , we need to code it accordingly.Where it is applicable?
say I am testing two different versions of the same application like-Webversion and Windows version. So the application data might be same but we need to use it from two different location.
Again say I am testing localization testing of an application, So based on the location I need to pick some other datatable.Such cases this case comes handy.
Supported versions of data souce:
Even the zip files–
File–>import Test from Zip
Datatable object methods:
AddSheet:-Adds the specified sheet to the run-time Data Table and it returns the sheet so that we can add properties to the sheet in the same statement.
How to set parameter/properties to it?
datatable.GetSheet("Sheet1").AddParameter "Fly From",""
Next method will be deletesheet
This method will delete a specific sheet from the data table during run time.
Export :-Saves the copy of the run-time datable in the specified location.
datatable.Export ("location along with Excel name")
Note :- if the file is not created /present QTP will create the file at runtime and exports the specified sheet.
ExportSheet :- exports the specific sheet in the run-time datatable to An Excel file .
DataTable.ExportSheet "location along filename", "sourcesheet"
Three things to know:
1. if the file is not present or created QTP will create the file at runtime and exports the specified sheet.
2. If the excel file is already created but there is no sheet associated with it. QTP will open this file and add the sheet.
3. Say if the file is already created and the sheet is already there, QTP will overwrite the sheets.
if we have a created a sheet called “flight”
if we want to export the first sheet
Import :- imports the specified Excel file to the run time Data Table
Import method deletes/replaces all table available in datatable during run with its sheets.Remember sheet1 will be copied to Global,Sheet2 will be copied to Action. If you have more sheets in the source excel there will no Excel tab in QTP.So we need to create those tab by addSheet then only we will be able to get those extra sheets else those data is not accessable using this method.
It is a best practice to know the numbers of sheets presents in the source file and try to add those sheets during runtime.Then try to get those sheets in QTP.
Import Sheet :- To import the specific sheet in the run time data table.The data in the imported sheet replaces the data in the destination sheet
DataTable.ImportSheet ("location+filename", "Source sheet",destination sheet)
here also you need to create a sheet using datatable.addsheet,then only we will be able to put the flight to run time data.
GetCurrentRow :- returns the current row in the first sheet in the run-time Data-Table(Global sheet).if you are using BPT framework or business component driven approach