0

We get an an AssertionFailedException on our Build-Server, but the Tests run well when started in the IDE.

The Build-Job is running on Windows and not as a Service, so this should not be a problem.

org.eclipse.swtbot.swt.finder.exceptions.AssertionFailedException: assertion failed: Could not post keyevent.
at org.eclipse.swtbot.swt.finder.utils.internal.Assert.isTrue(Assert.java:95)
at org.eclipse.swtbot.swt.finder.keyboard.SWTKeyboardStrategy.pressKey(SWTKeyboardStrategy.java:41)
at org.eclipse.swtbot.swt.finder.keyboard.AbstractKeyboardStrategy.pressKeys(AbstractKeyboardStrategy.java:56)
at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.pressKeys(Keyboard.java:157)
at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.pressShortcut(Keyboard.java:123)
Chriss
  • 5,157
  • 7
  • 41
  • 75

1 Answers1

0

We tried to send a CR-key and found the following workaround. Instead of sending an event to the OS and wait for the OS to reply with a defaultSelection event we sent the defaultSelection event ourselvs. Our original code looked like this:

KeyboardFactory.getSWTKeyboard().pressShortcut(Keystrokes.CR);

Then we replaced it with:

final Event event = new Event();
SWTBot bot = new SWTBot();
SWTBotList variableList = bot.listWithId(DIALOG_LIST);
event.type = SWT.DefaultSelection;
event.display = bot.getDisplay();
event.widget = variableList.widget;
event.time = (int) System.currentTimeMillis();

bot.getDisplay().syncExec(new Runnable() {
    @Override
    public void run() {
        variableList.widget.notifyListeners(SWT.DefaultSelection, event);
    }
});

this solved our problem.

Veselin
  • 197
  • 2
  • 12