6

我正在使用 FEST 测试我的 Java 对话框,我需要测试是否创建了一个新的模式对话框。

@Before
public void setUp() throws Exception {
    TestFrame testFrame = GuiActionRunner.execute(new GuiQuery<TestFrame>() {
        @Override
        protected TestFrame executeInEDT() throws Throwable {

            panel = new CustomPanel();
            return new TestFrame(panel);
        }
    });

    frameFixture = new FrameFixture(testFrame);
    frameFixture.show();

    frameFixture.robot.waitForIdle();
}

注意:TestFrame 是一个辅助类,它扩展了 JFrame 以用于单元测试。

在我的测试中,我单击了一个按钮,它会出现一个模式对话框。我正在尝试查找并验证已创建对话框,但是我的所有尝试都找不到任何东西:

WindowFinder.findDialog("Window Title")).using(robot);

其中机器人 =

  1. BasicRobot.robotWithCurrentAwtHierarchy();
  2. BasicRobot.robotWithNewAwtHierarchy();
  3. frameFixture.robot (frameFixture => JFrame)

我也尝试过指定机器人的查找范围:

robot.settings().componentLookupScope(ComponentLookupScope.ALL);

网上有很多 FEST 示例可以调用,robot()但我不知道这个机器人功能应该如何或应该是什么。

为什么我找不到我新创建的弹出对话框?

4

2 回答 2

1

尝试添加查找时间:

WindowFinder.findDialog(MyDialog.class).withTimeout(10000).using(robot);

欲了解更多信息: http: //fest.googlecode.com/svn-history/r458/trunk/fest/fest-swing/javadocs/org/fest/swing/fixture/util/WindowFinder.html

于 2015-06-30T21:27:06.363 回答
0

最近,我也在使用 FEST 进行测试。

在处理相同情况时,我使用以下方法来模拟“获取此窗口/对话框”操作

private DialogFixture blablawindow;
...
blablawindow = WindowFinder.findDialog("XXX").using(robot());
blablawindow.button("button1").click();

由于我是 FEST 的新手,所以对我来说,需要注意一些事情:

XXX 不是 UI 上显示的实际文本,您需要查看源代码才能看到窗口/对话框的名称:看起来像这样setName("actual name of window"); 或任何摆动元素private javax.swing.JButton button1;

于 2015-07-10T21:06:59.290 回答