Environment variables can be used during automation testing to have global level variables or constants available all the time to all scripts or business components. This can be used as part of any kind of automation test framework used. It will be part of definition of the framework.
They are used for having a global value stored at the windows OS level. The environment variables can be viewed as follows (in a typical windows XP machine):
1. Go to Control Panel
2. Click on “System”
3. Go to “Advanced” tab and click on “Environment Variables” button.
The environment variables will be listed in two sections: a) User Variables and b) System Variables.
All the environment variables defined in the scripts will be stored as part of “User Variables” group.
This should be used minimally as this may be maintenance overhead. It would be hard to explain it to the executor or maintainer unless they are same as the script developers.
The following gives the code snippet to define and use the environment variables in a QTP script.
'-------------------Declaration Section---------------------
'Create the WScript.Shell object
Set objWshShell = CreateObject("WScript.Shell")
'-----------------------------------------------------------
'-------------------Usage Section---------------------
' Access the User Environment property
Set WshEnv = objWshShell.Environment( "User" )
DSPath = WshEnv(strEnvName)
'-----------------------------------------------------------
They are used for having a global value stored at the windows OS level. The environment variables can be viewed as follows (in a typical windows XP machine):
1. Go to Control Panel
2. Click on “System”
3. Go to “Advanced” tab and click on “Environment Variables” button.
The environment variables will be listed in two sections: a) User Variables and b) System Variables.
All the environment variables defined in the scripts will be stored as part of “User Variables” group.
This should be used minimally as this may be maintenance overhead. It would be hard to explain it to the executor or maintainer unless they are same as the script developers.
The following gives the code snippet to define and use the environment variables in a QTP script.
'-------------------Declaration Section---------------------
'Create the WScript.Shell object
Set objWshShell = CreateObject("WScript.Shell")
'-----------------------------------------------------------
'-------------------Usage Section---------------------
' Access the User Environment property
Set WshEnv = objWshShell.Environment( "User" )
DSPath = WshEnv(strEnvName)
'-----------------------------------------------------------