Monday, May 18, 2009

Environment Variables

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 Variables 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 OSVersion
  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”)= “Rajaputra”
        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.

    We can use environment variables in a number of ways:

    1) When you want a global variable that is needed throughout the test run (across all your reusable actions).

    2) When you see that one reusable action in a script is dependent on the others. You might want to use them

    3) When you need to reference the current “test directory” irrespective of the location where it is stored.

1 comment:

Sathish said...

Excellent Explanation..little basic but bang on what a fresher want!!!

About Me

My photo
Hi all,I am Arun Singh Rajaputra. I am working as a Project Lead in a reputed organization in Hyderabad, AP, India. I have little bit knowledge on Quick Test Professional and like to share my knowledge to all through this blog.

Subscribe to get updates on this blog

Enter your email address:

NOTE

Some of the posts posted in this blog are collected and most of them have been prepared by me. If any one have objections regarding any copied posts. Please mail me so that I can take a necessary action on that post.