• No results found

Using the .NET Windows Forms Spy

The .NET Windows Forms Spy enables you to view details about selected .NET Windows Forms controls and their run-time properties. You can use the .NET Windows Forms Spy to help you develop extensibility for .NET Windows Forms controls.

To spy on a .NET Windows Forms application, make sure that the

application is running with Full Trust. If the application is not defined to run with Full Trust, you cannot spy on the .NET application’s Windows Forms controls with the .NET Windows Forms Spy. For information on defining trust levels for .NET applications, refer to Microsoft

documentation.

The .NET Windows Forms Spy is intended for advanced QuickTest users, especially those who are using .NET Add-in extensibility to create support for custom .NET Windows Forms controls. The .NET Windows Forms Spy can assist you in examining .NET Windows Forms controls within your application and seeing which events cause it to change (to facilitate recording and running) and how the changes manifest themselves in the control's state.

The .NET Windows Forms Spy enables you to select a specific control in your .NET application, view its run-time properties and values, change property values in the application in run-time, listen to events on a specific control, view the event arguments, and fire events back at the application.

Note: The .NET Windows Forms Spy runs in the context of your .NET application, not in the QuickTest context. The objects and run-time properties on which you are spying are the raw .NET controls in your application, and not the .NET test objects used in QuickTest. Since the .NET Windows Forms Spy runs in the context of your .NET application, you can close QuickTest while you use the .NET Windows Forms Spy. However, QuickTest must be open if you want to use the pointing hand mechanism to spy on additional objects. If you close the .NET application on which you are spying, the QuickTest .NET Windows Forms Spy window is closed automatically.

Chapter 4 • Testing .NET Windows Forms Applications

To open the .NET Windows Forms Spy and spy on an object:

1 Open the .NET Windows Forms application to the window containing the object on which you want to spy.

2 Choose Tools > .NET Windows Forms Spy. The QuickTest .NET Windows Forms Spy window opens.

3 In the QuickTest .NET Windows Forms Spy window, click the pointing hand. Both QuickTest and the .NET Windows Forms Spy are minimized so that you can point to and click on any object in the open application.

Tips: 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. For more information, refer to the QuickTest Professional User’s Guide.

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.

If the object on which you want to spy can be displayed only by performing an event (such as right-clicking or moving the pointer over an object to display a context menu), hold the left CTRL key. The pointing hand temporarily turns into a standard pointer and you can perform the event.

When the object on which you want to spy is displayed, release the left CTRL

key. The pointer becomes a pointing hand again.

4 Click the object whose properties you want to view. If the location you clicked in your application is associated with more than one object, the Object Selection dialog box opens. The objects associated with the location you clicked are displayed in hierarchical order.

Chapter 4 • Testing .NET Windows Forms Applications

5 Select the .NET Windows Forms object on which you want to spy and click OK. The QuickTest .NET Windows Forms Spy window opens showing the properties and values for the selected object.

The QuickTest .NET Windows Forms Spy window includes the following:

6 You can repeat steps 3 to 5 to spy on additional objects and add them to the Objects pane in the QuickTest .NET Windows Forms Spy window.

Note: QuickTest must be open if you want to use the pointing hand mechanism to spy on additional objects.

You can now view and modify the object’s run-time property values. In addition, you can view, listen to, and fire events on the object.

Item Description

Pointing hand button Enables you to select a .NET Windows Forms object on which to spy. You can spy on as many objects within a single .NET application as you want. Each object that you select is added to the Objects pane.

Note: If you select an object from a different .NET application, an additional QuickTest .NET Windows Forms Spy window opens, showing the information for the selected object.

Type Displays the full type name of the selected object.

Objects pane Displays a hierarchical tree of the objects you selected to spy. For more information, see “Working with the Objects Pane” on page 45.

Properties tab Enables you to view and modify run-time property values in your .NET application. For more information, see “Working with the Properties Tab” on page 46.

Events tab Enables you to listen to events in your .NET application and fire them at the application. For more information, see “Working with the Events Tab” on page 49.

