Swing widgets embedded within SWT widgets

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

Swing widgets embedded within SWT widgets

Postby Chin-Huat Ang » Wed Sep 10, 2008 1:51 am

Please forgive me if this is a duplicate post, I tried searching the whole forum but I couldn't find any topic similar to this one.

I have the following code in an Eclipse plugin which makes embedding Swing widgets in SWT possible, using SWT/AWT bridge:

Code: Select all
      
Composite container = new Composite(parentComposite, SWT.EMBEDDED | SWT.NO_BACKGROUND);
Frame frame = SWT_AWT.new_Frame(container);
JApplet applet = new JApplet();
// Populate applet with Swing widgets
frame.add(applet);


The result of this code snippet shows Swing widgets nicely in an SWT container, all the keyboard and mouse events are properly handled and dispatched to the embedded Swing widgets. The questions, is it possible to test this? I'm using Window Tester Pro v3.5.0 for Eclipse 3.4, running the test as JUnit plugin test.The problem is when I try to record an Eclipse application launch, it'll only generate codes related to locating SWT widgets. I tried to use Swing widget locators within the SWT test case and I get widget not found exception instead.

Code: Select all
public class TestLaunch extends UITestCaseSWT {

   public void testTestLaunch() throws Exception {
      IUIContext ui = getUI();
      ui.click(new MenuItemLocator("File/New/Other..."));
      ui.wait(new ShellShowingCondition("New"));
      ui.click(new FilteredTreeItemLocator("My wizard"));
      ui.click(new ButtonLocator("&Next >"));
      ui.click(new JRadioButtonLocator("Option one"));  // <--- *** Swing widget locator ***
      ui.click(new ButtonLocator("&Next >"));
      ui.enterText("test");
      ui.click(new ButtonLocator("Cancel"));
   }
}


From the stack trace, it appears that the exception was thrown from within SWT UI context.

Code: Select all
com.windowtester.runtime.WidgetNotFoundException: Widget NOT Found:
JRadioButtonLocator("Option one")
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:568)
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:543)
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:543)
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:543)
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:543)
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:543)
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:543)
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:543)
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:543)
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:543)
   at com.windowtester.runtime.swt.internal.UIContextSWT.find(UIContextSWT.java:543)
   at com.windowtester.internal.runtime.selector.ClickHelper.doFind(ClickHelper.java:192)
   at com.windowtester.internal.runtime.selector.ClickHelper.click(ClickHelper.java:58)
   at com.windowtester.internal.runtime.UIContextCommon.click(UIContextCommon.java:83)
   at com.windowtester.runtime.swt.internal.UIContextSWT.click(UIContextSWT.java:290)
   at com.windowtester.internal.runtime.UIContextCommon.click(UIContextCommon.java:76)
   at com.windowtester.runtime.swt.internal.UIContextSWT.click(UIContextSWT.java:298)
   at com.windowtester.internal.runtime.UIContextCommon.click(UIContextCommon.java:69)
   at com.windowtester.runtime.swt.internal.UIContextSWT.click(UIContextSWT.java:281)
   at TestLaunch.testTestLaunch(TestLaunch.java:21)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at junit.framework.TestCase.runTest(TestCase.java:164)
   at junit.framework.TestCase.runBare(TestCase.java:130)
   at com.windowtester.runtime.common.UITestCaseCommon.access$001(UITestCaseCommon.java:26)
   at com.windowtester.runtime.common.UITestCaseCommon$1.run(UITestCaseCommon.java:133)
   at com.windowtester.runtime.common.UITestCaseCommon$2.run(UITestCaseCommon.java:150)
   at com.windowtester.internal.runtime.junit.core.SequenceRunner$1.run(SequenceRunner.java:46)


Any help would be greatly appreciated.
Chin-Huat Ang
 
Posts: 1
Joined: Wed Sep 10, 2008 1:16 am

Re: Swing widgets embedded within SWT widgets

Postby Phil Quitslund » Tue Sep 23, 2008 7:44 pm

Do you have a simple sample we could use to reproduce this on our end? We'll make much faster progress with a local reproduction.

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

Re: Swing widgets embedded within SWT widgets

Postby samtonyclarke » Mon Jan 12, 2009 10:17 am

Is testing embedded swing widgets within SWT widgets supported under Window Tester Pro?
samtonyclarke
 
Posts: 2
Joined: Mon Jan 12, 2009 10:15 am

Re: Swing widgets embedded within SWT widgets

Postby Phil Quitslund » Tue Jan 13, 2009 11:56 am

It is not supported in the recorder but should be possible in the runtime. In other words you should be able to hand write tests that work with embedded Swing components even if they are not recognized by the recorder. If anyone can volunteer a simple sample app or snippet, we can cook up some examples... Thanks!
--
Phil Quitslund
Software Engineer
Google, Inc.
Phil Quitslund
Moderator
 
Posts: 491
Joined: Fri Apr 28, 2006 6:26 am

Re: Swing widgets embedded within SWT widgets

Postby samtonyclarke » Tue Jan 13, 2009 12:49 pm

We are currently evaluating using TesterPro to test embedded swing widgets nested with and swt widget. An example would be much appreciated, even if it is just for run time playback. Is recording nested swing events on the road map?
samtonyclarke
 
Posts: 2
Joined: Mon Jan 12, 2009 10:15 am

Re: Swing widgets embedded within SWT widgets

Postby Phil Quitslund » Thu Jan 15, 2009 2:51 pm

Hybrid recording is on the short list but not yet scheduled. As for a sample, do you have a stand-alone example we could build a test around? Perhaps something based on one of the SWT snippets here?:

http://www.eclipse.org/swt/snippets/

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


Return to Window Tester

Who is online

Users browsing this forum: No registered users and 1 guest