QTP10.com is a new and completely free website that offers help in all the versions of HP QTP (including latest version 10). More importantly, it offers free code for users of HP QuickTest Professioal. This site helps you in learning the basics of QTP and descriptive/advanced programming in (QTP) on various environments like - .Net, Infragistics, Web, Windows, etc.

Note -
This blog is NOT affiliated with HP / Hewlett-Packard in any way. The data/questions come from various sources and we have our own testing questions. I am just another Software Tester like you.

Dictionary Object and QTP

A little introduction about Dictionary Object:

 

The Dictionary object is used to store information in name/value pairs (referred to as key and item). The Dictionary object might seem similar to Arrays, however, the Dictionary object is a more desirable solution to manipulate related data.

Comparing Dictionaries and Arrays:

  • Keys are used to identify the items in a Dictionary object
  • You do not have to call ReDim to change the size of the Dictionary object
  • When deleting an item from a Dictionary, the remaining items will automatically shift up
  • Dictionaries cannot be multidimensional, Arrays can
  • Dictionaries have more built-in functions than Arrays
  • Dictionaries work better than arrays on accessing random elements frequently
  • Dictionaries work better than arrays on locating items by their content

    Read more on..

Dictionary Object & QTP

As an alternative to using environment variables to share values between actions, you can use the Dictionary object. The Dictionary object enables you to assign values to variables that are accessible from all actions (local and external) called in the test in which the Dictionary object is created.

 

'In order to have IntelliSense for the Dictionary object, and have it recognized by other actions, it is added to the registry 
Dim WshShell
Set WshShell =CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\GlobalDictionary\ProgID", "Scripting.Dictionary","REG_SZ"
Set WshShell = Nothing

'
After updating the registry, you must close and reopen QuickTest Professional.
' ***********************************************************************************
'
Available methods
' -----------------------------
'
Exists
GlobalDictionary.Exists(<Key Name>) ' Returns True or False

'
Remove
GlobalDictionary.Remove(<Key Name>) ' Remove a specific key

'
RemoveAll
GlobalDictionary.RemoveAll ' Removes all keys

'
Add
GlobalDictionary.Add <Key Name>, <Value> ' Create a new key and assigns its value

'
Item
GlobalDictionary.Item(<Key Name>) ' Gets/Sets a key value



Sending Keyboard Input to an Application by QTP

The example below uses the PressKey method to send keyboard input to an application.

 

The PressKey method uses the ASCII value for the key.
63 is the ASCII value for F5.

ASCII values for other keys:
F1 - 59
F2 - 60
F3 - 61
F4 - 62
F5 - 63
F6 - 64
F7 - 65
F8 - 66
F9 - 67
F10 - 68
F11 - 87
F12 – 88

 

   1: 'An example that presses a key using DeviceReplay. 



   2:        Set obj = CreateObject("Mercury.DeviceReplay") 



   3:        Window("Notepad").Activate 



   4:        obj.PressKey 63 


Web application performance testing using QTP

QTP is a functional automated testing tools, and the page loading time or  response time of a web application should be a performance testing thing.But as a matter of fact, QTP can also get page load time statistics by some functions. Because QTP using a VBS script and VBS script is so powerful that it can call any windows of the COM components and objects. So the idea of getting page load time is very simple, that is, we want to use VBS for IE page and get statistics of the page load time.