Using WindowFinder to find a modal dialog

1k views Asked by At

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?

2

There are 2 answers

0
Amber On BEST ANSWER

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

0
Zzz... On

Recently, I am also using FEST to do the testing.

When working on the same situation I use the following method to simulate the "get this window/dialog" action

private DialogFixture blablawindow;
...
blablawindow = WindowFinder.findDialog("XXX").using(robot());
blablawindow.button("button1").click();

As I am new to FEST, so for me, something need to be careful:

XXX is not the actual text that is shown on UI, you need to check the source code to see the name of the window/dialog: looks like this setName("actual name of window"); or any swing element private javax.swing.JButton button1;