QTP Must Read

download QTP Must Read

of 2

Transcript of QTP Must Read

  • 8/3/2019 QTP Must Read

    1/2

    Today we will see a less talked about and not so often used Dictionary Object in QTP. Note that, this is not something very QTP specific. Dictionary object

    was developed by Microsoft and is part of VB Scripting.

    What is Dictionary Object?

    In simple terms, Dictionary object is similar to a typical array. The difference between a dictionary object and an array is that there i s a

    unique key associated with every item of dictionary object. This unique key can help you in calling that item as and whenever required.

    What is the syntax and how can we use dictionary object?

    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. Company-HP,Tool-QuickTest Pro, Website-LearnQTP, Country-India are key-item pairs that were added using Add

    method on dict object.

    Other methods available for dictionary object are Exists Method,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 doesnt 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

    Using Remove method to remove Website LearnQTP pair from the object.

    dict.Remove(Website)

    Using Remove all method to clear the dictionary

    dict.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. [Source]

    1. Open Windows registry by opening a Run window and entering regedit.2. Navigate to HKEY_CURRENT_USER\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects.3. Create a new key (folder) named GlobalDictionary by right-clicking on the ReservedObjects key and selecting New -> Key.4. Under the new key, create a String value named ProgID by right-clicking on GlobalDictionary and selecting New -> String Value.5. Assign Scripting.Dictionary to the new ProgID string value by right-clicking on ProgID and selecting Modify.6. If QTP window is already open you need to close and restart it.7. Now to check whether dictionary object was installed successfully in registry, simple write GlobalDictionary. (dont forget the dot) and you should see a

    drop-down containing all methods and properties associated with dictionary object.

    Why dictionary object and why not array only?

  • 8/3/2019 QTP Must Read

    2/2

    As shown in the example above, dictionary object was used with the index (key) being string. In the case of array, the index can be ONLY numeric. Then of course we

    have some obvious advantages like referencing a value with a meaningful keys etc.

    Have you ever wondered why do we need to launch the application under test (AUT) after QTP is launched?

    When I started learning QTP I asked the same question to the trainer and he said he would get back on it, after some research i found the answer to my question , sharing here what i learnt (

    few years back ) and found ( recently ) :

    y QTP interacts with test applications using windows hooks.A hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages

    before they reach the target window procedure.y Therefore these hooks help QTP during recording and identifying objectsy Hooks can only be installed using DLLsy These Hooks can be injected only during runtime when QTP is brought up.

    An interesting example from Tarun here :

    "Hooks are basically interceptors in system". This example will c lear it

    User Clicks -> Windows OS determine which Application should get it - > Sends the click to t he application.

    Now hooks allow to intercept the message and take action accordingly

    User Clicks -> Windows OS determine which Application should get it - > Installed Hook (Hook can decide to s end the message or cancel it or record it or take some action based on event)->Sends the click to the application.Happy Testing!