Java 使用WindowFinder查找模式对话框

Java 使用WindowFinder查找模式对话框,java,swing,unit-testing,fest,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

我正在使用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();
}
机器人在哪里=

  • BasicRobot.robotWithCurrentAwtHierarchy()
  • BasicRobot.robotWithNewAwtHierarchy()
  • frameFixture.robot(frameFixture=>JFrame)
  • 我还尝试指定robot的查找范围:

    robot.settings().componentLookupScope(ComponentLookupScope.ALL);
    
    在线上有很多FEST示例,它们调用了
    robot()
    ,但我不知道这个robot函数应该是什么样的


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

    尝试添加查找时间:

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

    更多信息:

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

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

    由于我是FEST的新手,所以对我来说,有些事情需要小心:

    XXX不是UI上显示的实际文本,您需要检查源代码以查看窗口/对话框的名称: 看起来像是
    setName(“窗口的实际名称”)
    
    或任何swing元素
    私有javax.swing.JButton按钮1

    是否可以包含一个完整的示例,以便我可以查看这些解决方案中是否有任何一个可行?我发现了一个这样创建机器人的例子:robot=BasicRobot.robotWithCurrentAwtHierarchy();robot.settings().delayBetweenEvents(50);还有一个像这样寻找窗口的:WindowFinder.findDialog(MyDialog.class).withTimeout(10000).using(robot);此外,请参阅这篇文章,其中解释了在实例化任何帧或对话框之前必须设置机器人。
    WindowFinder.findDialog(MyDialog.class).withTimeout(10000).using(robot);
    
    private DialogFixture blablawindow;
    ...
    blablawindow = WindowFinder.findDialog("XXX").using(robot());
    blablawindow.button("button1").click();