Environment Variables

QTP Environment variables are variables which we can share information across actions, recovery scenarios and libraries.

These environment variables are different from Windows environment variables.

Windows environment variable are available to all the programs running on the machine while QTP environment variables are only available to a test script running at run-time.

Types of Environment variables:

There are three types of Environment variables in QTP:

1.       Built-in :  QTP provides a variety of environment variables that define information such as the currently executing test’s name, the test’s path, the operating system type and its verision and the local host name.

To Check Built-in environment variables:

File -> Settings -> Environment tab -> From Variable type drop down select ‘BuiltIn’

Ex: msgbox environment(“OS”)

     Msgbox environment(“Prod Dir”)

2.       User defined Internal :  These variables are defined in a test and saved with the test. These variables can be modified during run-time.

Accessing User defined internal variables:

File -> Settings -> Environment tab -> From Variable type drop down select ‘User defined’ -> Click on ‘+’ button and enter environment variable name and value -> click on OK button.

3.       User Defined External : 
These variables are defined in an external environment files. These variables are read-only and cannot be modified at run-time. The external file can be associated with the test.

Accessing User defined external variables:

File -> Settings -> Environment tab -> From Variable type drop down select ‘User defined’ -> Click on ‘+’ button and enter environment variable name and value -> Click on Export button and save the corresponding file. -> Open a new test -> File -> Settings -> Environment tab -> From Variable type drop down select ‘User defined’ -> Check the Load variables and values from external files check box -> browse the corresponding environment file. -> Click Apply -> Click OK
Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com