Wednesday, June 16, 2010

Environment variables in QTP

Environment variables in QTP:

Environment variables in QTP are like global variables in other programming languages which can be accessed through any part of the script.

·         The values of these variables remain same irrespective of the number of iterations (unless you change them through scripting).
·         These variables can prove to be very useful when you want a variable to be shared across various reusable actions.

There are two types of environment variables:

1.       Built-In:
2.       User-Defined:

Build IN:
·         These are the internal variables that are provided by QTP.
·         Contain information like the path of the folder where test is located, the path of the results folder, the name of the action iteration or the OS version.
·         You can simply type in Environment.Value(“OSVersion”) to get the OS version


These can be further defined into two types.
·         User defined Internal
o   Define within the test.
o   These variables are saved with the test and are accessible only within the test in which they were defined.
o   So how can we define and use them?

To define them: Environment.Value(“name”)= “Ankur Jain”
To call them: msgbox Environment.Value(“name”)

·         User defined External
·         These are the variables that we predefine in the active external environment variables file.
·         These can be created using a list of variable-value pairs in an external file in .xml format or any other

For e.g.

‘ Load an INI file with user-defined parameters
App.Test.Environment.LoadFromFile “C:\Test_Params\environment_file1.ini”

‘ Set the value of a specific user-defined Environment variable
App.Test.Environment.Value(“newvariable”) = “new value”

As you can see from the example, the Environment variable file is actually an .ini file. The structure would be:


  1. Nice Blog. Wish to follow and share my exp in the future.

  2. very nicely explained !! thanks for this and other qtp related posts, please keep posting ! Grateful to you


Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | JCpenney Printable Coupons