Stage 9: Implementing Support for Highlighting Objects in the Application

A UFT user can select an object in the object repository and instruct UFT to highlight this object in the application being tested. This enables the user to ensure that UFT associates the test object with the correct object in the application. For more information, see Developing Support for Highlighting Objects.

For UFT to highlight a test object in the application, the Testing Agent must implement the GetHWND method in the IHWNDSupplier interface, the GetRectangle method in the IRectangleSupplier interface, and the ITestable interface.

The GetHWND method receives the object ID of the object that needs to be highlighted, and returns the hWnd of the lowest-level window containing this object. UFT uses this hWnd to make the object that needs to be highlighted visible.

The GetRectangle method receives the object ID of an object and returns a RECT structure that contains the coordinates of the top-left and bottom-right points of the virtual rectangle that surrounds the object.UFT uses this information to draw the rectangle used to highlight the object in the application.

In the QuickID Testing Agent, highlighting objects was supported as follows:

  1. In the TEASampleTestableImp.h file:

    • The following line was added to the CTEASampleTestableImp class inheritance list to indicate that it implements the IRectangleSupplier interface (and therefore also the IHWNDSupplier interface from which it inherits):

          public IDispatchImpl<IRectangleSupplier, &__uuidof(IRectangleSupplier), &LIBID_AutInterface>

    • The following line was added to the CTEASampleTestableImp class' COM Map:

      COM_INTERFACE_ENTRY(IRectangleSupplier)     COM_INTERFACE_ENTRY2(IHWNDSupplier, IRectangleSupplier)

    • All of the methods in the IRectangleSupplier and IHWNDSupplier interfaces were declared members of the CTEASampleTestableImp class.

  2. The Testing Agent's GetRectangle method was implemented in the TEASampleTestableImp.cpp file as follows:

    1. The Testing Agent's GetRectangle method calls GetElementByRuntimeID with the object ID it received.

    2. GetElementByRuntimeID determines the application object to which the object ID refers and returns the global object that represents that application object.

    3. The Testing Agent's GetRectangle method calls the global object's CTEASampleObject::GetRectangle method. The method is implemented in the TEASampleObject.cpp file.

    4. The global object's GetRectangle method delegates the request to the CTEASampleDlg::GetRectangle method with the object ID. CTEASampleDlg is the application's dialog object, implemented in file TEASampleDlg.cpp.

    5. The CTEASampleDlg'sGetRectangle method receives the object ID and returns the rectangle that surrounds the relevant object in the application.

  3. The Testing Agent's GetHWND method was implemented in the TEASampleTestableImp.cpp file in the same way as GetRectangle was implemented, always returning the hWnd of the application dialog box.