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.