Highlighted
Absent Member.
Absent Member.
2389 views

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?

0 Likes
2 Replies
Highlighted
Absent Member.. Absent Member..
Absent Member..


@liquid8 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?

 

 


@liquid8 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?

 


@liquid8 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

 


@liquid8 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 Arora
Relevant Codes
LinkedIn
0 Likes
Highlighted
Absent Member.
Absent Member.

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.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.