Load and Export environment variables in QTP

By | July 1, 2009
Hi friends, I have posted on subject environment variables in QTP in my previous post, In which I had described types of environment variable, how to add environment variable dynamically, how to create user defined environment variables in QTP manually.

Today in this post I am going to describe two things.

1. How to Load user defined environment variables from XML file to QTP manually and dynamically.
2. How to export user defined environment variables to any XML file manually and dynamically.

How to load user defined environment variables from file to QTP manually and dynamically?

Steps:

1. Create file named qtp.xml and write it in a following format and save it in c directory.

Load and Export User defined environment variables in QTP :

2. Go to File->setting->Environment tab.
3. select variable type to User-defined.
4. check “Load variables and values from external file” named box.
5. enter file name and path for e.g here c:\qtp.xml
6. Press apply and ok.

Now Lets talk about how to load it dynamically. You need to do following things.

1. Create one XML file described in above first step.
2. Write following line in your test script.

environment.LoadFromFile(“c:\qtp.xml”)

msgbox environment.Value(“qtp”)

After running above code You will have one message box with this content http://quicklearnqtp.blogspot.com/.

How to export user defined environment variables to any XML file manually and dynamically.

Steps:

1. Go to File->setting->Environment tab.
2. Select variable type to User-defined.
3. Press on “Export” button and give the name of file for e.g qtptest.xml

You will see all the user defined variable will be exported to qtptest.xml file( In XML format).

Now Lets talk about how to export variables to any XML file it dynamically/programmatically. You need to do following things.

Write following line in your test script.
————————————————-
environment.ExternalFileName(“c:\qtptest.xml”)
————————————————–

All user defined environment variables will be exported to qtptest.xml file.

Note: If you don’t have any user-defined variable stored in QTP. Than error will occur.

You are always welcome to share your experience or doubts.

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

One thought on “Load and Export environment variables in QTP

  1. Anonymous

    ExternalFileName Property
    Description
    Returns the name of the loaded external environment variable file specified in the Environment pane of the Test Settings dialog box. If no external environment variable file is loaded, returns an empty string.

    It doesn’t facilitate exporting of environment variables

    Reply

Leave a Reply

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