QTP DataTable Advanced Level Concept

This Page will contain the datatable concept used in QTP. It Covers
  • Export Run Time DataTable
  • Import Excel Workbook in Datable
  • Import only particular value
  • Save the result file at desired location.
  • Set parameter in particular cell and in particular format.
'This example imports data from external files into the Data Table and sets parameters
'for the test through the Data Table. It shows how you can send parameters to a test by
'setting the Data Table values before running the test.

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable

Dim qtOptions 'As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable

Set qtApp = CreateObject("QuickTest.Application") ' Create a Application object

qtApp.Launch ' Start QuickTest

qtApp.Visible = True ' Make the QuickTest application visible

' Open the test
qtApp.Open "C:\Tests\YourTestName", False ' Open a test named "YourTestName"

' Import data to the design-time Data Table and then add new data

qtApp.Test.DataTable.Import "C:\MySheet.xls" ' Import data from an external file

qtApp.Test.DataTable.ImportSheet "C:\Tables.xls", 1, "Action1" ' Import a single sheet

qtApp.Test.DataTable.GlobalSheet.GetParameter("Started") = Now ' Set test run starting time

qtApp.Test.DataTable.GlobalSheet("ParamCount") = 45 ' Set a parameter for the test using the Data Table

' Run the test
Set qtOptions = CreateObject("QuickTest.RunResultsOptions") ' Create a Results Option object

qtOptions.ResultsLocation = "<TempLocation>" ' Set the Results location to temporary location

qtApp.Test.Run qtOptions, True ' Run the test and wait for it to finish before continuing the automation script

' Set additional values in the design-time Data Table
qtApp.Test.DataTable.GlobalSheet("Ended") = Now ' Set test's run ending time

qtApp.Test.DataTable.GlobalSheet("RanBy") = "MyName" ' Set the "RanBy" cell


' Save the Run-time Data Table
qtApp.Test.LastRunResults.DataTable.Export "C:\Runtime.xls" ' Save the run-time Data Table to a file
qtApp.Quit ' Exit QuickTest

Set qtOptions = Nothing ' Release the Run Results Options object

Set qtApp = Nothing ' Release the Application object

No comments:

Post a Comment