Environment 对象
上一篇 /
下一篇 2012-09-26 21:10:55
/ 个人分类:QTP
通过Environment对象可以读取和设置环境变量。包括 Build-in 和User-Default 两种
OS = Environment.Value(“OS”)
OSVersion = Environment.Value(“OSVersion”)
TestName = Environment.Value("TestName")
Reporter.ReportEvent micDone,"Environment","运行
测试脚本" &TestName
Description
Enables you to work with environment variables.
You can set or retrieve the value of environment variables
using the Environment object. You can retrieve the value of any environment
variable. You can set the value of only user-defined, environment variables.
Syntax
To set the value of a user-defined, environment variable:
Environment (VariableName) =NewValue
To retrieve the value of a loaded environment variable:
CurrValue=Environment (VariableName)
Argument | Type | Description |
---|
VariableName | String | The name of the environment variable. |
NewValue | Variant | The new value of the environment variable. |
CurrValue | Variant | The current value of the environment variable. |
Example
The following example creates a new internal user-defined
variable named MyVariable with a value of 10, and then retrieves the variable
value and stores it in the MyValue variable.
Environment.Value("MyVariable")=10
MyValue=Environment.Value("MyVariable")
ExternalFileName Property
Description
Returns the name of the loaded external environment variable
file specified in the Environment pane of the Test Settings dialog box. If no
external environment variable file is loaded, returns an empty string.
Syntax
Environment.ExternalFileName
Example
The following example uses the ExternalFileName property to
check whether an environment variable file is loaded, and if not, loads a
specific file and then displays one of the values from the file.
'Check if an External Environment file is loaded and if not,
load it.
fileName = Environment.ExternalFileName
If (fileName = "") Then
Environment.LoadFromFile("C:\Environment.xml")
End If
'display value of one of the Environment variables from the
External file
msgbox Environment("MyVarName")
收藏
举报
TAG: