is it possible to run multilple ui-tests in one TestClass? I'm always getting a SWTException if i do this. Here's the exception:
- Code: Select all
org.eclipse.swt.SWTException: Device is disposed
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Display.error(Unknown Source)
at org.eclipse.swt.widgets.Display.syncExec(Unknown Source)
at com.windowtester.runtime.swt.internal.state.MenuWatcher.startWatching(MenuWatcher.java:63)
at com.windowtester.runtime.swt.internal.UIContextSWT.setDisplay(UIContextSWT.java:201)
at com.windowtester.swt.UIContextFactory.createContext(UIContextFactory.java:36)
at com.windowtester.swt.UIContextFactory.createContext(UIContextFactory.java:23)
at junit.extensions.swt.ExecutionEnvironment.createUI(ExecutionEnvironment.java:92)
at junit.extensions.swt.ExecutionEnvironment.getUI(ExecutionEnvironment.java:80)
at junit.extensions.swt.SWTExecutionMonitor.getUI(SWTExecutionMonitor.java:185)
at junit.extensions.swt.SWTExecutionContext.getUI(SWTExecutionContext.java:36)
at junit.extensions.UITestCaseCommon.getUI(UITestCaseCommon.java:259)
at de.wt.TestSnippet63.testCancel(TestSnippet63.java:25)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.extensions.UITestCaseCommon.access$101(UITestCaseCommon.java:26)
at junit.extensions.UITestCaseCommon$1.run(UITestCaseCommon.java:140)
at junit.extensions.core.SequenceRunner$1.run(SequenceRunner.java:44)
I use following two code-sections as test. The first one is the Application and the second one the TestClass.
Thanks
mseele
- Code: Select all
package de.wt;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
public class Snippet63 {
public static void main(String[] args) {
Display display = Display.getDefault();
System.out.println(display + " " + Thread.currentThread());
Shell shell = new Shell(display);
shell.setText("dialog");
shell.pack();
shell.open();
final boolean[] result = new boolean[1];
final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM
| SWT.APPLICATION_MODAL);
dialog.setText("promt");
dialog.setLayout(new RowLayout());
final Button ok = new Button(dialog, SWT.PUSH);
ok.setText("OK");
Button cancel = new Button(dialog, SWT.PUSH);
cancel.setText("Cancel");
Listener listener = new Listener() {
public void handleEvent(Event event) {
result[0] = event.widget == ok;
dialog.close();
}
};
ok.addListener(SWT.Selection, listener);
cancel.addListener(SWT.Selection, listener);
dialog.pack();
dialog.open();
System.out.println("Prompt ...");
while (!dialog.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
System.out.println("Result: " + result[0]);
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
System.out.println("Exit");
}
}
- Code: Select all
package de.wt;
import junit.extensions.UITestCaseSWT;
import com.windowtester.runtime.IUIContext;
import com.windowtester.runtime.swt.locator.ButtonLocator;
import com.windowtester.runtime.swt.locator.ShellLocator;
public class TestSnippet63 extends UITestCaseSWT {
/**
* Create an Instance
*/
public TestSnippet63() {
super(Snippet63.class);
}
public void testOk() throws Exception {
IUIContext ui = getUI();
ui.click(new ButtonLocator("OK"));
ui.close(new ShellLocator("dialog", false));
}
public void testCancel() throws Exception {
IUIContext ui = getUI();
ui.click(new ButtonLocator("Cancel"));
ui.close(new ShellLocator("dialog", false));
}
}