FEST-swing example doesn't work, frame.isShowi

2019-05-18 12:43发布

问题:

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.)