我在尝试使用BasicRobot (FEST)时得到以下内容。我不知道如何解决这个问题。
[ConditionalEventPump] Exception occurred during event dispatching:
java.lang.IllegalThreadStateException: Cannot call method from the event dispatcher thread
at org.fest.swing.core.BasicRobot.waitForIdle(BasicRobot.java:669)
at org.fest.swing.core.BasicRobot.waitForIdle(BasicRobot.java:654)
at org.fest.swing.core.BasicRobot.click(BasicRobot.java:426)
at org.fest.swing.core.BasicRobot.click(BasicRobot.java:387)
at org.fest.swing.core.BasicRobot.click(BasicRobot.java:372)
at org.fest.swing.core.BasicRobot.click(BasicRobot.java:360)
at org.fest.swing.driver.ComponentDriver.click(ComponentDriver.java:94)
at org.fest.swing.fixture.JButtonFixture.click(JButtonFixture.java:99)
代码如下:
BasicRobot robot = (BasicRobot) BasicRobot.robotWithCurrentAwtHierarchy()
MainFrame.button( "setup" ).click();
//Exception is thrown in this line
DialogFixture setupViewDialog = WindowFinder.findDialog( "setup" ).using( robot );
setupViewDialog.button( "Save" ).click();
我该如何解决这个问题?
看起来你不能从EDT调用click()
,所以启动一个新线程来调用它,像这样:
BasicRobot robot = (BasicRobot) BasicRobot.robotWithCurrentAwtHierarchy()
new Thread(new Runnable() {
@Override
public void run() {
MainFrame.button("setup").click();
}
}).start();
DialogFixture setupViewDialog = WindowFinder.findDialog( "setup" ).using( robot );
new Thread(new Runnable() {
@Override
public void run() {
setupViewDialog.button("Save").click();
}
}).start();