Chapter 4 • Testing .NET Windows Forms Applications

Working with the Objects Pane

The Objects pane contains a list of the objects in your .NET application on which you have spied. Each time you spy on another object in the same .NET application, it is added to the Objects pane. You can spy on as many objects from the same .NET application as you want, using the pointing hand button in the QuickTest .NET Windows Forms Spy window.

The Objects pane also contains any embedded objects that you added from the Properties tab. Each time you add an embedded object to the Objects pane, it is added below its parent object, in a hierarchical format. For more information on viewing properties for embedded objects, see “Working with the Properties Tab” on page 46.

You can select an object in the Objects pane and view or modify its properties and property values, and listen to and fire its events.

You can remove objects from the Objects pane if you no longer need them.

You cannot delete the last remaining parent object from the Objects pane.

When you remove an object, its descendants (if any) are also removed.

To remove objects from the Objects pane:

1 Select the object that you want to remove.

2 Perform one of the following:

➤ Right-click the object and choose Remove Object.

➤ Press DELETE.

Working with the Properties Tab

The Properties tab enables you to view run-time properties and values for objects in your .NET application. You can select a property to display a description of the property below the property grid. You can choose to display the properties alphabetically or by category.

You can change property values in the .NET Windows Forms Spy and apply those changes to your .NET application in run-time.

You can also add embedded objects from the Properties tab to the Objects pane to view their properties.

Chapter 4 • Testing .NET Windows Forms Applications

To view run-time property values for a .NET Windows Forms object:

In the Objects pane, select the object whose run-time properties you want to view. The properties for the selected object are displayed in the Properties tab, with the property names on the left, and the property values on the right. A description of the selected property is displayed below the properties grid.

To modify run-time property values for a .NET Windows Forms object:

1 In the Properties tab, click the property value you want to modify. Properties shown in gray are defined as read-only in the .NET application and cannot be modified.

2 Edit the property value as required. The property value displays different types of edit fields, depending on the needs of a particular property. These edit fields include edit boxes, drop-down lists, and links to custom editor dialog boxes.

After you modify a property value, the new value is applied to the run-time instance of the .NET application. For example, you can change the text of an edit box label, change the background color of a dialog box from gray to red, and so forth.

Note: Any changes you make to the run-time property values of the .NET application remain in effect only for the current instance of the .NET application. The next time you run the .NET application, the properties will return to their original run-time values.

To view properties of embedded objects:

1 In the Properties tab, select the property whose embedded object properties you want to view.

2 Click the Add Selected Property button. The property is added to the Objects pane, and its run-time properties and property values (if any) are shown in the Properties tab. Each time you add an embedded object to the

Note: The Add Selected Property button is disabled if the property’s value is null, or the property is an object with no properties of its own.

To sort the properties grid:

Click one of the following buttons to sort the properties grid in the Properties tab:

➤ Categorized. Lists all properties and property values for the selected object, by category. Categories are listed alphabetically. You can collapse a category to reduce the number of visible properties. When you expand or collapse a category, a plus (+) or minus (-) is displayed to the left of the category name.

➤ Alphabetical. Alphabetically sorts all run-time properties for the selected object.

Note: The Property Pages button is not currently supported.

Chapter 4 • Testing .NET Windows Forms Applications

Working with the Events Tab

The Events tab enables you to listen to selected events on a specific control in your .NET application. You can then view the event arguments, and fire selected events back at the application.

This is especially useful if you are using .NET Add-in extensibility to create support for custom .NET Windows Forms controls. You can see which events cause your .NET application to change, so you can implement extensibility for recording operations on specific controls, and also check which events need to be fired to make your .NET application behave the way you want.

To listen to specified events for a .NET Windows Forms object:

1 In the Objects pane, select the object to whose events you want to listen.

2 In the Events list, select the check boxes for the event types to which you want to listen.

