9 Dec 2012

Environment Variables

Environment Variables

Environment variables in QTP are similar to global variables which can be accessed through any part of the script.These variables can prove to be very useful when we want a variable to be shared across various reusable actions and functions.

Two Types of Environment variable

Built in variables

User Defined variables
         Internal
         External

Built in variable

Built-in: Variables that represent information about the test on which the test is run, such as Test path and Operating system. These variables are accessible from all tests, and are designated as read-only.

Syntax:

Variable = Environment("environment variable name")

Example:

'Some of the In built Environment Variables

Msgbox Environment("OS")
Msgbox Environment("OSVersion")
Msgbox Environment.value("ProductDir")
Msgbox Environment.value("ProductName")

'path where Test result for the current test is stored
Msgbox Environment("ResultDir")

Internal User defined variable

User defined Internal: are the variables that we define within the test.The variables are saved with the test and are accessible only within the test.

Example:

'User can create their own enviroment variables like "Url"

Environment.Value("Url")= "http:\\www.gmail.com"

URL=Environment.Value("Url")

Systemutil.Run "iexplore.exe",URL

External User defined variable

User defined External: are the variables that we predefine in the active external environment variables file.These can be created using a list of variable-value pairs in an external file in .xml format.

Steps to follow:

1. Create External user defined variable

File --> settings --> Environment --> select variable type as user defined --> click add icon (+) --> enter variable name & Value --> click OK --> click export --> browse path and enter file name --> save with xml extension --> click OK.

2. Associate environment variable file(xml)

File --> settings -->Environment --> select variable type as user defined --> check “load variables and values from the external file” --> browse path of the xml file --> click apply --> Click OK.

XML file with variable name and value should be mentioned

No comments:

Post a Comment