QTP - Environment Variables

QTP environment variables are special types of variables that can be accessed by all actions, function libraries, and recovery scenarios. There are in-built environment variables for Windows that are available to all the applications running on that particular system, but QTP environment variables are only available to that particular 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 an external file as a .xml file and can be loaded into the test as shown in the figure given below. It 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
Kickstart Your Career

Get certified by completing the course

Get Started