【发布时间】:2012-07-26 17:04:16
【问题描述】:
@Before public void setUp() {
Robot robot = BasicRobot.robotWithCurrentAwtHierarchy();
ApplicationLauncher.application("myApp").start();
Pause.pause(5, TimeUnit.SECONDS);
frame = WindowFinder.findFrame("frame0").using(robot);
JTableFixture table = frame.table(new GenericTypeMatcher<JTable>(JTable.class) {
@Override protected boolean isMatching(JTable table) {
return (table instanceof myTreeTable);
}
});
}
此代码运行良好。如果我们删除 5 秒的暂停,则找不到该表,因为应用程序需要几秒钟来加载它。
我想知道是否有更清洁的方法。我在 ApplicationLauncher 之后尝试使用 robot.waitForIdle()(我猜一旦 EDT 为空,所有内容都已加载),但它不起作用。
我知道 pause 可以使用某些条件作为何时停止的事件,但我不明白如何编写它,因为 JavaDoc 和官方文档很差。
- Pause.pause(WaitForComponentToShowCondition.untilIsShowing(frame.component())) :我需要一个组件,如果我通过包装框架它不起作用。而且我不能通过桌子,因为这正是我正在等待得到的。
-
我明白我可能应该使用 ComponentFoundCondition 但我不明白!我厌倦了:
ComponentMatcher matcher = new GenericTypeMatcher<JTable>(JTable.class) { @Override protected boolean isMatching(JTable table) { return (table instanceof myTreeTable); } }; Pause.pause(new ComponentFoundCondition("DebugMsg", frame.robot.finder(), matcher));
有什么帮助吗?
【问题讨论】:
标签: java swing testing robot fest