1

I would like to be able to dynamically extract all objects belonging to an IWindow and then convert them to TestObjects. I list all available IWindows using:

IWindow[] windows = root.getTopWindows();

The user will then select an IWindow based on its title (using windows[i].getText() to identify the correct title). I would then like to be able to extract all its children so that I can perform operations on them at a later stage. For TestObject instances, I can already extract all children - however how do I go from having grabbed an IWindow to getting the TestObjects that compose its user interface?

Machavity
  • 30,841
  • 27
  • 92
  • 100
JB2
  • 1,587
  • 2
  • 24
  • 40

1 Answers1

1

I am sure whether it is possible to get TestObjects from an IWindow or to convert an IWindow to a TestObject. Maybe there is another way to find windows—via DomainTestObjects. I know it is not exactly an answer to the question, but could be something:

public void displayDomainsAndTopObjects()
{
    DomainTestObject[] dtos = getDomains();
    for (DomainTestObject dto : dtos)
    {
        System.out.println("--- " + dto.getName() + " ---");
        TestObject[] tos = dto.getTopObjects();
        for (TestObject to : tos)
        {
            System.out.println(to.getDescriptiveName());
        }
    }
}

Maybe you can find a workaround that way? E.g. displaying all open browsers:

public void displayBrowsers()
{
    DomainTestObject[] dtos = getDomains();

    List<DomainTestObject> htmlDomains = new ArrayList<DomainTestObject>();
    for (DomainTestObject dto : dtos)
    {
        if (dto.getName().equals("Html"))
        {
            htmlDomains.add(dto);
        }
    }

    List<BrowserTestObject> browsers = new ArrayList<BrowserTestObject>();
    for (DomainTestObject htmlDomain : htmlDomains)
    {
        TestObject[] tos = htmlDomain.getTopObjects();
        for (TestObject to : tos)
        {
            if (to.getProperty(".class").equals("Html.HtmlBrowser"))
            {
                browsers.add((BrowserTestObject) to);
            }
        }
    }

    System.out.println("Found " + browsers.size() + " browsers:");
    for (BrowserTestObject browser : browsers)
    {
        System.out.println(browser.getProperty(".documentName"));
    }
}
Roland
  • 1,220
  • 1
  • 14
  • 29
  • Thanks Roland. This seems like a really good workaround! Just a question: what are Domains in the context of RFT? – JB2 Oct 07 '14 at 13:47
  • 1
    A domain represents the object model of a supported area—e.g. Java, Html, Net, Process. `getDomains()` returns an array containing DomainTestObjects for all domains which are currently running. I think it is somewhat the most top-level object you can get to find further TestObjects in RFT. – Roland Oct 07 '14 at 14:15
  • OK, thanks. getDomains() returns only one domain named "Process". It contains no children (no mappable children, no top objects etc)...any idea what causes this? – JB2 Oct 07 '14 at 14:20
  • Not really. When I run the code I get the domains Net, ActiveX, Win (with several windows), Siebel, Java, Html (with some browsers and dialogs), and Process. Running RFT 8.5.1.2 (Java) on Win7. Are you running some applications which are activated—e.g. an activated IE? Then at least the Html and Java Domains should be running. – Roland Oct 07 '14 at 14:40
  • Mhh, odd. Running RFT 8.5 on Win7 as well. Yup, I have several activated applications running...IE, a sample Java application, Notepad etc – JB2 Oct 07 '14 at 15:22