QTP10.com is a new and completely free website that offers help in all the versions of HP QTP (including latest version 10). More importantly, it offers free code for users of HP QuickTest Professioal. This site helps you in learning the basics of QTP and descriptive/advanced programming in (QTP) on various environments like - .Net, Infragistics, Web, Windows, etc.

Note -
This blog is NOT affiliated with HP / Hewlett-Packard in any way. The data/questions come from various sources and we have our own testing questions. I am just another Software Tester like you.

QTP Environment Variables Simplified

Share This Post -

Sponsored Links:

The variables that are commonly used across the environment in many tests by different resources are know as Environment Variables.

There are Two types of Environment variables

1. Built-in-variables

2. User Defined Variables

1.Built-in-variables :- These variables will be by default available in every test and can be directly used in any test with help of following syntax.

Syntax: Environment.value(“Built-in-variables”)

Example :

var=environment.Value("OS") : to display the Operating System

msgbox var

2. User Defined Variables :- The variables which are required commonly in number of test apart from the Built-in-variables need to be created by the user which are known as User Defined Variables.

User Defined Variables are created in environment file, any body in that environment can Associate this file and use the variables in it.

There are Two types of User Defined Variables:

i. Internal User Defined Variables : These Variables are used in the same file. See below example:

  • Open the Cal application
  • Put the tool under recording mode
  • Capture the objects properties of Cal application to Object Repository
  • Stop recording

Steps for Declaring the Environment Variables in QTP:

  • Activate the menu item Test
  • Go to Settings
  • Select the Environment tab
  • Select variable type as User-defined
  • Click on New button
  • Add new Environment window will appear
  • Give the details of Name and value ( type will be Internal )
  • Click on OK
  • Again Click on New button to add one more variable
  • Add new Environment window will appear
  • Give the details of Name and value ( type will be Internal )
  • Click on OK
  • Click on Apply
  • Click on OK
  • If you want you can Export these data to a a file with .xml extension file in the Environment folder

Associating the Environment Variables ( by parameterizing )

  • Develop the script in test pane as below:

' Setting the declered environment value (a ) to value1 edit button

VbWindow("Form1").VbEdit("val1").Set environment.Value("a")

' Setting the declered environment value (b ) to value2 edit button

VbWindow("Form1").VbEdit("val2").Set environment.Value("b")

' clicking on ADD button

VbWindow("Form1").VbButton("ADD").Click

  • Run the test
  • Analyze the results

ii. External User Defined Variables :- which are Imported from other file. See below example (Proceed step by step):

  • Open the Cal application
  • Put the tool under recording mode
  • Capture the objects properties of Cal application  to Object Repository
  • Stop recording

Declaring the Environment Variables:

  • Activate the menu item Test
  • Go to Settings
  • Select the Environment tab
  • Select variable type as User-defined
  • Select the check box of ‘load variables and values from an external file’

If you want you can make use of Exported data or you can create your own data in a file with .xml extention file in the Environment folder

  • Browse that file
  • Click on Apply
  • Click on OK

Associating the Environment Variables ( by parameterizing )

  • Develop the script in test pane as below

' Setting the declered environment value (a ) to value1 edit button

VbWindow("Form1").VbEdit("val1").Set environment.Value("a")

' Setting the declered environment value (b ) to value2 edit button

VbWindow("Form1").VbEdit("val2").Set environment.Value("b")

' clicking on ADD button

VbWindow("Form1").VbButton("ADD").Click

  • Run the test
  • Analyze the results