How can I get the value of a system environment variable into a Service Test script?
Question ID: 104584
0
0

I want to make a sort of Global value that all of my Service test scripts can use and I want My Service Test script to grab the value of the environment variable at runtime and use the value in the script as a parameter. Is there a way to do this.

Marked as spam
Posted by (Questions: 36, Answers: 3)
Asked on September 5, 2012 4:46 pm
73 views
Answers (2)
0
Private answer

You can see a video of this example being constructed from the link below.

Step 1 add a user variable to the Service test script called URL

Step 2 add a Custom Code step to the canvas

Step 3 rebuild the solution from the build menu

Step 4 add the code to the custom code activity

`string mySTR=System.Environment.GetEnvironmentVariable(''URL_ENV'',EnvironmentVariableTarget.Machine);
this.CodeActivity6.Context.TestProfile.SetVariableValue(''URL'',mySTR);`

Step 5 Add an environment variable under the system environment variables with the same name as in the code ''URL_ENV''

Step 6 Use the value in the script by slecting test variable from the data source as I just did in my report message in the example video

[Get the video here][1]

[1]: http://ftporasi.com/HPSupport/How_to_grab_the_value_of_a_machine_environment_variable_to_use_in_a_Service_Test_script.zip

Marked as spam
Posted by (Questions: 6, Answers: 167)
Answered on September 5, 2012 4:52 pm
0
Private answer

In QTP I use the GlobalDictionary object. I don't know for sure if this works with Service Test since I don't use it yet, but it probably will. Here's a nice write-up that I got from http://www.sqaforums.com on how to use it:

> Using the Dictionary Object As an
> alternative to using environment
> variables to share values between
> actions you can use the Dictionary
> object. The Dictionary object enables
> you to assign values to variables that
> are accessible from all actions (local
> and external).
>
> 'in order to have intelisence for the
> Dictionary object, and have it
> recognized by other actions, it is
> added to the registry
>
> Dim WshShell Set WshShell
> =CreateObject(''WScript.Shell'') WshShell.RegWrite
> ''HKCUSoftwareMercury
> InteractiveQuickTest
> ProfessionalMicTestReservedObjectsGlobalDictionaryProgID'',
> ''Scripting.Dictionary'',''REG_SZ'' Set
> WshShell = Nothing
>
> ' After updating the registry, you
> must close and reopen QuickTest Pro !!
>
> *********************************************************************************** ' Available methods
>
> ' -----------------------------
>
> ' Exists
>
> GlobalDictionary.Exists() '
> Returns True or False
>
> ' Remove
>
> GlobalDictionary.Remove() '
> Remove a specific Key
>
>
> ' RemoveAll
>
> GlobalDictionary.RemoveAll ' Remove
> all Keys
>
>
> ' Add
>
> GlobalDictionary.Add ,
> ' Create a new key and assigne
> its value
>
> ' Item
>
> GlobalDictionary.Item() '
> Get/Set a key value

Marked as spam
Posted by (Questions: 17, Answers: 807)
Answered on September 5, 2012 5:32 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top