1. Definition - Environment variables are variables used across QTP Scripts/ all actions in a script/recovery scenario/function libraries in a UFT script.
Understand them as global variables for UFT Test Scripts.
2. Types of Environment Variables:
Environment variables are of 2 types:
a. Built in Variables
b. User Defined Variables
3. Built -in variables are defined in QTP and can provide information on the QTP scripts and the operating system.
4. User Defined variables are again be divided into two types:
a. User Defined - Internal - defined at test level by adding a new environment parameter.
b. User Defined - External - imported for an external xml file with parameters and values for parameters defined in the external file.
5. Steps to add user defined environment variables:
a.) In the test in which environment variable are to be added, Go to file -> Settings -> Environment.
b.) In variable type, select user defined.
c.) Click on + icon, and add a new parameter with name and value.
6. To import from external file, check checkbox to load from external file and provide the path of the external file.
7. Environment variable for external file can be imported through code as shown below:
8. Access and update environment variable in the script:
9. Example of environment variable xml file
10. Useful Reference:
http://gareddy.blogspot.in/2010/12/qtp-environment-variables.html
http://qaautomationqtp.blogspot.in/2013/05/environment-variables-in-qtp.html
Summary
Understand them as global variables for UFT Test Scripts.
2. Types of Environment Variables:
Environment variables are of 2 types:
a. Built in Variables
b. User Defined Variables
3. Built -in variables are defined in QTP and can provide information on the QTP scripts and the operating system.
4. User Defined variables are again be divided into two types:
a. User Defined - Internal - defined at test level by adding a new environment parameter.
b. User Defined - External - imported for an external xml file with parameters and values for parameters defined in the external file.
5. Steps to add user defined environment variables:
a.) In the test in which environment variable are to be added, Go to file -> Settings -> Environment.
b.) In variable type, select user defined.
c.) Click on + icon, and add a new parameter with name and value.
6. To import from external file, check checkbox to load from external file and provide the path of the external file.
7. Environment variable for external file can be imported through code as shown below:
fileName = Environment.ExternalFileName if (fileName = "") Then Environment.LoadFromFile("C:\testEnv.xml") End If
8. Access and update environment variable in the script:
''Acessing an environment variable: Testval = Environment.Value("testing") ''Updating an user defined variable Environment.Value("testing") = "testing2"
9. Example of environment variable xml file
<Environment> <Variable> <Name>Environment1</Name> <Value>ValueA</Value> </Variable> <Variable> <Name>Variable2</Name> <Value>ValueB</Value> </Variable> </Environment>
10. Useful Reference:
http://gareddy.blogspot.in/2010/12/qtp-environment-variables.html
http://qaautomationqtp.blogspot.in/2013/05/environment-variables-in-qtp.html
Summary