【问题标题】:Locating Main Frame (JFrame) using Robot (FEST Swing tests)使用机器人定位主框架 (JFrame)(FEST Swing 测试)
【发布时间】:2015-10-13 10:00:41
【问题描述】:

我正在使用 Java Web 启动应用程序(通过 JNLP 运行)。目前我正在尝试使用此代码为应用程序定位主框架:

Process p = Runtime.getRuntime().exec("C:\\Windows\\System32\\cmd.exe /c cd C:/Users/ash/Documents/MyApp/Environment & launcher.jnlp", null, new File("C:\\Users\\ash\\Documents\\MyApp\\Environment"));
    p.waitFor();
    Thread.sleep(40000);
    robot = BasicRobot.robotWithCurrentAwtHierarchy();
    robot.settings().delayBetweenEvents(50);
FrameFixture frame = WindowFinder.findFrame(getMainFrameByTitle(".*?MyApp.*?")).using(robot);
    frame.focus();

但是我遇到了一个错误:

org.fest.swing.exception.WaitTimedOutError: 等待使用匹配器 swing.app.simple.test.JavaSwingTests$9@6c5b675e 找到组件时超时 无法使用匹配器 swing.app.simple.test.JavaSwingTests$9@6c5b675e 找到组件。

下面的方法是我用来按名称匹配框架:

private static GenericTypeMatcher<javax.swing.JFrame> getMainFrameByName(
        final String frame) {
    GenericTypeMatcher<javax.swing.JFrame> textMatcher = new GenericTypeMatcher<javax.swing.JFrame>(
            javax.swing.JFrame.class) {
        protected boolean isMatching(javax.swing.JFrame frameName) {
            return (frame.replace(" ", "")).equals(frameName.getName()
            .replace(" ", ""));
        }
    };
    return textMatcher;
}

如果我做错了什么或没有考虑我应该做的事情,谁能告诉我。我是 FEST 的新手,刚刚开始使用它

谢谢

【问题讨论】:

  • 小修正FrameFixture frame = WindowFinder.findFrame(getMainFrameByName(".*?MyApp.*?")).using(robot); frame.focus();

标签: java swing fest


【解决方案1】:

如果我只在本机 jar 中从 Class 运行它,似乎当前的 awt 层次结构会看到应用程序

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 2017-10-19
    • 2017-11-19
    • 2018-09-16
    • 2018-10-25
    相关资源
    最近更新 更多