7/9/2015--
Importance of Environment variable:
- Normal variables cannot be used at many places, so hp has come up with environment variables.
Environment.value("<variable name>")= "<name1>"
Value defined inside can be visible/can be used outside. The passing of variables is possible if there are environment variables.
Environment variables - is to promote the communication data between one entity(function) to another entity.
We can change the value of environment variable, when used in a function. Once changed the variable will have data(with latest change).
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.
Dim strTestDir
strTestDir=environment.Value(“TestDir”) ‘ Make sure T and D is capital
msgbox strTestDir
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.
Steps:
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.
msgbox environment.Value(“qtp”)
You will see one msgbox with value of qtp which is “http://quicklearnqtp.blogspot.com”.
Importance of Environment variable:
- Normal variables cannot be used at many places, so hp has come up with environment variables.
Environment.value("<variable name>")= "<name1>"
Value defined inside can be visible/can be used outside. The passing of variables is possible if there are environment variables.
Environment variables - is to promote the communication data between one entity(function) to another entity.
We can change the value of environment variable, when used in a function. Once changed the variable will have data(with latest change).
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.
Dim strTestDir
strTestDir=environment.Value(“TestDir”) ‘ Make sure T and D is capital
msgbox strTestDir
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.
Steps:
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.
msgbox environment.Value(“qtp”)
You will see one msgbox with value of qtp which is “http://quicklearnqtp.blogspot.com”.
No comments:
Post a Comment