0

I created an eclipse wizard which i want to test now with the SWTBot. I already used the SWTWorkbenchBot which finally works but i want to test the wizard now without the eclipse workbench. Thats why i created a shell in my testclass where i want to put on my wizardpage, but all i could see, was a empty shell without my wizardPage.

So i created a new shell class which included this code:

public static void main(String args[]) {
    try {
        Display display = Display.getDefault();
        HorrorShell shell = new HorrorShell(display);
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}

/**
 * Create the shell.
 * 
 * @param display
 */
public HorrorShell(Display display) {
    super(display, SWT.SHELL_TRIM);
    setLayout(new FillLayout());

    createContents();
}

/**
 * Create contents of the shell.
 */
protected void createContents() {
    setText("SWT Application");
    setSize(450, 300);
    ManualSettingsWizardPage page = new ManualSettingsWizardPage();
    page.createControl(this);
}

With the shell class it works, my wizardpage was shown but if i try to run my testclass as SWTBotTest or as JUnitTest it wont show me anything but a empty shell. Here's the code in my testclass:

private ManualSettingsWizardPage wizard;
private SWTBotShell botShell;
private Shell shell;
private Display display;
    private SWTBot bot;

@Before
public void setUp() {

    botShell = new SWTBotShell(shell);
    bot = new SWTBot();
    wizard = new ManualSettingsWizardPage();

    display = Display.getDefault();
    shell = new Shell(display);
    shell.open();
    shell.layout();

}

@Test
public void bot() throws Exception {
    bot = botShell.bot();
    shell.setBounds(200, 200, 400, 400);
    shell.setLayout(new FillLayout());

    wizard.createControl(shell);
}

1 Answers1

0

I think your problem stems from the fact that you are creating GUI components from the SWTBot-Thread. They should be created by the UIThread, though.

Normally, you'd test some plugin which would open a wizard as the result of choosing an action, e.g. "new xyz". First step would be to put your wizard code into a plugin and register a new action that would fire up the wizard. then you could try finding the shell with SWTBot and executing the desired actions.

Cpt. Senkfuss
  • 1,347
  • 3
  • 12
  • 20