Load and Export environment variables in QTP
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?
1. Create file named qtp.xml and write it in a following format and save it in c directory.
<Environment>
<Variable>
<Name>QTP</Name>
<Value>http://automationinyouall.blogspot.com/</Value>
</Variable>
</Environment>
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://automationinyouall.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.
No comments:
Post a Comment