UFT: Finding the windows of the application under test

My objective is to capture the mouse and keyboard events that UFT generates in the application-under-test (AUT), for use in a third-party application. Ideally, the solution should work with existing tests, or need just minimal changes.

Using Windows hooking on the AUT would work, but this requires enumerating the AUT's window handles. Is there a generic way to get those?

The simplest solution would be doing this for objects in the test:

Set obj = Dialog("Login")
Print "HWND of the login dialog: " & Hex(obj.GetROProperty("hwnd"))

 
The obvious downside is manually coding this for each of the objects in each of the tests.

I tried enumerating the window and dialog objects, but it turns out UFT enumerates every window whether it belongs to the AUT or not:

Set desc = Description.Create  
Set objChildren = Desktop.ChildObjects(desc)
' The following counts every open window on the desktop
Print "Objects under Desktop: " & objChildren.Count

 
Surprisingly, the test's object repositories turned up empty:

' The following line outputs zero
Print "Repository Count:" & RepositoriesCollection.Count

 

Querying individual actions' repositories also turned up no results:

Dim qtApp,qtRepositories, actName
actName=Environment.Value("ActionName")
Set qtApp = GetObject("", "QuickTest.Application") 'also tried with CreateObject
Set qtRepositories = qtApp.Test.Actions(actName).ObjectRepositories
' The following line outputs zero
Print "Action name: " & actName & " Repository count: " & qtRepositories.Count 

 

There is still the option to use ObjectRepositoryUtil, but for that you need a repository path. As far as I can tell, the small test I have created based on the "Flight GUI" sample application, does not even contain a .tsr file which holds the object repository.

So is there another way in UFT to get the windows in the application under test?


  • wrote:

    My objective is to capture the mouse and keyboard events that UFT generates in the application-under-test (AUT), for use in a third-party application. Ideally, the solution should work with existing tests, or need just minimal changes.

    Is QTP not recording the events with existing settings? Are you missing an add-in?

     

     


    wrote:

    The simplest solution would be doing this for objects in the test:

    Set obj = Dialog("Login")
    Print "HWND of the login dialog: " & Hex(obj.GetROProperty("hwnd"))

    What are you trying to achieve with the above?

     


    wrote:

    I tried enumerating the window and dialog objects, but it turns out UFT enumerates every window whether it belongs to the AUT or not:

    Set desc = Description.Create  
    Set objChildren = Desktop.ChildObjects(desc)
    ' The following counts every open window on the desktop
    Print "Objects under Desktop: " & objChildren.Count

    You can create a more specific filter by adding additional properties to desc. For example:


    Set desc = Description.Create
    desc("title").Value = "MyApplication.*"
    
    Set objChildren = Desktop.ChildObjects(desc)
    
    ' Will now give you the count of windows matching the title above
    Print "Objects under Desktop: " & objChildren.Count

     


    wrote:

    Surprisingly, the test's object repositories turned up empty:

    ' The following line outputs zero
    Print "Repository Count:" & RepositoriesCollection.Count

    When you manually check for SORs, do they show up in the list?

     

     

     

     

  • Anshoo,


    Thank you for your reply.

     

    >> Is QTP not recording the events with existing settings? Are you missing an add-in?

     

    I am working on replaying existing tests, not on recording new ones.

     

    >>> What are you trying to achieve with the above?

     

    I need the window handle, or process ID, of the application under test, for integrating with a 3rd party tool.

     

    >>> When you manually check for SORs, do they show up in the list

     

    When checking object repository manually, I do get the list of objects (see screenshot attached). I'd like to get the same result using a script.