java - 使用机器人定位主机(JFrame)(FEST Swing 测试)

标签 java swing fest

我正在使用 Java Web Start 应用程序(通过 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:WAITING使用匹配器 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 新手,刚刚开始使用它

谢谢

最佳答案

如果我仅从 native jar 中的类运行它,当前的 awt 层次结构似乎会看到该应用程序

关于java - 使用机器人定位主机(JFrame)(FEST Swing 测试),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33099717/

相关文章:

java - 在java中通过命令行输入一个文本文件

Java swing 绘图图形空指针?

java - 我怎样才能设置这个GUI的大小?

java - 使用 WindowFinder 查找模态对话框

Java,将华氏度转换为摄氏度

Java 重新尝试执行服务调用

java - 如何在 Java 中对 ArrayList 的 ArrayList 进行操作?

java - 使用 NetBeans IDE 将图像添加到 JPanel

java - 制作节 :s component lookup mechanism wait for a component to exist