The Dictionary object enables you to assign values to variables that are accessible from all actions (local and external) called in the test in which the Dictionary object is created.
Dictionary Objects have methods like Add (Adds a key and item pair to a Dictionary object), Items (Returns an array containing all the items in a Dictionary object.), Keys (Returns an array containing all existing keys in a Dictionary object.) etc. and properties like Count (Returns the number of items in a Dictionary object.), Item (Sets or returns an item for a specified key in a Dictionary object.). Below examples will make Dictionary Objects more clear. For complete information on these, see QTP User Guide.
To use the Dictionary object, you must first add a reserved object to the registry by following the below mentioned steps:
Go to Start-> Run. Run dialog opens.
Type regedit.exe and click ok. Registory Editor opens.
Go to HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\
Under ReservedObjects create a new Key (Highlight ReservedObjects, go to Edit menu->New ->Key, and name it Dictionary. Right click on DIctionary, go to New-> String Value, Type the name as ProgID. Double click on this ProgID, Edit String dialog opens, type the Value data as Scripting.Dictionary and click ok)
Restart QuickTest Professional
A simple example showing Actions sharing information with the use of Dictionary Objects.
Open a new test in QTP.
In the Expert View of Action1 type:
Dictionary.Add "A", 123
Go to Insert->Call to New Action, to create Action2
In the Expert View of Action2 type:
Run the test.
Above you are setting the values in Action1 and accessing them in Action2.
Another simple example which shows that functions can return dictionary objects:
Set dict_obj = CreateObject("Scripting.Dictionary")
Public Function sum()
dict_obj.add "one",1End function
dict_obj.add "three",dict_obj("one") + dict_obj("two")
Set sum = dict_obj