FEST:在做任何事情之前等待GUI加载
题
@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()在applicationlauncher之后(我猜一旦edt为空,一切都已加载),但它只是不起作用。
我知道暂停可以用一些条件作为何时停止的事件,但是我不明白如何编写它,因为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));
任何帮助?
解决方案
您可以使用 componentfinder 要定位组件。例如,基于问题的匹配:
final ComponentMatcher matcher = new TypeMatcher(myTreeTable.class);
Pause.pause(new Condition("Waiting for myTreeTable") {
@Override
public boolean test() {
Collection<Component> list =
window.robot.finder().findAll(window.target, matcher);
return list.size() > 0;
}
}, 5000);
.
这是一个替代的查找名称:
final ComponentMatcher nameMatcher = new ComponentMatcher(){
@Override
public boolean matches(Component c) {
return "ComponentName".equals(c.getName()) && c.isShowing();
}
};
Pause.pause(new Condition("Waiting") {
@Override
public boolean test() {
Collection<Component> list =
window.robot.finder().findAll(window.target, nameMatcher);
return list.size() > 0;
}
}, 5000);
. 不隶属于 StackOverflow