Note: The events that you select affect only the events that are listened to and logged by QuickTest. If you select or clear a check box for an event type after listening to events for an object, the events in the Fired Events list are not changed.

Tip: You can click the Select All Events or Clear All Events buttons to select or clear all the event check boxes. You can also right-click the Events list and choose Select All or Clear All.

3 Click the Listen to Selected Events button. QuickTest starts listening to the specified events on the selected object.

4 In your .NET application, perform the operations on the object to whose events you want to listen. The specified events are logged as they occur and are shown in the Fired Events list.

5 When you want to stop listening to events, click the Stop Listening to Events button. QuickTest stops listening to and logging the specified events.

To view event arguments for a .NET Windows Forms object:

1 In the Objects pane, select the object whose event arguments you want to view.

2 Select the event in the Fired Events list whose arguments you want to view.

The selected events arguments and argument values are shown directly below the event, in the Event Arguments list.

To fire selected events on a .NET Windows Forms object:

1 In the Objects pane, select the object whose events you want to fire.

2 In the Fired Events list, select one or more events that you want to fire on your .NET application. You can select multiple events using standard Windows selection techniques (CTRL and SHIFT keys).

Chapter 4 • Testing .NET Windows Forms Applications

Tip: The selected events are fired in the order in which they appear in the Fired Events list. If the events do not appear in the Fired Events list in the order in which you want to fire them, listen to more events on the object until the events you want are added to the Fired Events list in the required order.

3 If the events you selected have editable arguments, you can change their argument values in the Event Arguments list if needed before firing the events. When the events are fired, they will be fired with the modified argument values.

4 Click the Fire Selected Events button. The selected events are fired in the order in which they appear in the Fired Events list. You can view the effect that firing these events has on the relevant object in your .NET application.

To remove specific events from the Fired Events list:

1 In the Objects pane, select the object whose events you want to remove from the Fired Events list.

2 Select the events in the Fired Events list that you want to remove. You can select multiple events using standard Windows selection techniques (CTRL

and SHIFT keys).

3 Click the Clear Selected Events button. The selected events are removed from the Fired Events list.

To clear all events from the Fired Events list:

1 In the Objects pane, select the object whose events you want to remove from the Fired Events list.

2 Click the Clear Event List button. All the logged events are removed from the Fired Events list.

A

accessing internal properties and methods of run-time .NET Web Forms objects29 accessing internal properties and methods of

run-time .NET Windows Forms objects38

Add-in Manager dialog box14 add-ins

loading with add-in support14 loading without add-in support16 repairing17

uninstalling external18

administrator privileges for installing4

C

checkpoints

supported for Web Forms objects28 supported for Windows Forms objects

36 components

running on .NET Web Forms objects 30

running on .NET Windows Forms objects33

conventions. See typographical conventions custom .NET controls23

,

32

Customer Registration screen8

viewing with .NET Windows Forms Spy49

Expert View29

,

38 external add-ins

uninstalling18

H

hard disk space requirements3

I

installation requirements3

InstallShield Wizard Complete screen12 internal methods, accessing29

,

38

K

Mercury Customer Support Web sitex Mercury Home Pagex

methods29

,

38

Index

N

native properties, accessing29

,

38 .NET Web Forms objects, testing23

30 .NET Windows Forms Spy40

.NET Windows Forms objects, testing31

39

O

Object property29

,

38 online documentationviii online resourcesx

opening .NET applications during record25

,

33 output values

supported for Web Forms objects28 supported for Windows Forms objects

36

P

prerequisites, installation3 properties

viewing with .NET Windows Forms Spy46

Q

QuickTest

loading with add-in support14 loading without add-in support16

R

Readmeviii

Record and Run Settings dialog box25

,

30

,

33

,

39

recording tests, on .NET objects25

,

33 repairing add-ins17

requirements, installation3 running tests

on .NET Web Forms applications30 on .NET Windows Forms applications

39

Test Results window30

,

39 tests

running on .NET Web Forms objects 30

running on .NET Windows Forms objects33

Related documents