Book Image

Advanced UFT 12 for Test Engineers Cookbook

Book Image

Advanced UFT 12 for Test Engineers Cookbook

Overview of this book

Table of Contents (18 chapters)
Advanced UFT 12 for Test Engineers Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Exporting a DataTable


We may need to save data that is collected during a run session. For example, a comparison of the current result with previous results might be required. Alternatively, we might wish to update the expected results. In such scenarios, we can save the data to an external Excel sheet for later use.

How to do it...

To save the DataTable in its current state before the run session ends, we will use the DataTable.Export method, which takes the path and name of an Excel file as an argument. There are two options to save the data table:

  • Using a hardcoded filename:

    DataTable.Export(Environment("TestDir") & "\MyDynamicallySavedExcel.xls")
  • Using a variable filename:

    DataTable.Export(Environment("TestDir") & "\" & strFileName & ".xls")

How it works...

The preceding statement saves the current contents of the DataTable (all worksheets) to a new Excel file (if not existent, otherwise it is overwritten). The statement Environment("TestDir") returns a string with the path of the current test to which a string with the name of the file we wish to create is concatenated (TestDir is one of the built-in Environment variables covered in detail later in this chapter).

There's more...

To export just a single worksheet (in our example, the global sheet) for an action, use the DataTable.ExportSheet method, as follows:

call DataTable.ExportSheet(Environment("TestDir") & "\MyDynamicallySavedSheet1.xls", "Global")

Here, the first parameter is the Excel filename and the second is the source datasheet. The target datasheet will take the same name as the source.