A question about the find() method of IUIContext

WindowTester allows you to easily create and run unit tests for every GUI they build. It can also be used to generate system level tests.

Moderators: gnebling, Eric Clayberg, Dan Rubel, keertip, Phil Quitslund

A question about the find() method of IUIContext

Postby jasonwang » Wed Aug 01, 2007 10:56 pm

I am trying to use ui.find() to check if a dialog contains certain labels (RCP application). The idea is:
Code: Select all

//open the dialog
...

//create the expected String list
...

while(list.hasNext){
//get expected text from the list
...

try{
//create locator
WidgetLocator myLocator = new SWTWidgetLocator(Label.class, expectedText);

ui.find(myLocator);
System.out.println("Found widget: "+ expectedText);
             
}
catch(WidgetSearchException e){
System.out.println("Cannot find widget: "+ expectedText);
}

}


It works properly when the dialog has the expected labels, but if an expected label does not exist, the dialog is closed after the WidgetSearchException expection occurs. As a result, the rest of the labels cannot be checked. I would like to know why the dialog is closed when the find method throws an exception.

Thanks.
jasonwang
 
Posts: 11
Joined: Tue Jul 17, 2007 10:51 pm

Postby Phil Quitslund » Mon Aug 06, 2007 8:33 am

The find() method does some lifecycle management before it throws its exceptions (this is required in cases like open dialogs since they are modal and will stop the exception from propagating). Instead of find(), try findAll() which does not throw any exceptions and does not do any tearing down.

Hope this helps!
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am

Postby jasonwang » Tue Aug 07, 2007 11:14 pm

Thank for the reply. I tired the findAll() method and it does throw any exceptions, but could you tell me how to access the result and get the widget? I always get java.lang.ClassCastException when trying to cast the IWidgetLocator. Please see the following snippet I tried:

Code: Select all
WidgetLocator[] ref = ((WidgetLocator[])ui.findAll(myLocator));
//or
//WidgetReference[] ref = ((WidgetReference[])ui.findAll(myLocator));
jasonwang
 
Posts: 11
Joined: Tue Jul 17, 2007 10:51 pm

Postby Phil Quitslund » Wed Aug 08, 2007 1:30 pm

Yeah this is annoying. Java does not permit that cast.

Instead you'll have to do it on an instance by instance basis:

Code: Select all
for (IWidgetLocator loc : locators) {
   Object widget = ((IWidgetReference)loc).getWidget();
        ....
}
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am

Postby jasonwang » Thu Aug 09, 2007 6:54 pm

Thanks a lot. That helps.
jasonwang
 
Posts: 11
Joined: Tue Jul 17, 2007 10:51 pm


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest