2

I'm trying to run tests on multiple frames. When executed it hangs on the creation of a new Robot.

The first frame uses the default Robot, the code for the second Robot is below:

Robot robot2 = BasicRobot.robotWithCurrentAwtHierarchy();

window2 = new FrameFixture(robot2, frame2); 

I can't understand why it would not execute past this line, no errors are thrown it just pauses.

John Smith
  • 276
  • 1
  • 2
  • 15

2 Answers2

3

Try to use only one robot or make sure that before starting a new robot, that the old robot does a robot.cleanUp() or robot.cleanUpWithoutDisposingWindows() otherwise your new robot will just be waiting to get a lock on the screen, which the first robot owns, so your test program will just hang.

Marcin Sanecki
  • 1,324
  • 3
  • 19
  • 35
1

When creating the Fest's Robot or calling methods on the Robot make sure you are NOT on a UI thread. Alex Ruiz explains this caution of Swing-Fest threading in his blog.

I found that if I called methods on the Robot while on a JavaFX thread it consistently hung only on OS X 10.8.5 Java 7 (60). On Windows 8 Java 7 (60) the subtle, hidden problem did not reveal itself.

Perhaps adding Precondition calls with utility method like this:

public static boolean isUIThread()
{
    return SwingUtilities.isEventDispatchThread() || Platform.isFxApplicationThread();
}

such as

Preconditions.checkState(!Utilities.get().isUIThread());
Robot robot = new FrameFixture(frame).robot;

ensures you are calling the Robot methods safely.

(Wouldn't it be helpful if the Fest library could add some state or error conditions checks to enforce the threading requirements detailed in Alex's blog.)

javajon
  • 1,660
  • 16
  • 18