Monday, August 11, 2008

What are environmental variables in QTP? How to use environmental variables?

In QTP, the variables defined in one action cannot be accessed in another action. By using environmental variables, we can access these variables.
QTP supports 3 types of environmental variables:
1. Built-in environmental variables: Variables that represent information about the test and the computer on which the test is run, such as Test path and Operating system. These variables are accessible from all tests, and are designated as read-only.
2. User defined internal environmental variables: variables that you define within the test. These variables are saved with the test and are accessible only within the test in which they were defined. You can create or modify internal, user-defined environment variables for your test.To create User defined internal variables follow below navigation:Test -> settings -> Environmental tab -> Choose “User-defined” in variable type -> click on new button and give name and value.

3. User defined external environmental variables: variables that you predefine in the active external environment variables file. External environment variable values are designated as read-only within the test.To create User defined external variables follow below navigation:Test -> settings -> Environmental tab -> Choose “User-defined” in variable type -> and choose Load variables and values from external file(reloaded each run session) check box ->Enter .xml file which contains the environmental variables.

All the internal user defined environmental variables are displayed with black color, and external environmental variables are displayed in blue color.
The access the value of the environmental variables:temp=Environment.Value("Name")

No comments: