UFT - Environment Variables

Environment Variables

QTP environment variables are special types of variables that can be accessed by all actions, function libraries and recovery Scenarios. There are inbuilt environment variables for Windows that are available to all the applications running on that particular system where as QTP environment variables are only available to that test script during run-time.

Types of Environment Variables

Built-in Environment Variables - provides a range of environment parameters that can provide information such as test name, action name, the test path, local host name, the operating system name, type and its version. The Environment Variable names can be accessed by Navigating to "File" -> "Test Settings" -> "Environment" Tab
Build-in Environment Variables
User defined Internal - User Defined Variables can be saved by Selecting "User Defined" in the Environment Tab Window. The "+" button is Clicked to enter Parameter Name and Value as shown below:
User Defined Internal Environment Variables
User Defined External - User Defined Variables can be stored in a external file as an .xml and can be loaded into the test as shown in the below figure or can also be loaded dynamically during run-time as explained below in one of the examples.
User Defined Internal Environment Variables

Environment Variables - Supported Methods:

1. ExternalFileName Property - 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, this property returns an empty string
x= Environment.ExternalFileName print x
User Defined Internal Environment Variables
2. LoadFromFile Method - Loads the specified environment variable file(.xml) dynamically during run time. When using this method, the environment variables need NOT be added manually into the Environment Tab.
 Environment.LoadFromFile "D:\config.xml"
 b = Environment.Value("Browser")
 print b
User Defined Internal Environment Variables
3. Value Property - Retrieves the value of environment variables. We can also set the value of user-defined internal environment variables using this property.
  ' Get the Value of the InBuilt Environment Variables
  a = Environment.Value("OS")
  print a
  b = Environment.Value("ActionName")
  print b
  'Loaded from External File
  Environment.LoadFromFile "D:\config.xml"
  c = Environment.Value("Browser")
  print c
User Defined Internal Environment Variables


Post a Comment