DataTables in QTP
When you test your applications, you may want to check how the application performs the same operations with multiple sets of data.
suppose you want to check how your Web site responds to ten separate sets of data. You could create ten separate tests, each with its own set of data. But that isn’t feasible and code length is going to very large having approximately 1000 values. So writing same code lines for each value of test data is not a good practice.
Alternatively: You can create Data Table parameters so that your test runs ten times, each time using a different set of data.
DataTable is just like Microsoft Excel file. The DataTable contains a global sheet and a separate sheet for each action in the test. So we two types of sheets in data table.
1.) Global sheet
2.) Local sheet
Global sheet is available to all actions in the test and local sheet is available to the corresponding action. The best practice is to use local data sheet while parameterizing the test.
Practical example of Data table in QTP
I am going to give you step by step procedure from scratch to end for how to use data table in your application, so you will be more clearer about data table in QTP.
Please go through following procedure.
1. Press “Record” button.
2. Go to start->run write http://google.com and click OK.
3. close the internet explorer window, you will have code like following.
4. Now put cursor on second sentence and do right click on that sentence.
5. Select “Insert output value”, you will have window like following select all three properties and click ok. By default all the values will go to global sheet. You can modify this setting by pressing “modify” button and selecting local sheet.
(Note: You can also redirect these values to environment table and you can access it. know more about environment variable in qtp and how to load and export environment variable in qtp ).
6. So you will have code like following.
7. So when you run the above script you can view three parameter and its value in global data sheet. If you are not able to view, please go to view->Data Table.
8. You can view values during test run, you can’t view that value after test is over.
9. You can export these values in external file with help of datatable.export command.
Put following sentence at last in your script
10. You can also use datatable.import command to import external excel file to your test in the start of test.
Types of DataTable:
Design Time DataTable:While creating editing the test scripts, you enter data directly in the data table displayed there. You can view data table by selecting View >> Data Table option. This data table is called Design Time 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.
Adds the specified sheet to the run time data table.
Deletes the specified sheet from the run time data table.
DataTable.DeleteSheet “My Sheet”
Exports the current sheet to the specifed path.
Reporter.ReportEvent 1, “Row Number”, row
Rowcount=DataTable.Get Sheet(“My Sheet”).GetRowCount
Reporter.ReportEvent 2, “There are” &rowcount, “rows in the data sheet”
Reporter.ReportEvent 0, “sheet number”, “There are” &sheetcount “sheets in data table”
DataTable.ImportSheet”C:\abc.xls”, 1, ”Name”
Description: Returns the current (active) sheet of the data table.
Description: Data table default property. Retrieves or sets the value of the cell in specified parameter and the current row of the data table.
DtSheet.AddParameter: (Adds a new column.)