使用WindowFinder查找模态对话框

gle*_*roo 6 java swing unit-testing fest

我正在使用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();
}
Run Code Online (Sandbox Code Playgroud)

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

在我的测试中,我单击一个按钮,显示模式对话框.我试图找到并验证对话框是否已创建,但是我的所有尝试都无法找到任何内容:

WindowFinder.findDialog("Window Title")).using(robot);
Run Code Online (Sandbox Code Playgroud)

机器人=

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

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

robot.settings().componentLookupScope(ComponentLookupScope.ALL);
Run Code Online (Sandbox Code Playgroud)

网上有很多FEST例子可以调用,robot()但是我无法知道这个机器人函数应该是什么或者是什么.

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

Amb*_*ber 1

尝试添加查找时间:

WindowFinder.findDialog(MyDialog.class).withTimeout(10000).using(robot);
Run Code Online (Sandbox Code Playgroud)

有关详细信息:http://fest.googlecode.com/svn-history/r458/trunk/fest/fest-swing/javadocs/org/fest/swing/fixture/util/WindowFinder.html