- Advanced UFT 12 for Test Engineers Cookbook
- Meir Bar Tal Jonathon Lee Wright
- 408字
- 2021-08-05 17:09:11
Retrieving data from a DataTable
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.
Getting ready
Prior to getting started with this recipe, please ensure that you have followed the Creating a DataTable parameter recipe.
How to do it...
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
Tip
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.
How it works...
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.
Note
The dtLocalSheet
constant always refers to the datasheet by the name of the current action. The dtGlobalSheet
constant always refers to the global datasheet and can be used in any action.
- Mastering Visual Studio 2017
- Oracle WebLogic Server 12c:First Look
- Go語言高效編程:原理、可觀測性與優化
- Visual FoxPro 程序設計
- INSTANT Sencha Touch
- INSTANT OpenNMS Starter
- 區塊鏈技術進階與實戰(第2版)
- Geospatial Development By Example with Python
- .NET 4.5 Parallel Extensions Cookbook
- Kotlin進階實戰
- PHP Microservices
- 一覽眾山?。篈SP.NET Web開發修行實錄
- C++面向對象程序設計
- 循序漸進Vue.js 3前端開發實戰
- Expert Cube Development with SSAS Multidimensional Models