- 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.
- 多媒體CAI課件設(shè)計(jì)與制作導(dǎo)論(第二版)
- Mobile Web Performance Optimization
- Learning Spring 5.0
- JavaScript+jQuery開發(fā)實(shí)戰(zhàn)
- R語言編程指南
- Python數(shù)據(jù)分析(第2版)
- Responsive Web Design by Example
- 網(wǎng)站構(gòu)建技術(shù)
- Extending Puppet(Second Edition)
- Java語言程序設(shè)計(jì)教程
- HoloLens與混合現(xiàn)實(shí)開發(fā)
- UI設(shè)計(jì)全書(全彩)
- Xcode 6 Essentials
- Distributed Computing in Java 9
- jQuery技術(shù)內(nèi)幕:深入解析jQuery架構(gòu)設(shè)計(jì)與實(shí)現(xiàn)原理