官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 江达县| 玉屏| 荥经县| 绵阳市| 和田市| 马公市| 白玉县| 合水县| 达日县| 隆子县| 开江县| 康马县| 宜城市| 同江市| 福贡县| 青州市| 嘉峪关市| 阜康市| 瓦房店市| 綦江县| 二连浩特市| 突泉县| 浦北县| 桐乡市| 苍梧县| 白银市| 平江县| 调兵山市| 霍林郭勒市| 封开县| 天津市| 三亚市| 铜鼓县| 彭州市| 宜兴市| 麻栗坡县| 徐水县| 卫辉市| 贵州省| 伊通| 德格县|