Dictionary object is similar to a typical array. The difference between a dictionary object and an array is that there is a unique key associated with every item of dictionary object. This unique key can help you in calling that item as and whenever required.
Shown below is a typical script.
Items Method, Keys Method, Remove Method, RemoveAll Method
Open Window’s registry by opening a Run window and entering regedit.
Shown below is a typical script.
Dim dict ‘ Create a variable.
Set dict = CreateObject(“Scripting.Dictionary”)
dict.Add “Company”, “HP” ‘ Adding keys and corresponding items.
dict.Add “Tool”, “QuickTest Pro”
dict.Add “Website”, “LearnQTP”
dict.Add “Country”, “India”
dict is an object of class Scripting.Dictionary.Set dict = CreateObject(“Scripting.Dictionary”)
dict.Add “Company”, “HP” ‘ Adding keys and corresponding items.
dict.Add “Tool”, “QuickTest Pro”
dict.Add “Website”, “LearnQTP”
dict.Add “Country”, “India”
Items Method, Keys Method, Remove Method, RemoveAll Method
Using Exists Method to check whether the key Country exists?
If dict.Exists(“Country”) Then
msg = “Specified key exists.”
Else
msg = “Specified key doesn’t exist.”
End If
msg = “Specified key exists.”
Else
msg = “Specified key doesn’t exist.”
End If
Using Items and Keys method to retrieve ALL items and keys respectively from inside dictionary object.
i = dict.Items ‘ Get the items.
k = dict.Keys ‘ Get the keys.
For x = 0 To dict.Count-1 ‘ Iterate the array.
msgbox i(x) & ” :” & k(x)
Next
k = dict.Keys ‘ Get the keys.
For x = 0 To dict.Count-1 ‘ Iterate the array.
msgbox i(x) & ” :” & k(x)
Next
Using Remove method to remove Website – LearnQTP pair from the object.
dict.Remove(“Website”)
Using Remove all method to clear the dictionarydict.RemoveAll ‘ Clear the dictionary.
What are the places where it can be used?
When you want to share data between different actions in a test, dictionary object can be used. To do this you should create a reserved test object for the Dictionary object. Here is a process to set up a reserved dictionary object.Open Window’s registry by opening a Run window and entering regedit.
- Navigate to HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects.
- Create a new key (folder) named GlobalDictionary by right-clicking on the ReservedObjects key and selecting New -> Key.
- Under the new key, create a String value named ProgID by right-clicking on GlobalDictionary and selecting New -> String Value.
- Assign “Scripting.Dictionary” to the new ProgID string value by right-clicking on ProgID and selecting “Modify.”
- If QTP window is already open you need to close and restart it.
- Now to check whether dictionary object was installed successfully in registry, simple write GlobalDictionary. (don’t forget the dot) and you should see a drop-down containing all methods and properties associated with dictionary object.
No comments:
Post a Comment