Environment variables in QTP:
Today I am going to discuss about environment variables in QTP.
There are two types of environment variables in QTP.
1. Bulit In
2. User defined
BuiltIn environment variable:
These environment variable are built in QTP. You can get following information from builtIn environment variables in QTP
– Local host name
– Operating System name
– OS version
– Path of the directory where the QTP is installed
– Name of the product (QTP)
– Name of test ( Main project file)
– Current directory path at you are working
And lots many thing, To know builtIn variable just go to File->setting->environment tab.
You can see list of built in environment variables with name and description.
Now You might be thinking of following question. This you will find very useful when you want to get some value dynamically(when QTP is running).
Question: How to get value from environment variable during run time?
Answer: If you want to know the path of the folder in which test is located. Just write following lines in your script, you will get what you want.
strTestDir=environment.Value(“TestDir”) ‘ Make sure T and D is capital
Note:- Please write variable name as it appears in environment tab. It is case sensitive.
User defined environment variable:
User can define environment variable.
There are two ways to define user specific environment variable manually.
1. Load variables and values from external file.
2. Enter one by one by variable name and its value.
I am describing here one way to define environment variable.
Go to File->setting->environment tab
Select variable type to User defined
Than clik on “+” sign.
add name for e.g qtp
add value for e.g. http://quicklearnqtp.blogspot.com/
Click on apply and ok.
You can check it using following line and run it.
You will see one msgbox with value of qtp which is “http://quicklearnqtp.blogspot.com”.
So that’s all about environment variables in QTP, You are always welcome to share your experience on this post.