【问题标题】:Using WindowFinder to find a modal dialog使用 WindowFinder 查找模式对话框
【发布时间】:2015-06-17 13:39:20
【问题描述】:

我正在使用 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(),但我不知道这个机器人功能应该是如何或应该是什么。

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

【问题讨论】:

  • 是否可以包含一个完整的示例,以便我查看这些解决方案是否可行?我找到了一个这样创建机器人的示例:robot=BasicRobot.robotWithCurrentAwtHierarchy();机器人.settings().delayBetweenEvents(50);另一个寻找这样的窗口:WindowFinder.findDialog(MyDialog.class).withTimeout(10000).using(robot);此外,请参阅这篇文章,该文章解释了您必须在实例化任何框架或对话框之前设置您的机器人。 stackoverflow.com/a/4965444/1324406

标签: java swing unit-testing fest


【解决方案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

【讨论】:

    【解决方案2】:

    最近我也在用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;

    【讨论】:

      猜你喜欢
      • 2011-04-19
      • 1970-01-01
      • 1970-01-01
      • 2015-09-19
      • 1970-01-01
      • 2021-04-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      相关资源
      最近更新 更多