DataTable
is a UFT object that acts as a wrapper to an MS Excel file, and its scope is global. This means that it can be accessed from any action within a test, as well as from function libraries that were attached to the test. When you create a new test or open an existing UFT test, you will notice that the DataTable pane will always show a global datasheet and a local one for each existing action within the test.
Prior to getting started with this recipe, please ensure that you have followed the Creating a DataTable parameter recipe.
We will retrieve the value of a DataTable parameter, namely, LocalParam1
, from the Action1
local sheet with the following code written in the code editor inside Action1
:
Dim MyLocalParam MyLocalParam = DataTable.Value("LocalParam1", dtLocalSheet) Print MyLocalParam
Similarly, the following code snippet shows how to retrieve the value of a DataTable parameter from the test global sheet:
Dim MyGlobalParam MyGlobalParam = DataTable("GlobalParam1", dtGlobalSheet) 'We can omit the explicit .Value property as given above since it is the default property Print MyGlobalParam MyGlobalParam = DataTable("GlobalParam1") 'We can omit the second parameter as given above (dtGlobalSheet) since the Global sheet is the default Print MyGlobalParam
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
The result of this code in UFT's console is as follows:
Of course, we need to ensure beforehand that the parameter exists in the DataTable
class as outlined in the previous Creating a DataTable parameter recipe.
By using the DataTable.Value
property we are referring to the column by the parameter name in the underlying Excel worksheet (be it global or local):
MyLocalParam = DataTable.Value("LocalParam1", dtLocalSheet) MyGlobalParam = DataTable("GlobalParam1", dtGlobalSheet)
As we entered just a single value into the datasheet, the command retrieves just the value in the first row. If multiple values were entered and action iterations were set to run on all rows, then it would have retrieved the values from each row with each iteration.