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?
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"));
}
}