I have gathered this information from learnqtp.com by Ankur.
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:
- 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. 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”)
- 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.
- User defined Internal
No comments:
Post a Comment