Environment variables are a
set of dynamic named values that can affect the way running processes will
behave on a computer. Environment variables in qtp are very useful to define
the environment condition in which QTP is working.
To access the environment variable, Go to File>Settings>Environment and select built-in or user defined from the drop down.
Types of Environment variables
There are two types of Environment
variables in QTP
Built-in variable
Built-in variables are QTP defined variables that contains information of Test Properties, computer’s information, Information related to operating system and Action’s property.User defined variable
Other than environment variable defined in-built in QTP, We can define user defined environment variables. The main purpose of defining user defined variables is to define global variables that can be used throughout test execution irrespective of working with different Actions. So scope of user defined variable is throughout the test execution. This can be of type internal or external if loaded from a file.Loading of User defined Environment variable
Environment variable can be loaded in following ways:
1. Through QTP UI
User defined Environment variables can be created through UI as shown below
Option to export
user-defined environment variables and loading of environment variables from
external file is also available.
2. Using ExternalFileName Property and LoadfromFile Method
Loading of variables from external file as shown above can be done through code:
'Check if
an External Environment file is loaded and if not, load it.
End If
3. Using Environment.Value
Value of environment variable can be extracted at runtime as
StrEnv=environment.value(envName)
Similarly
value of environment variable can be set at runtime as
Environment.value(“envname”)=”some
value”
Where to Access Environment Variable
To access the environment variable, Go to File>Settings>Environment and select built-in or user defined from the drop down.
Accessing environment variables |
Does one way have a benefit over the other like using Environment variable vs Dictionary object ? Is Dictionary more memory consumption
ReplyDelete