FEST Swing new frame on click, can't make new

2019-05-24 11:08发布

I am trying to write a Fest Swing test but am having trouble making / finding a frame fixture. I have two JFrames, one opens the other on click, and I'd like to either:

1.) find the frame fixture of the new JFrame opened

2.) make a new frame fixture out of the the new JFrame object created (I can get the object from the original JFrame Object.)

I have tried using

    GenericTypeMatcher<secondGUI> matcher = new GenericTypeMatcher<secondGUI>(secondGUI.class) {
        protected boolean isMatching(secondGUI frame) {
            System.out.println("0".equals(frame.getTitle()) && frame.isShowing());
            return "0".equals(frame.getTitle()) && frame.isShowing();
        }
    };
    Robot robot = BasicRobot.robotWithCurrentAwtHierarchy();

to find the frame, but run into an EdtViolationException.

I have also tried

    secondGUI secGUI = GuiActionRunner.execute(new GuiQuery<secondGUI>() {
        @Override
        protected secondGUI executeInEDT() throws Throwable {
            return firstGUI.getController().getWindows().get("0");
        }
    });
    FrameFixture secondWindow = new FrameFixture(secGUI);

But the last line gave an EdtViolationException as well. Any suggestions? Thanks!

标签: java swing fest
1条回答
Animai°情兽
2楼-- · 2019-05-24 12:04

Try finding your frame using the title of the frame:

Robot robot = BasicRobot.robotWithCurrentAwtHierarchy();
FrameFixture frame = WindowFinder.findFrame("Title of my frame").using(robot);

Also, secondGUI should be SecondGUI since it's a class name.

BTW, glad to see another FEST user.

查看更多
登录 后发表回答