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

Storing data in the Environment object

The Environment global object is one of UFT's reserved objects and it can be used to store and retrieve both runtime and design-time data.

Note

For a more detailed description of the Environment object, please see the next recipe Retrieving data from the Environment object.

How to do it...

Proceed with the following steps:

  1. To store a parameter at design time, navigate to File | Settings from the UFT menu and then select Environment. From the Variable type list box, select User-defined, as shown in the following screenshot:
  2. Click on the + button on the right of your Environment window. The Add New Environment Parameter window will open. Enter the new parameter's (variable) name and value:
  3. Click on the OK button to approve. You will notice that the newly created variable, with its value, now appears on the list. You should pay attention to the Type column, in which it indicates that the variable we just created is Internal:

What does it mean? A user-defined variable is Internal when we define it through the UFT GUI. It becomes External when either we export the variables to an XML file or define them directly in such a file and later, load the file with the variables and values to the test.

How it works...

Definitions of the types of variable classifications are as follows:

  • Internal variables: When you open an existing test, which has an Internal variable defined, these will be loaded automatically. Changes made to their values during the run session will not be saved. In this sense, the values given to Internal variables using the GUI can be referred to as default values.
  • External variables: When you open an existing test, which has its user-defined variables loaded from an external XML file, these will be loaded automatically. Their values cannot be changed during the run session. In this sense, the values given to External variables can be referred to as constant values.

There's more...

We can also store a value to an Environment variable dynamically from the code. Such a variable will have global scope but will be accessible during runtime only. This means that you will not see it in the list of Internal variables, as shown in this recipe. The procedure is equivalent to using the default Add method of the Scripting.Dictionary object, as shown in the following line of code:

Environment("MyEnvParam") = "MyEnvValue"

See also

Refer to an article by Yaron Assa at http://www.advancedqtp.com/reservedobjects-as-an-env-object-replacement.

主站蜘蛛池模板: 平舆县| 阜城县| 偏关县| 合山市| 广水市| 沾化县| 淮北市| 临江市| 精河县| 固始县| 西峡县| 泸定县| 连州市| 衢州市| 沙雅县| 广丰县| 廊坊市| 芦山县| 辛集市| 九龙坡区| 鸡泽县| 安吉县| 丹棱县| 乌鲁木齐县| 淄博市| 岳池县| 普兰店市| 綦江县| 曲靖市| 安宁市| 图木舒克市| 清河县| 呼伦贝尔市| 清水河县| 阜新市| 定州市| 高陵县| 汶川县| 滕州市| 冀州市| 台江县|