Dictionary Object :
***************************************************************************************************************
Dictionary object is similar to an associative array. Every unique key presnt in the dictionary object has a corresponding value.
**************************************************************************************************************
Advantages of using the “Dictionary Object”:
***************************************************************************************************************
1) One advantage of using a dictionary object is that the values assigned to the variables can be accessed from all actions (local and external).
1) One advantage of using a dictionary object is that the values assigned to the variables can be accessed from all actions (local and external).
2) Any amount of run time values can be stored to and retrieved from the dictionary object.
3) We can use this as one of the parameterization techniques to pass values in QTP.
4)We can return multiple values from functions
***************************************************************************************************************
Simple example is shown below to illustrate the usage of the dictionary object.
***************************************************************************************************************
Set dictObj = CreateObject(“Scripting.Dictionary”)
dictObj.Add “a”, 1
msgBox dictObj(“a”)
*****************************************************************************************************************
Note : This would display the value “1” in the message box. The first 2 statements can be present in one action say Action 1. If the 3rd statement is executed from another action say Action 2, it would still work as dictionary objects are accessible from all actions.
***************************************************************************************************************
Some of the methods associated with the dictionary object are:
***************************************************************************************************************
Items Method (object.Items( ) )
**************************************************************************************************************
Returns an array containing all items in the dictionary object.
**************************************************************************************************************
Exists Method (object.Exists(key))
************************************************************************************************************** Returns true if a specified key exists in the Dictionary object, false if it does not.
**************************************************************************************************************
Keys Method (object.Keys( ))
***************************************************************************************************************
Returns an array containing all existing keys in a Dictionary object.
**************************************************************************************************************
Remove Method (object.Remove(key))
************************************************************************************************************** Removes a key, item pair from a Dictionary object.
**************************************************************************************************************
RemoveAll Mthod (object.RemoveAll))
**************************************************************************************************************
The RemoveAll method removes all key, item pairs from a Dictionary object.
**************************************************************************************************************
No comments:
Post a Comment