• Home
  • Testing
  • SAP
  • Web
  • Must Learn!
  • Big Data
  • Live Projects
  • Blog

What is Environment Variable?

Environment variables are dynamic "object" on a computer that can store a value, which in turn can be referenced by one or more software programs in Windows.

Environment variables are dynamic in nature, and it can be changed. There are number of environment variables that can be referenced by programs and can be useful in finding information about their computer environment.

QTP Environment Variables

QTP environment variables can be accessed by all actions, function library, and recovery scenarios.

Types of QTP environment variables

Environment variables are those variables that can be used globally in the tests. There are two types of environment variables

  • Built-in variables
  • User defined variables (Has 2 sub-types )
    • Internal
    • External

Built-in Variables

In QTP, built-in variables are pre-defined variables. It enables the user to retrieve the information about the test that is executing and to get information about the O.S (Operating Systems) on which the test is executing. Some of the built-in variables are Action iteration, Operating system, Test directory, local host names, Operating system version etc.

Go to file -> Settings -> Environment tab to view the environment variable section to see the list of environmental variables.

Environment Variable in QTP

The values from environment variables can be obtained and used wherever necessary during the run session.

Example:

MsgBox Environment.Value("OSVersion")

Environment Variable in QTP

User-defined Variables

Before the execution of the test, these are the variables that are defined by the user. It can be used globally across different tests, or they can also be restricted to one test.

User-defined variables were classified into two types

  • Internal
  • External
  1. User defined - Internal Variables: These variables are defined by the user before executing the test and these are available only to a particular test
  2. User defined- External Variables: These variables are defined by the user and it can be used globally across different tests.

    External variables can be loaded in two ways. It can be done manually before executing the test through environment tab or user-defined screen by inspecting the load variables check box and then by selecting the XML file.

    You can create a user defined variable as follows

    Environment Variable in QTP

    Environment Variable in QTP

    You can access the variable as follows

    MsgBox Environment.Value("Guru99")

    Environment Variable in QTP

 

YOU MIGHT LIKE: