Environment objects enables you to work with Environment variables. You can retrieve values of In bulit environment variables but you can set and retrieve values of user defined variables.
Syntax:
To retrieve a value of an environment variable.
Environment.value(VariableName)
To set a value to a User defined environment variable.
Environment.value(VariableName) = NewValue
The Associated Methods and Properties of Environment Objects are
1. ExternalFileName Property
2. LoadFromFile Method
3. Value Property
ExternalFileNameProperty
This returns the name of the loaded external environment variable file specified in the environment tab of the Test settings dialog box. If no external environment variable file is loaded it returns an empty string.
Syntax
Environment.ExternalFileName
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("VariableName")
LoadFromFileMethod
This method loads the specified environment variable file. The environment variable file must be an xml file. Your xml file should contain the variables in this convention.
Syntax
Environment.LoadFromFile(Path of xml File)
The following example loads an xml file and also prints the value of a environment variable.
Environment.LoadFromFile("E:\Hybrid_FrameWork\Environment.xml")
msgbox Environment("Result")
Value Property
It sets or retrieves the value of an environment variable. You can retrieve the value of any environment variable but you can only set the values of an user defined environment variables.
Syntax
Environment.value(VariableName)
Even though you do not specify value QTP takes by default the value property.
0 comments:
Post a Comment