Whenever we record a real-world object (also known as a Runtime object), QTP creates a corresponding Test Object and stores it in the Object Repository. The Test Object contains QTP specific properties and methods which allow us both to identify the relevant runtime object during playback, as well as to perform standard operations on it and with it.
For example, a Window test object contains properties which allow QTP to identify it in the "real world": text, height, nativeclass, etc.; on top of these, it also contains methods to operate it: Close, Click, Maximize. We can easily see these methods and properties via the object spy’s Test Object tab.
It is important to understand that the test object’s properties and methods are not really "out there" in the application’s runtime object, but are only derived from it. So for example, a SwfComboBox Test Object has the property "all items", while the actual .net application combobox runtime object has no such property. QTP builds the "all items" property out of the combobox runtime object’s available items collection, so even though the property does not exist in the runtime object, it is derived from it.
Test objects play several roles in QTP, the most immediate one is object identification. By using a window test object with a text property of "Notepad", we tell QTP to look for a runtime window object with text = "Notepad".
Another important role is standardization. While the application runtime objects might be extremely complex, the corresponding QTP test objects are standard and very simple in comparison. The test object’s simple properties and methods act as a bridge, sparing us the need to nitpick our way through the runtime object’s unknown commands, events and properties. QTP will translate the test object’s simple commands to the runtime object’s commands required to perform the task at hand.
For example, selecting a value in a .Net combobox usually involves changing several properties (SelectedIndex, SelectedItem), and raising several events (SelectionChanged, ItemSelected, TextChanged, etc.). However, the corresponding SwfComboBox test object provides a much more simple and standard "Select" method which does the trick for you.
Working with Test Objects
How can we work with test objects in our scripts?
The most straight-forward way is to simply use them. Every time we maximize a window, select a value from a VBComboBox or click a WebElement, we do it through the QTP test objects. QTP will then locate the corresponding "real" runtime object, and perform the relevant action on it. We can either use prerecorded test objects from the object repository, or create instant test objects via Descriptive Programming.
Aside from straightforwardly using our test objects to perform actions, there are 4 special commands which allow us to access the core of QTP’s test object mechanism: GetTOProperty, GetTOProperties, SetTOProperty and GetROProperty.
GetTOProperty allows us to retrieve the value of a test object property. For example, this command will print out "Notepad":
Msgbox Window("text:=Notepad").GetTOProperty("text")
The GetTOProperty command will retrieve the value as it was originally recorded (or created via DP). It does not matter if the corresponding runtime object exists, or if that value was updated in "the real world" since the object was recorded.