Saturday 9 November 2013

Environment Variables


If we are using global varibals, its global only for that Action. The Action2 are not able to access the Action1 Global variable.


But if we are using the Environment variables, the All actions under the test is able to access.Test case variables mainly treated as Environment variable in real time.


File -> Settings- Environment

1) Built in Environment Variables

-> Pre-Defined Variables, its Read only
-> Its have the value only at run time

Ex:

msgbox Environment.Value("ActionName")

ActionName is Pre-Defined Variables


if we try to change the pre-Defined variables, its get system Error.

Ex: Environment.value("OSVersion")='"windows"     'got Error



2) User Defined Environment Variable

set the user defined variable as below

File -> Settings- Environment -> select veriable type as User-Defined -> Add the variable name and variable value

Ex:

msgbox Environment.Value("Env_1")


we cannot create user defined variable which we have the same name as built in function.

Set the value into user Defined Environment Variable

We can change the user define function value in run time.

Ex:

msgbox Environment.Value("Env_1")
Environment.Value("Env_1") ='QTP Domain"
msgbox Environment.Value("Env_1")

o/p  Value1
QTP Domain


Remove the value from user Defined Environment Variable


Ex:

msgbox Environment.Value("Env_1")
Environment.Value("Env_1") ='QTP Domain"
msgbox Environment.Value("Env_1")

Environment.Value("Env_1") =Nothing
msgbox Environment.Value("Env_1")

o/p  Value1
QTP Domain
Show Error object variable not set




External Environment Variables


1) Using XML file

syntax for create XML file

<Environment>
    <Variable>
        <Name>User_ID</Name>
        <Value>arunrajvdm</value>
    </Variable>
</Environment>

Script

Environment.LoadFromFile "E:\Environment1.xml"
Msgbox Environment.value(User_ID)



Display the external XML file name path for loaded External variablee

filename1=environment.ExternalFileName
msgbox filename1




No comments:

Post a Comment