-->

FEST:等待的GUI做任何事情之前加载(FEST: Wait for the GUI to loa

2019-09-20 06:52发布

    @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是空的,一切都是装),但它只是doesn't工作。

我知道暂停可以使用一些条件,在什么时候停止的事件,但我不知道怎么写,因为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)); 

任何帮助吗?

Answer 1:

你可以使用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);


文章来源: FEST: Wait for the GUI to load before doing anything