Environment Variables in QTP

This article gives the information about the environment variables in QTP.
Environment variables are like global variables. The value of these variables can’t be changed until the value changed dynamically when running the script.
Environment variables are used to share/keep the same value for a variable across actions. These variables can hold the values like OS Name, OS verison, TestName, TestDir, LocalHostName, ProductName, Product Directory etc.
QTP has two types of environment variables. They are Built In and User Defined.The important point to remember is the environment variables are global to QTP tests only. But Windows environment variables are global to all processes running on the specified machine.
Setting up the Environment variables: Navigate to Test>Settings> Environment Tab and click on Variable Type drop down list and observe that two options “Built In” and “User Defined” are displayed.
Built In Variables: Built in variables holds the values like OS Name, OS Version, Host Name and Test Directory in which the selected Test resides etc.
User Defined Variables: We have two types of user defined environment variables. They are internal and external. Internal variables are created and saved within the selected test. The value of the internal variables can be changed during run time. External variables can be defined in an external environment file. The value of the external variables can’t be changed during run time.
Passing Objects using Environment Variables: We can pass the object using environment variables in two ways. 
The first method is to passing the string definition of an object and convert it to an object.
Example:
'String form an object
Environment("TestBrowser") = "Browser(" "CreationTime:=0")"

Dim browserObject

'Execute the following code to set "TestBrowser" to browserObject

Execute "set browserObject ="& Environment("TestBrowser")

browserObject.close

Second method is directly assign the environment variable to the object.
Example:
'String form an object

Environment("TestBrowser") ="Browser(" "CreationTime:=0" ")"

Dim browserObject

'Execute the following code to set "TestBrowser" to browserObject

Set browserObject "&" Environment("TestBrowser")
browserObject.close 
Loading the environment variables from external file: We can use Environment.LoadFromFile  to load the environment variables from an external file. QTP will always keep only the variables which are recently loaded.
Example: Assume that the environment varianle “Env_File01.xml” is loaded first and “Env_File02.xml” is loaded recently. QTP will have only the environment variables which are loaded from “Env_File02.xml” file. This is the limitation in QTP.
SHARE

About அமரகோசம்

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment