-->User Defined Environment Variables

Steps to work with User defined Environment Variable (Local variable):
1.Go to File -> Settings -> Click on Environment Tab
2.Select the “User defined” option from the variable type
3.Click on Add variable button
4.Provide the name and value -> Click on OK
5.Repeat the above steps to add all the required environment variables
6.Go back to QTP Script editor
7.Use the following syntax to read the values of radio button

msgbox Environment (“DB Server”)

Note: The variables declared with the above steps are local to the script, which they are defined. We can’t use them for another script.

Steps to work with Global Variables (.ini format):
1.Open a notepad file -> Declare the environment variable as below
[Environment]
App path = C:\Programfiles\Mercury\Interactive\ Quicktestprofessional\samples\Flioght41.exe”
URL = http://localhost/Enquirysetup/index.aspx
User Id = Rafi, Password = Mercury
2.Save the file with .ini extension -> Go back to QTP script editor
3.Use the following code to retrieve the values of Environment variables
Environment.Load from file (“D:\QTP Teesting\Env.ini “)
App path = Environment (“app path”)
Invoke application App path
User = Environment (“user ID”)
User Val = Split (User,” “)
Log (“login”).Win edit (“Agent name”)
Val (Random given (0, u bound (user cal)))
Log (“Login”).Win edit (“Password”).set environment (“Password”)
Log (“Login”).Win button (“O.K”).Click

Steps to associate Environment file to the script:
1. File -> Settings -> Environment -> User defined
2. Enable the check button -> Load values & Variables from external file
3. Provide the path of the file -> Click on Apply and OK

Steps to work with Global variables (.XML Format):
1. Select File -> Settings -> Click on Environment tab
2. Select user defined from the variable type
3. Add the variable name and value->Click on Export
4. Save the file (save as .XML)
5. Open XML file -> Right click on it -> Select view source
6. Edit the file for adding or removing the variable -> Save the file
7. Go to QTP script editor
8. Use the following syntax to read the values
Environemnt.Load from file (“D:\QTP Testing\Env.XML”)
App path = Environment (“App path”)
Invoke application App Path
User – Environment (“user ID”)
User Val = split (user,” “)

External File name: This method is used check weather an environment file is already associated
Eg: f= environment. External file name
If f= "then"
Environement.Load from file (“D:\QTP Testing\Env.XML”)
f = Environment external file name
msgbox f
End if