Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to Initialize Environment Variable
#1
Solved: 11 Years, 3 Months, 3 Weeks ago
Hello there,

I have a library file that is being used by all scripts, for some functions I use Environment Variables to pass values between scripts, my question is:

How to initialize a Environment Variable?

For example, I have a script that call a function x, Function x uses Environment.Value("Test123"), but the script that is calling function x did not initialize Test123....so when it runs, I get an execution error.

I know the correct way is to initialize the variable, but if for a reason I don't, how to validate Test123 exist and if doesn't to initialize it with a default value?

Thanks for your help.
Reply
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
Well in this case u can bring a concept of .xml file which will be used as common environment variable. Just create "a.xml", initialize the environment variable there in following format---

Code:
<Environment>
        <Variable>
        <Name>Test123</Name>
        <Value>Enter value here</Value>
    </Variable>
</Environment>


Now call this environment variable in your function library like following by its name,this will be accessed by all scripts--

Environment.Value("Test123") ---this will return u --"Enter value here" in function library...

Now its the most important part...
Open your test (From which u called that function) in QTP and go to File-->Settings-->Environment Tab-->Select USER DEFINED from drop down-->Check the checkbox "Load Variable......"-->browse that particular xml file. and click ok.

now you are done...now u can access that environment variable from your script through function. Whenever your script will call "Function x" where that environment value is accessed, just load this xml file with that script from which you want to call that function which are accessing that environment variable....


Hope i am clear to u....if there is any doubt, just drop me a mail in souvikghosh.diatm@gmail.com...because i often check these replies...
Reply
#3
Solved: 11 Years, 3 Months, 3 Weeks ago
Thanks a lot for the info, really helpful.
Reply
#4
Solved: 11 Years, 3 Months, 3 Weeks ago
you are most welcome dear.....
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to retrieve ArrayList saved in Environment Variable Gautam26 8 4,725 11-07-2013, 08:26 PM
Last Post: ssvali
  C# Environment property using QTP API asuteau 0 3,976 08-03-2012, 06:51 PM
Last Post: asuteau
  Array as User-Defined Environment Variables Arena 3 4,260 04-16-2012, 09:19 AM
Last Post: sshukla12
  programming to use different external file of environment variables bundfromnj 1 3,959 01-19-2012, 05:32 PM
Last Post: SteveS
  how can I store a string with variable in it, in another variable? reejais 4 4,600 11-11-2010, 11:46 PM
Last Post: smeepaga

Forum Jump:


Users browsing this thread: 2 Guest(s)