FEST-swing example doesn't work, frame.isShowing() return false

天大地大妈咪最大 提交于 2020-01-02 09:28:08

问题


Try to use the FEST-Swing for Swing GUI testing, and using example from http://easytesting.org/swing/wiki/pmwiki.php?n=FEST-Swing.LaunchFromMain

Unfortunately the frame.isShowing() always return false though I already see the JavaApp Swing is running

See my codes

...
    ApplicationLauncher.application(JavaApp.class).start();
    GenericTypeMatcher<Frame> matcher = new GenericTypeMatcher<Frame>(Frame.class) {
        protected boolean isMatching(Frame frame) {
        System.out.println("title:" + frame.getTitle() + " showing:" +frame.isShowing()); // .getTitle());
            return "Java Application".equals(frame.getTitle()) && frame.isShowing();
        }
    };
    Robot robot = BasicRobot.robotWithNewAwtHierarchy();
    FrameFixture frame2 = WindowFinder.findFrame(matcher).withTimeout(5000).using(robot);
...

from the console log

title: showing: false

Two questions:
1. I have to use Frame insteaf of JFrame, otherwise it can't be matched, it cause the title is not correct, I expect "Java Application"
2. the frame.isShowing() is always returning false, it seems strange

BTW: lastest codes seems needs parameter for GenericTypeMatcher() rgs/larry


回答1:


The problem is that you are calling robotWithNewAwtHierarchy after you launch your app. What happens is that any frame or dialog instantiated before calling robotWithNewAwtHierarchy will not be seen by the created Robot.

You can either move robotWithNewAwtHierarchy before the line where you start your app, or you can use robotWithCurrentAwtHierarchy instead (which will see any instantiated frame or dialog, regardless when this method is called.)



来源:https://stackoverflow.com/questions/3296477/fest-swing-example-doesnt-work-frame-isshowing-return-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!