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:
· 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
‘ Load an INI file with user-defined parameters
‘ 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: