ENVIRONMENT VARIABLES IN QTP

 ENVIRONMENT VARIABLES IN QTP

Environment Variables :-

The variables that are commonly used across the environment in many tests by different resources are know as Environment Variables.

There are Two types of Environment variables
1. Built-in-variables 2. User Defined Variables

1.Built-in-variables :- These variables will be by default available in every test and can be directly used
in any test with help of following syntax.
Syntax : Environment.value(“Built-in-variables”)
Example :
var=environment.Value(“OS”) : to display the Operating System
msgbox var

2. User Defined Variables :- The variables which are required commonly in number of test apart from
the Built-in-variables need to be created by the user which are known as User Defined Variables .
User Defined Variables are created in environment file, any body in that
environment can Associate this file and use the variables in it.

There are Two types of User Defined Variables
1. Internal User Defined Variables :- which are used in the same file
Example :
ð Open the Cal application
ð Put the tool under recording mode
ð Capture the objects properties of Cal application to Object Repository
ð Stop recording
Declaring the Environment Variables
ð Activate the menu item Test
ð Go to Settings
ð Select the Environment tab
ð Select variable type as User-defined
ð Click on New button
ð Add new Environment window will appear
ð Give the details of Name and value ( type will be Internal )
ð Click on OK
ð Again Click on New button to add one more variable
ð Add new Environment window will appear
ð Give the details of Name and value ( type will be Internal )
ð Click on OK
ð Click on Apply
ð Click on OK
ð If you want you can Export these data to a a file with .xml extention file in the Environment folder
Associating the Environment Variables ( by parameterizing )
ð Develop the script in test pane as below
‘ Setting the declered environment value (a ) to value1 edit button
VbWindow(“Form1″).VbEdit(“val1″).Set environment.Value(“a”)
‘ Setting the declered environment value (b ) to value2 edit button
VbWindow(“Form1″).VbEdit(“val2″).Set environment.Value(“b”)
‘ clicking on ADD button
VbWindow(“Form1″).VbButton(“ADD”).Click
ð Run the test
ð Analyze the results

2. External User Defined Variables :- which are Imported from other file
Example :
ð Open the Cal application
ð Put the tool under recording mode
ð Capture the objects properties of Cal application to Object Repository
ð Stop recording
Declaring the Environment Variables
ð Activate the menu item Test
ð Go to Settings
ð Select the Environment tab
ð Select variable type as User-defined
ð Select the check box of ‘load variables and values from an external file’
If you want you can make use of Exported data or you can create your own data in a file with .xml extention file in the Environment folder
ð Browse that file
ð Click on Apply
ð Click on OK
Associating the Environment Variables ( by parameterizing )
ð Develop the script in test pane as below
‘ Setting the declered environment value (a ) to value1 edit button
VbWindow(“Form1″).VbEdit(“val1″).Set environment.Value(“a”)
‘ Setting the declered environment value (b ) to value2 edit button
VbWindow(“Form1″).VbEdit(“val2″).Set environment.Value(“b”)
‘ clicking on ADD button
VbWindow(“Form1″).VbButton(“ADD”).Click

ð Run the test
ð Analyze the results

Comments