IBM Support

Deriving a TestObject for the active window

Troubleshooting


Problem

The getActiveWindow method returns the active window as an IWindow. This document discusses an approach for retrieving the active window as a TestObject by using the process id of the window.

Resolving The Problem

Use the getPid method on the IWindow returned by the getActiveWindow window to find the process id for the window.

Use the getDomains method to return all of the Java and HTML domains running on the computer. Run the getTopObjects method on those domains, which returns the top objects as type TestObject. For each top object, run the getProcess method to retrieve its corresponding ProcessTestObject. On each ProcessTestObject, run the getProcessId method to return its process id. Then compare the process ids returned by this method with the process id returned by the getActiveWidow method to determine which top object TestObject corresponds to the active window. Since the getDomains method only returns Java and HTML domains, this comparison is only possible if the active window is a Java or HTML object.

What follows is sample code that uses this approach



public void testMain (Object[] args)
{
    IWindow aw = getScreen().getActiveWindow();
    TestObject to = getActiveTOWindow(aw);
    if (to != null)
    {
      System.out.println("Active Window is a Java or HTML app");
    }
    else
    {
      System.out.println("Active Window NOT a Java or HTML app");
    }
}//end of testMain

public TestObject getActiveTOWindow(IWindow aw)
{
    long awPID = (long)aw.getPid();

    DomainTestObject[] dto = getDomains();
    for(int i = 0; i < dto.length; i++)
    {
      TestObject[] topTO = dto[i].getTopObjects();
      int topCount = (topTO != null ? topTO.length : 0);
      for(int j = 0; j < topCount; j++)
      {
        long PID = topTO[j].getProcess().getProcessId();
        if (awPID == PID)
          return (topTO[j]);
      }//end of inner for loop
    }//end of outer for loop

    return null;
}//end of getActiveTOWindow

Be sure to unregister the TestObjects as soon as they are no longer necessary.



[{"Product":{"code":"SSSHZT","label":"Rational XDE Tester"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Not Applicable","Platform":[{"code":"PF033","label":"Windows"}],"Version":"2003;2003.06.00;2003.06.01;2003.06.12","Edition":"","Line of Business":{"code":"","label":""}}]

Document Information

Modified date:
16 June 2018

UID

swg21192654