Friday, 24 July 2015

ENVIRONMENT VARIABLES IN QTP


         Environment Variables:

                        The variables that may be varied in different environments and need to    be used in the multiple scripts should not be directly used in the scripts. They need to be declare separately in an environment file that file need to be associated to the test and then the variables in that file need to be used in those test so that whenever the values need to be updated in different environments one can update them very easily in the environment
             
                        So all the tests using those variables will be automatically updated such kind of variables separately declared in the environment file are known 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 with all the tests so that we can directly use them in any test with the following syntax

              SYNTAX: environment.value(“built invariable name”)
              Example:        var = environment.value(“05”)
                   Msg box var



            2. User defined variables:
                        These variables need to e declared by us according and need to be stored in a separate environment file. Whenever required one need to associate these files to the currant test and use those variables

    Navigation for creating an environment file with environment variables:
·         Activate the menu item test
·         Select the option settings
·         Select the environment tab
·         Select the variable type as user defined
·         Click on new
·         Specify the variable name and the value
·         Click on ok
·         Click on export
·         Browse the desired location
·         Specify the desired file name with .XML extension
·         Click on save

To avoid the above navigation one can directly develop the XML file as follows

<environment>
<variable>
<name> flight path </name>
<value>”d:\program files\mercury” </value>
</variable>
<variable>
<name> b </name>
<value>203</value>
</variable>
</environment>

Navigation for associating an environment file to the current test:
·         Activate the menu item test
·         Select the option settings
·         Select the environment tab
·         Select the variable types as user defined
·         Select the check box load variables and value from external files
·         Browse the path of the environment file
·         Click on apply and ok
In order to avoid the above navigation one can directly type the following script statement in the starting of the script

Syntax: environment. Load from file “path of the env file”

Example: environment. Load from file”d:\envfile122.xml” invoke application environment. Value(“flight Path”)

                   environment.LoadFromFile"C:\Documents and Settings\srss\Desktop\asdf.xml"
                   systemutil.run"C:\Documents and Settings\srss\Desktop\cal"
                   x=environment ("a")
                   y=environment ("b")
                   VbWindow("CALCULATOR").VbEdit("VALUE1").Set x
                   VbWindow("CALCULATOR").VbEdit("VALUE2").Set y
                   VbWindow("CALCULATOR").VbButton("ADD").Click


No comments:

Post a Comment