6

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?

glenneroo
  • 1,908
  • 5
  • 30
  • 49
  • Is it possible to include a complete example so I can see if any of these solutions will work? I found one example that creates the robot like this: robot=BasicRobot.robotWithCurrentAwtHierarchy(); robot.settings().delayBetweenEvents(50); And another that looks for the window like this: WindowFinder.findDialog(MyDialog.class).withTimeout(10000).using(robot); Also, see this post that explains you have to set up your robot before any frame or dialog is instantiated. http://stackoverflow.com/a/4965444/1324406 – Amber Jun 30 '15 at 15:34

2 Answers2

1

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

Amber
  • 2,413
  • 1
  • 15
  • 20
0

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;

Zzz...
  • 291
  • 6
  • 19