FEST:在执行任何操作之前等待GUI加载 [英] FEST: Wait for the GUI to load before doing anything
问题描述
@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秒暂停,则找不到表,因为应用程序加载它需要几秒钟。
This code works well. If we remove the 5 seconds pause, then the table is not found because it takes some seconds to the app to load it.
我想知道是否有更干净的方式。我在ApplicationLauncher之后尝试使用robot.waitForIdle()(我猜一旦EDT为空,一切都已加载),但它无法正常工作。
I would like to know if there is a cleaner way of doing it. I tried with robot.waitForIdle() after ApplicationLauncher (I guess once EDT is empty, everything is loaded), but it just doesn´t work.
我知道暂停可以使用某些条件作为何时停止的事件,但我不明白如何编写它,因为JavaDoc和官方文档很差。
I know pause can use some conditions as an event on when to stop, but I don´t understand how to write it since JavaDoc and official doc is poor.
- Pause.pause(WaitForComponentToShowCondition.untilIsShowing(frame.component())):我需要一个组件,如果我通过包装器框架它不起作用。而且我无法通过这张桌子,因为这正是我正在等待的内容。
-
我明白我应该使用ComponentFoundCondition,但我不明白!我厌倦了:
- Pause.pause(WaitForComponentToShowCondition.untilIsShowing(frame.component())) : I need a component, if I pass the wrapper frame it does not work. And I cannot pass the table because thats precisely what I am waiting for to get.
I understand then I should probably work with ComponentFoundCondition but I dont get it! I tired with:
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 来定位组件。例如,基于问题中的匹配器:
You could use ComponentFinder to locate the component. For example, based on the matcher in the question:
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);
这是一个按名称查找的替代方案:
Here is an alternative with lookup by name:
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);
这篇关于FEST:在执行任何操作之前等待GUI加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!