问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/10626357/fest-swing-new-frame-on-click-cant-make-new-frame-fixture