Tricentis Tosca 16.0 Released on Feb-2023 ----- UFT has been upgraded from UFT 15.0.1 to UFT One 15.0.2, Beginning at November 2020.

Saturday, 18 February 2017

What are environment variables in UFT/QTP and what are the different types of environment variables


Environment Variables are similar to that of Global Variables when compared to traditional programming languages like "C".

Values of the Environment Variables can be accessible to all the Actions or functions or Tests and API using simple call

Syntax:


Environment("EnvironmentVariableName") = "Value"

We have two type of Environment Variables

1) Built In
2) User Defined
    i. User Defined - Internal
    ii. User Defined - External


Built In Environment variables are predefined variables defined by QTP/UFT.  Example of these variables are 


Msgbox Environment("OS")
Msgbox Environment("LocalHostName")

Note Please remember Environment Variable Names are case sensitive 




User can also create custom environment variables apart from the built-in environment variables. These variables are called User-defined Environment variables.

To create an user defined environment variable user can click on the Add(+) button which is shown in the below snapshot and define the Environment variable. 

In the snapshot below I have created an user defined environment variable ( Internal) . the Name of the Environment variable is "ProjectName" and when the user calls the environment variable it return the value "HealthCare"

Calling user defined variable is no different from built in environment variables. 

Example
Msgbox Environment("ProjectName")

































User Can export the created user defined( Internal) environment variables to XML file. To do this user has to click on the Export button as shown in the above snapshot.

The content of the xml file contains the following content

<Environment>
 <Variable>
  <Name>ProjectName</Name>
  <Value><![CDATA[HealthCare]]></Value>
 </Variable>
</Environment>




User can also add their own environment variables by adding necessary tag to the existing xml content

<Environment>
 <Variable>
  <Name>ProjectName</Name>
  <Value><![CDATA[HealthCare]]></Value>
 </Variable>
 <Variable>
  <Name>BlogName</Name>
  <Value><![CDATA[Http://BHOJARAZU.BLOGSPOT.IN]]></Value>
 </Variable>
 <Variable>
  <Name>BlogAuthorName</Name>
  <Value>Bhojarazu</Value>
 </Variable>
</Environment>


If you are willing to try you can copy the above code and save the code in a .xml file
The below snapshot shows how to add an external environment file to UFT/QTP. You can provide the fill path of
 the xml file which has valid tags format to display the content in UFT/QTP










No comments:

Post a Comment

Note: only a member of this blog may post a comment.