Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何避免;断言失败:无法发布keyevent";在SWTBot?_Java_Unit Testing_Eclipse Rcp_Swtbot - Fatal编程技术网

Java 如何避免;断言失败:无法发布keyevent";在SWTBot?

Java 如何避免;断言失败:无法发布keyevent";在SWTBot?,java,unit-testing,eclipse-rcp,swtbot,Java,Unit Testing,Eclipse Rcp,Swtbot,我们在构建服务器上得到了一个AssertionFailedException,但是测试在IDE中启动时运行良好 生成作业在Windows上运行,而不是作为服务运行,因此这应该不是问题 org.eclipse.swtbot.swt.finder.exceptions.AssertionFailedException: assertion failed: Could not post keyevent. at org.eclipse.swtbot.swt.finder.utils.internal.

我们在构建服务器上得到了一个
AssertionFailedException
,但是测试在IDE中启动时运行良好

生成作业在Windows上运行,而不是作为服务运行,因此这应该不是问题

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)

我们尝试发送CR密钥,并找到以下解决方法。我们没有向操作系统发送事件并等待操作系统回复defaultSelection事件,而是向自己发送defaultSelection事件。我们的原始代码如下所示:

KeyboardFactory.getSWTKeyboard().pressShortcut(Keystrokes.CR);
然后我们将其替换为:

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);
    }
});
这解决了我们的问题