Viewing Object Properties Using the Object Spy

Using the Object Spy, you can view the properties of any object in an open application. You use the Object Spy pointer to point to an object. The Object Spy displays the selected object's hierarchy tree and its properties and values in the Properties tab of the Object Spy dialog box.

To view object properties:

  1. Open your browser or application to the page containing the object on which you want to spy.
  2. Choose Tools > Object Spy or click the Object Spy toolbar button to open the Object Spy dialog box and display the Properties tab. Alternatively, click the Object Spy button from the Object Repository dialog box.
  3. In the Object Spy dialog box, click the pointing hand . Both QuickTest and the Object Spy are minimized so that you can point to and click on any object in the open application.

Note: If the window on which you want to spy is partially hidden by another window, hold the pointing hand over the partially hidden window for a few seconds. The window comes into the foreground. You can now point and click on the object you want. You can configure the length of time required to bring a window into the foreground in the General tab of the Options dialog box. You can also hold the left Ctrl key to change the window focus. Additionally, if the window containing the object you want to select is minimized, you can display it by holding the left Ctrl key, right-clicking the application in the Windows task bar, and choosing Restore from the context menu.

  1. If the object on which you want to spy can be displayed only by performing an event (such as a right-click or a mouse-over to display a context menu), hold the left Ctrl key. The pointing hand temporarily turns into a standard arrow and you can perform the event. When the object on which you want to spy is displayed, release the left Ctrl key. The arrow becomes a pointing hand again.
  2. Click the object for which you want to view properties. The Object Spy returns to focus and displays the object hierarchy tree and the properties of the object that is selected within the tree.

Tip: You can resize the Object Spy dialog box. This is useful if you have a deep hierarchy, or long property names and values, enabling you view all the information without scrolling.

  1. To view the properties of the test object, click the Test Object Properties radio button. To view the properties of the run-time object, click the Run-time Object Properties radio button.

Tips: In a function, you can use the Object property to retrieve the values of the run-time properties displayed in the Object Spy

In a function, you can also use the GetTOProperty and SetTOProperty methods to retrieve and set the value of test object properties for test objects. You can use the GetROProperty to retrieve the current property value of the objects in your application during the run session. .

  1. If you want to view properties for another object within the displayed tree, click the object in the tree.
  2. If you want to copy an object property or value to the Clipboard, click the property or value. The value is displayed in the selected property/value box. Highlight the text in the selected property/value box and use Ctrl + C to copy the text to the Clipboard or right-click the highlighted text and choose Copy from the menu.

Test Object and Run-Time Object Properties and Methods

The test object property set for each test object is created and maintained by QuickTest. The run-time object property set for each run-time object is created and maintained by the object creator (for example, Microsoft for Microsoft Internet Explorer objects, Netscape for Netscape objects, the product developer for ActiveX objects, and so forth).

Similarly, test object methods are methods that QuickTest recognizes and records when they are performed on an object while you are recording, and that QuickTest performs when your component runs. Run-time object methods are the methods of the object in your application as defined by the object creator. You can access and perform run-time object methods using the Object property.

Each test object method you perform while recording is recorded as a separate step in your component. When you run your component, QuickTest performs the recorded test object method on the run-time object.

Test object properties are the properties whose values are captured from the objects in your Web site or application when you record your component. QuickTest uses the values of these properties to identify run-time objects in your application during a run session.

Property values of objects in your application may change dynamically each time your application opens, or based on certain conditions. To make the test object property values match the property values of the run-time object, you can modify test object properties manually while designing your component, or use SetTOProperty statements during a run session (via an operation defined in a function library). You can also use regular expressions to identify property values based on conditions or patterns you define

You can view or modify the test object property values that are stored with your component in the Object Properties or Object Repository dialog box. You can view the current test object property values of any object on your desktop using the Properties tab of the Object Spy

You can view the syntax of the test object methods as well as the run-time methods of any object on your desktop using the Methods tab of the Object Spy.

Using operations defined in function libraries, you can retrieve or modify property values of the test object during the run session by adding GetTOProperty and SetTOProperty statements. You can retrieve property values of the run-time object during the run session by adding GetROProperty statements.

If the available test object methods or properties for an object do not provide the functionality you need, you can access the internal methods and properties of any run-time object using the Object property. You can also use the attribute object property to identify Web objects in your application according to user-defined properties

VBScript Constants

A constant is a meaningful name that takes the place of a number or string and never changes. VBScript defines a number of intrinsic constants .

Creating Constants

