Environment variable in QTP

By | June 30, 2009

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.

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”.

So that’s all about environment variables in QTP, You are always welcome to share your experience on this post.

If you like this article, You can subscribe through mail.

6 thoughts on “Environment variable in QTP

  1. Akansha

    Hey, can you please tell me how to declare arrays in QTP.
    I have to work on the checkboxes included in the webtable, for this i need to create an array to handle checkbox.

    Reply
  2. qtp-fan

    you can declare and use array in following way,

    Dim arrayVal(5)
    arrayVal(0)=”ON”

    Browser(“mybrowser”).page(“myPage”).frame(“myFrame”).webcheckbox(“mybox”).set cstr(arrayVal(0))

    Let me know incase you face any issue.

    Reply
  3. Anonymous

    Can you write the script that show we are using a variable from on action to another

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *