QTP Environment variables are special type of variables whose values persist across and are shared by all actions in a test. QTP environment variables can be used to share information across actions,recovery scenarios and libraries.
There are 3 types of environment variables:
1)Built-in: QTP provides a variety of environment variables that define information such as the currently executing test name,the test's path,operating system,its version etc..
Steps to verify the availability of built-in environment variables
>Go to File-->Settings-->Environment-->Built-in
Accessing an Built-in environment variable in Expert View
Msgbox Environment.Value("ProductDir") 'It will show the folder path where the product is installed'
Msgbox Environment.Value("ActionName") 'It will indicate which action is currently running'
2)User defined internal: These variables are defined in a test and saved with the test.These variables can be modified during run time.
Steps to create an user defined internal environment variable
>Go to File-->Settings-->Environment-->Select User-defined from variable Type drop down List
>Click on add icon ('+')
>Add New Environment Parameter Opens
>Provide some values in Name field(say 'x') and in value field (say '10')
>Click OK.
>Now Click OK on Test Settings Tab.
Accessing an User-defined internal environment variable in Expert View
Msgbox Environment.Value("X") 'It will display the value which we have given in value field i,e 10'
3)User-defined external: These variables are defined in an external environment file.These variables are read-Only and cannot be modified during run-time.The external file can be associated with with the test and can also be loaded at run time using LoadFromFile method.
Create an XML File
<Environment>
<Variable>
<Name>Address1</Name>
<Value>BBSR</Value>
</Variable>
<Variable>
<Name>Address2</Name>
<Value>Delhi</Value>
</Variable>
</Environment>
Steps to Create an user defined external environment variable
>Create an XML file and Save the file in a location that is accessible from the Quick Test.
>Go to File-->Settings-->Environment-->Select User-defined from variable Type drop down List
>Select the 'Load Variables and values from external file' Check box.
>Use the browse button or enter the full path of the XML file .
>The variables defined in the selected file are displayed in blue colour in the list of user-defined
environment variables with its Type as External.
>Click OK on Test Settings Tab.
Accessing an User-defined External environment variable in Expert View
Msgbox Environment.Value("Name") 'It will display the value which we have provided for the environment variable Name'
There are 3 types of environment variables:
1)Built-in: QTP provides a variety of environment variables that define information such as the currently executing test name,the test's path,operating system,its version etc..
Steps to verify the availability of built-in environment variables
>Go to File-->Settings-->Environment-->Built-in
Accessing an Built-in environment variable in Expert View
Msgbox Environment.Value("ProductDir") 'It will show the folder path where the product is installed'
Msgbox Environment.Value("ActionName") 'It will indicate which action is currently running'
2)User defined internal: These variables are defined in a test and saved with the test.These variables can be modified during run time.
Steps to create an user defined internal environment variable
>Go to File-->Settings-->Environment-->Select User-defined from variable Type drop down List
>Click on add icon ('+')
>Add New Environment Parameter Opens
>Provide some values in Name field(say 'x') and in value field (say '10')
>Click OK.
>Now Click OK on Test Settings Tab.
Accessing an User-defined internal environment variable in Expert View
Msgbox Environment.Value("X") 'It will display the value which we have given in value field i,e 10'
3)User-defined external: These variables are defined in an external environment file.These variables are read-Only and cannot be modified during run-time.The external file can be associated with with the test and can also be loaded at run time using LoadFromFile method.
Create an XML File
<Environment>
<Variable>
<Name>Address1</Name>
<Value>BBSR</Value>
</Variable>
<Variable>
<Name>Address2</Name>
<Value>Delhi</Value>
</Variable>
</Environment>
Steps to Create an user defined external environment variable
>Create an XML file and Save the file in a location that is accessible from the Quick Test.
>Go to File-->Settings-->Environment-->Select User-defined from variable Type drop down List
>Select the 'Load Variables and values from external file' Check box.
>Use the browse button or enter the full path of the XML file .
>The variables defined in the selected file are displayed in blue colour in the list of user-defined
environment variables with its Type as External.
>Click OK on Test Settings Tab.
Accessing an User-defined External environment variable in Expert View
Msgbox Environment.Value("Name") 'It will display the value which we have provided for the environment variable Name'