Dictionary Object
Dictionary Object stores data key, item pairs. A Dictionary object stores the items in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array.
Advantages of using it in QTP:
1. can be used as Global variable declaration. so that any test can access the values from it in the run time.
2. You can store and retrieve any number of run time values in to dictionary.
3. It is one of the Parametrization technique we can use in QTP
we can use below methods in Dictionary Object.
1. Add Method
2. Exists Method
3. Items Method
4.Keys Method
5. Remove Method
6. Removeall Method
Add Method
=========
Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add
"a", "Athens" ' Add some keys and items.
d.Add
"b", "Belgrade"
d.Add
"c", "Cairo"
Exists Method
=========
Dim d, msg ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
If d.Exists(
"c")
Then
msg = "Specified key exists."
Else
msg = "Specified key doesn't exist."
End If
Items Method
=========
Use below code after add the values to dictionary
a = d.Items
' Get the items.
For i = 0 To d.Count -1' Iterate the array.
s = s & a(i) & "
" ' Create return string.
Next