Dictionary Object Key Value Pair in QTP/UFT

1
55
Spread the love
  • 23
  • 22
  • 12
  • 34
  •  
  •  
  •  
  •  
  •  
  •  
    91
    Shares

Dictionary Object Key Value Pair in QTP/UFT
Dictionary Object Key Value Pair in QTP/UFT

 

Dictionary Object A fantastic Approach to solve Key Value Pair in QTP/UFT

Dictionary Object:

Dictionary Object is a Microsoft product and we can use it in UFT/QTP. The key and value both are mandatory for Dictionary Object.Items /elements can be stored in the array. Each member of this array is having a unique key. The key is used to retrieve the detailed information.

There are numerous approaches to utilize Dictionary Objects however the most well-known utilization of Dictionary Object is to keep the incentive in an Array and allude each an incentive with a one of a kind Key or Index.

Fundamentally, Dictionary Object is only an Array which contains values which are alluded by one of a kind keys. For each incentive in Dictionary Object, there is one of a kind key related with esteem. Utilizing Key name, we can call related esteem anyplace in the content.

This is the primary contrast among Array and Dictionary Object. An Array can have file an incentive as numeric though in word reference object, file esteem can be string. Consequently while alluding any an incentive with key, a key can have any name related with an esteem.

Exception:

It can store all possible values–string, integer, etc but can not store an array.

Where it can be used?

Model-1

This is a unique coding technique where the fields are getting changed but the total no of fields are given. The edit box sequence is dynamic. They may appear without any order.
Total number of questions are fixed -5

Scenario-1:
The sequence of questions are : 5,3,2,1,4

Scenario-2:
The sequence of questions are : 1,3,2,5,4

Scenario-3:
The sequence of questions are : 5,3,1,2,4
and so on….

Like wise we can have 5!=120 possible combinations for 5 questions. If the question set is more like 10. Then the possible combinations will be 10!=3628800
Developers introduced these challenge questions just to make sure the site is not accesses by bot. If we have to test this kind of application,we need to create these many scripts along with data. Which looks impossible and make no sense to automate.Also it is not cost effective. Now to resolve this we can use the Dictionary object.Instead of creating so many combinations, we will read 10 questions and store them in some model-X along with the testdata that needs to be inserted.Once we get the question from UAT, we will pass the question to the model-X,model-X will intern return me the test data. Our testscript will then sendKeys those values to the UAT. The model-X is termed as Dictionary object where the questions will be keys and the corresponding testdata will be the values.
Dictionary object was utilized with the index(key) being string. On account of cluster or Array, the list can be ONLY numeric. At that point obviously we have some undeniable preferences like referencing an incentive with a significant keys and so forth.Hence we can not utilize array in these scenarios

Model-2:

When there are lot of test data to be read and apply to an UAT,it is always better to use Dictionary Object as the data fetch from Excel  will be inefficient as there would be too many data seek. Using of dictionary object will surely make the execution faster.

Dictionary object was utilized with the index(key) being string. On account of cluster or Array, the list can be ONLY numeric. At that point obviously we have some undeniable preferences like referencing an incentive with a significant keys and so forth.Hence we can not utilize array in these scenarios

Looking at Dictionaries and Arrays:

  • Keys are utilized to recognize the things in a Dictionary object
  • You don’t need to call ReDim to change the extent of the Dictionary object
  • While erasing a thing from a Dictionary, the rest of the things will consequently move up
  • Dictionary Object can’t be multidimensional, Arrays can
  • Dictionary Object have more worked in capacities than Arrays
  • Lexicons work superior to exhibits on getting to irregular components much of the time
  • Dictionary Object work superior to clusters on finding things by their substance

 

The following code delineates the usage of a Dictionary object:

 

Create:

To Create a dictionary we need to use the following command:


Dim myVar // Create a variable.
Set myVar = CreateObject("Scripting.Dictionary")

Include/add Method

The Add strategy is utilized to include another key/thing pair to a Dictionary object.

Add methods accepts two arguments

  1. Key for the item
  2. Value or the item

Dim myVar // Create a variable.
Set myVar = CreateObject("Scripting.Dictionary")
myVar.Add "a", "Apple" // Add some keys and items.
myVar.Add "b", "Banana"
myVar.Add "c", "Chip"
There are 3 ways to Add to Dictionary
  • myVar.Add “1”,”Apple”
  • myVar.Item(“2″)=”Banana”
  • myVar(“3″)=”Chip”

Down to the post I have given the list of properties of dictionary object. Item is a property of Dictionary object and the third takes advantages of default property of the Dictionary.

ComapreMode:

The CompareMode property is utilized to set and restore the key’s string examination mode which decides how keys are coordinated while turning upward or looking.In simple words, it determines in which “mode” the dictionary’s Item property compares for equality while testing key. The options are:

  • Text(1:vbTestCompare)
  • Binary(0:vbBinaryCompare)
  • Database(2:vbDataBaseCompare)

Mostly during comparison we take the default Text mode and checks with case insensitive.


myVar.CompareMode = vbTextCompare 
 

Exists Method

The Exists() method or technique is utilized to decide if a key exists in the predefined Dictionary. Returns True if it does and False otherwise. It is important to check the existence of the key before we read an Item from Dictionary.


If myVar.Exists("c") Then
msg = "Specified key for the dictionary exists."
Else
msg = "Specified key for the dictionary doesn't exist."
End If
KeyExistsDemo = msg

Key Property

The Key property gives us a chance to change the key estimation of a current key/thing pair.The Keys strategy is utilized to retrieve the majority of the keys in a specific Dictionary article and store them in a cluster.

Thing/Item Property

The Item property enables us to retrieve the estimation of a thing in the accumulation assigned by the predefined key contention and furthermore to set that esteem by utilizing item value. It gives an insight on data storage inside Dictionary objects.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 23
  • 22
  • 12
  • 34
  •  
  •  
  •  
  •  
  •  
  •  
    91
    Shares

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here