FEST-swing示例不起作用,frame.isShowing()返回false [英] FEST-swing example doesn't work, frame.isShowing() return false
问题描述
尝试将FEST-Swing用于Swing GUI测试,并使用来自 http://easytesting.org/swing/wiki/pmwiki.php?n=FEST-Swing.LaunchFromMain
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
不幸的是,尽管我已经看到JavaApp Swing正在运行,frame.isShowing()总是返回false
Unfortunately the frame.isShowing() always return false though I already see the JavaApp Swing is running
查看我的代码
...
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);
...
从控制台日志中
title: showing: false
两个问题:
1.我必须使用JFrame的Frame insteaf,否则无法匹配,导致标题不正确,我希望"Java应用程序"
2. frame.isShowing()总是返回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
顺便说一句:最新代码似乎需要GenericTypeMatcher()的参数 rgs/larry
BTW: lastest codes seems needs parameter for GenericTypeMatcher() rgs/larry
推荐答案
问题是您启动应用后正在调用robotWithNewAwtHierarchy
.发生的情况是,在调用robotWithNewAwtHierarchy
之前实例化的任何框架或对话框都不会被创建的机器人看到.
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.
您可以将robotWithNewAwtHierarchy
移动到启动应用程序的行之前,也可以使用robotWithCurrentAwtHierarchy
(无论何时调用此方法,都会看到任何实例化的框架或对话框.)
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.)
这篇关于FEST-swing示例不起作用,frame.isShowing()返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!