You create user-defined constants in VBScript using the Const statement. Using the Const statement, you can create string or numeric constants with meaningful names and assign them literal values. For example:

Const MyString = "This is my string."
Const MyAge = 49

Note that the string literal is enclosed in quotation marks (" "). Quotation marks are the most obvious way to differentiate string values from numeric values. You represent Date literals and time literals by enclosing them in number signs (#). For example:

Const CutoffDate = #6-1-97#

You may want to adopt a naming scheme to differentiate constants from variables. This will prevent you from trying to reassign constant values while your script is running. For example, you might want to use a "vb" or "con" prefix on your constant names, or you might name your constants in all capital letters. Differentiating constants from variables eliminates confusion as you develop more complex scripts.

What Is VBScript?

Microsoft Visual Basic Scripting Edition brings active scripting to a wide variety of environments, including Web client scripting in Microsoft Internet Explorer and Web server scripting in Microsoft Internet Information Service.

Easy to Use and Learn

If you already know Visual Basic or Visual Basic for Applications (VBA), VBScript will be very familiar. Even if you do not know Visual Basic, once you learn VBScript, you are on your way to programming with the whole family of Visual Basic languages. Although you can learn about VBScript in just these few Web pages, they do not teach you how to program. To learn programming, take a look at Step by Step books available from Microsoft Press.

Windows Script

VBScript talks to host applications using Windows Script. With Windows Script, browsers and other host applications do not require special integration code for each scripting component. Windows Script enables a host to compile scripts, obtain and call entry points, and manage the namespace available to the developer. With Windows Script, language vendors can create standard language run times for scripting. Microsoft will provide run-time support for VBScript. Microsoft is working with various Internet groups to define the Windows Script standard so that scripting engines can be interchangeable. Windows Script is used in Microsoft® Internet Explorer and in Microsoft® Internet Information Service.

VBScript in Other Applications and Browsers

As a developer, you can license VBScript source implementation at no charge for use in your products. Microsoft provides binary implementations of VBScript for the 32-bit Windows® API, the 16-bit Windows API, and the Macintosh®. VBScript is integrated with World Wide Web browsers. VBScript and Windows Script can also be used as a general scripting language in other applications.

Useful Web Table Functions

Following are functions that may be useful when working on Web Tables.

' ******************************** Function Library *********************************

' Registering both functions

RegisterUserFunc "WebTable", "ObjectsByMicClass", "ObjectsByMicClass"

RegisterUserFunc "WebTable", "ItemByKeyColumn", "ItemByKeyColumn"

' Function: ObjectsByMicClass

' Description: Returns a collection of objects. All the objects in a

' WebTable that have the specified MicClass

' Return Value: A collection of objects

' Arguments:

' Obj - Test Object (WebTable)

' micClass - The micClass of the objects to retrieve

'---------------------------------------------------------------------------------------------------------

Function ObjectsByMicClass(Obj, micClass)

Set Table = Obj

' Create a collection object to hold the items

Set objCollection = CreateObject("Scripting.Dictionary")

' Go over all the cells in the table, and look for objects with the specified micClass

For row=1 to Table.RowCount

ColumnCount=Table.ColumnCount(row)

For col=1 to ColumnCount

For ItemIndex=0 to Table.ChildItemCount(row, col, micClass)-1

Set childItem=Nothing

Set childItem = Table.ChildItem(row, col, micClass, ItemIndex)

If Not childItem is Nothing Then

' If the cell contains a micClass object, add it to the collection

ItemKey = objCollection.Count + 1

objCollection.Add ItemKey, childItem

End if

Next

Next

Next

Set ObjectsbyMicClass = objCollection

End Function

' Function: ItemByKeyColumn

' Description: Returns an item from a column, based on the value of a

' key column

' Return Value: Object

' Arguments:

' Obj - Test Object (WebTable)

' KeyColumnIndex - Index of the KeyColumn

' KeyColumnValue - Value to search for in the key column

' KeyItemIndex - Index of the value in the key column (if there is

' more than one). If 0, the first item will be used.

' TargetColumnIndex - Column from which to retrieve the target item

' micClass - The micClass of the target item

' TargetItemIndex - Index of the target item to retrieve (if there is

' more than one). If 0, the first item will be used.

' ----------------------------------------------------------------------------------------------------

Function ItemByKeyColumn(Obj, KeyColumnIndex, KeyColumnValue, KeyItemIndex, TargetColumnIndex, micClass, TargetItemIndex)

Table = Obj

rowCount = Table.RowCount

' If TargetItemIndex was not specified, use 1 as default

If TargetItemIndex < 1 Then

TargetItemIndex = 1

End If

' If KeyColumnIndex was not specified, use 1 as default

If KeyItemIndex < 1 Then

KeyItemIndex = 1

End If

' Look for KeyColumnValue in the key column to determine from which

' row to retrieve the target item

Row = 0

foundIndex = 0

While Row <= RowCount And foundIndex < KeyItemIndex

Row = Row + 1

CellData = Table.GetCellData(Row, KeyColumnIndex)

If CellData = KeyColumnValue Then

foundIndex = foundIndex + 1

End If

Wend

If foundIndex < KeyItemIndex Then

Exit Function

End If

' Now that we know the row, retrieve the item (according to its micClass)

' from the target column.

ChildItemsCount = Table.ChildItemCount(Row, TargetColumnIndex, micClass)

If ChildItemsCount > =1 And ChildItemsCount >= TargetItemIndex Then

Set GetItemByKeyColumn = Table.ChildItem(Row, TargetColumnIndex, micClass, TargetItemIndex-1)

End If

End Function

' ******************* Examples that use these functions ******************************

' Using the ItemByKeyColumn function

Set obj = Browser("Table with objects").Page("Itenerary: Mercury Tours").WebTable("Acapulco to Zurich").ItemByKeyColumn(1,"FLIGHT",2,3,"WebElement",1)

msgbox obj.GetROProperty("innerhtml")

' Using the ObjectsByMicClass function

Set collection = Browser("Browser").Page("Page").WebTable("Table").ObjectsByMicClass("WebCheckBox")

For i=1 to collection.count

If collection(i).GetROProperty("checked") Then

collection(i).Set "OFF"

Else

collection(i).Set "ON"

End If

Next

Sending Keyboard Input to an Application

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

'An example that presses a key using DeviceReplay.

Set obj = CreateObject("Mercury.DeviceReplay")

Window("Notepad").Activate

obj.PressKey 63

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

Right-Clicking Objects Using Device Replay

The function below uses the DeviceReplay object to perform a right-click operation on any object by retrieving the coordinates of the object.

Sub RightClickObj(Obj, Offset_x, Offset_y)

x_coord = Obj.GetROProperty("abs_x")

y_coord = Obj.GetROProperty("abs_y")

Set dr = CreateObject("Mercury.DeviceReplay")

dr.MouseClick x_coord + Offset_x, y_coord + Offset_y, 2

End Sub

Registering User-Defined Functions as Test Object Methods

The two functions below illustrate how you can enhance the QuickTest Test Object Model by either replacing existing test object methods with new ones or by adding new methods to existing test objects.

Function SelectRegExp(Obj, patrn, Button, Offset)

dim NumOfItems, i, CurrentValue, regEx, ItemToSelect, oldFilter

' Initialize the regular expression object with the pattern

Set regEx = New RegExp

regEx.Pattern = patrn

regEx.IgnoreCase = False

oldFilter = Reporter.Filter ' save the default setting

Reporter.Filter = 2 ' Send only errors

ItemToSelect = -1

' Retrieve the number of items in the list

NumOfItems = obj.GetROProperty("items count")

For i=0 to NumOfItems-1

CurrentValue = obj.GetItem(i)

If regEx.Test(CurrentValue) Then

If (ItemToSelect <> -1) Then

SelectRegExp = -1 ' item not unique

Reporter.Filter = oldFilter

Exit Function

End If

ItemToSelect = i

End If

Next

Reporter.Filter = oldFilter ' Restore the default setting

' The actual selection

If (ItemToSelect >= 0) Then

SelectRegExp = obj.Select(ItemToSelect, Button, Offset)

Else

SelectRegExp = -1

End If

End Function

Function SelectItems(Obj, items)

Dim idx, item

If (StrComp(obj.GetROProperty("type"), "select-multiple", 1) = 0) Then

For Each item In items

obj.Select(item)

Next

Else

obj.Select(items(0))

End If

End Function

' Override the Select function of the WinList object

RegisterUserFunc "WinList", "Select", "SelectRegExp"

' Or add the SelectRegExp function to the WinList object

RegisterUserFunc "WinList", "SelectRegExp", "SelectRegExp"

RegisterUserFunc "WinList", "SelectItems", "SelectItems"

' Example of usage:

WinList("mylist").Select "2002.*"

WinList("mylist").SelectItems Array("item1", "item3", "item6")