Environment Variables in QTP

These are global variables; if we want to use some variables globally (From number of tests) declaring as global variables is better. If we declare as local variables in number of tests, modifications are difficult.

Types of Environment variables:

1. Built in variables: These are system defined variables, we can access from all tests but these are designed as read only.

2. User defined variables: Variables that we predefine in the active external environment variables file. We can create as many files as we want and we can change values of variables.

Usage of environment variables:


Variable = Environment("environment variable name")


X=Environment ("ActionName")

Msgbox x

Example Script:

ProductDir =environment ("ProductDir")

app= "\samples\flight\app\flight4a.exe"

Systemutil.Run ProductDir & app


Dialog("Login").WinEdit("Agent Name:").Set "abcd"

Dialog("Login").WinEdit("Password:").SetSecure "4b3c86f2107ff565cc195ba6c24739091b656407"


Creating user defined environment variables:


File > settings > Environment > select variable type as user defined > click add icon (+) > enter variable name & Value > click ok (like this we can create number of variables) > click export > browse path & enter file name, save with xml extension > click ok.

Associating environment variable file:


File > settings >Environment > select variable type as user defined > check "load variables and values from the external file" > browse path of the xml file > click apply & ok.


We can load environment file directly 

Environment.loadfromfile"path of the xml file"

Usage of user defined Environment variables:

Associate environment file to current test:

Variable = Environment ("Variable Name")

X=environment ("city")

Msgbox x

Modifying Environment files:

Select XML file>open with notepad>modify the values>Save.
Environment Variables in QTP Environment Variables in QTP Reviewed by Animesh Chatterjee on September 29, 2010 Rating: 5

No comments:

Powered by Blogger.