javaswingunit-testingfest

Using WindowFinder to find a modal dialog


I am using FEST to test my Java dialogs and I need to test that a new modal dialog is created.

@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();
}

Note: TestFrame is a helper class which extends JFrame for use in unit testing.

In my test, I click a button which makes a modal dialog appear. I am trying to find and verify the dialog is created, however all of my attempts aren't able to find anything:

WindowFinder.findDialog("Window Title")).using(robot);

Where robot =

  1. BasicRobot.robotWithCurrentAwtHierarchy();
  2. BasicRobot.robotWithNewAwtHierarchy();
  3. frameFixture.robot (frameFixture => JFrame)

I have also tried specifying the lookup scope of the robot:

robot.settings().componentLookupScope(ComponentLookupScope.ALL);

There are lots of FEST examples online which make a call to robot() but I can't find out how or what this robot function is supposed to be.

Why am I unable to find my newly created popup dialog?


Solution

  • Try adding a lookup time:

    WindowFinder.findDialog(MyDialog.class).withTimeout(10000).using(robot);
    

    For more info: http://fest.googlecode.com/svn-history/r458/trunk/fest/fest-swing/javadocs/org/fest/swing/fixture/util/WindowFinder.html