Use the .NET Windows Forms Spy

he .NET Windows Forms Spy Dialog Box enables you to select a specific control in your .NET application, view its run-time object 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.

In addition, you can use the .NET Windows Forms Spy to help you develop extensibility for .NET Windows Forms controls.

The .NET Windows Forms Spy runs in the context of your .NET application, not in the UFT context. The objects and run-time object properties on which you are spying are the raw .NET objects in your application, and not the .NET test objects used in UFT. As a result, you can close UFT when using the .NET Windows Forms Spy. However, UFT 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 UFT .NET Windows Forms Spy window is closed automatically.

Spy on an object

  1. Make sure that the application on which you want to spy is specified in the Windows Applications Tab (Record and Run Settings Dialog Box), and that the application is running with Full Trust.

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

  3. Select Tools > .NET Windows Forms Spy. The .NET Windows Forms Spy Dialog Box opens.

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

  5. 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.

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

  7. Repeat these steps to spy on additional objects and add them to the Objects pane in the UFT .NET Windows Forms Spy window.

Back to top

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 to the Objects tree button . The property is added to the Objects pane, and its run-time object properties and property values (if any) are shown in 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.

    Note: The Add selected property to the Objects tree button is disabled if the property's value is null, or the property is an object with no properties of its own.

Back to top

Locate a property by its value

  1. Click the Search a property by value button . The Find Property by Value dialog box opens.

  2. In the Find what box, specify the value for which you want to search.

  3. To find only those occurrences in which the capitalization matches the text you entered, select Match case.

  4. Specify the direction from the current cursor location in which you want to search: Up or Down.

  5. Click Find Next. The .NET Windows Forms Spy locates the property whose value you specified.

Back to top

Modify values of run-time object properties

  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 on.

Back to top

View event arguments on an 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.

Back to top

Listen to specified events of an 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 UFT. 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 select Select All or Clear All.

  3. Click the Listen to Selected Events button . UFT starts listening to the specified events on the selected object, and Listening is displayed in the status bar.

  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 . UFT stops listening to and logging the specified events.

Back to top

Fire selected events on an 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).

    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. The status bar displays that the event firing is in progress, and when it ends.

Back to top

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.

Back to top

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.

Back to top