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 remains 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: These are the internal variables that are provided by QTP. Among others they can provide you valuable 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. So, how can we access the built in environment variable? It’s simple, just have a look at screenshot.QTP Built-in environment variable So if you want to know the OSVersion of the operating system where your test is running. You can simply type in Environment.Value(“OSVersion”)QTP OS Version Environment Variable
  2. User-Defined: These can be further defined into two types.
    • User defined Internal
      • These are the variables that we define within the test.
      • These variables are saved with the test and are accessible only within the test in which they were defined.
      • 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. This is a topic of a separate post that we will discuss later.