1919
2020import javafx .geometry .Bounds ;
2121import javafx .scene .Node ;
22+ import javafxlibrary .exceptions .JavaFXLibraryNonFatalException ;
23+ import javafxlibrary .exceptions .JavaFXLibraryTimeoutException ;
2224import javafxlibrary .utils .HelperFunctions ;
25+ import javafxlibrary .utils .RobotLog ;
2326import org .hamcrest .BaseMatcher ;
2427import org .hamcrest .Description ;
2528import org .hamcrest .Matcher ;
2629
30+ import java .util .concurrent .TimeoutException ;
31+
2732import static javafxlibrary .utils .HelperFunctions .getHoveredNode ;
33+ import static org .testfx .util .WaitForAsyncUtils .waitFor ;
34+ import static org .testfx .util .WaitForAsyncUtils .asyncFx ;
35+ import static org .testfx .util .WaitForAsyncUtils .waitForFxEvents ;
2836
2937public class ExtendedNodeMatchers {
3038
@@ -48,8 +56,21 @@ public void describeMismatch(Object object, Description description) {
4856 }
4957
5058 private static boolean hoverable (Node node ) {
51- new javafxlibrary .keywords .Keywords .MoveRobot ().moveTo (node ,"DIRECT" );
52- return node .isHover ();
59+ try {
60+ waitFor (HelperFunctions .getWaitUntilTimeout (), HelperFunctions .getTimeUnit ("SECONDS" ), () -> {
61+ return asyncFx (() -> new javafxlibrary .keywords .Keywords .MoveRobot ().moveTo (node , "DIRECT" ) != null ).get ();
62+ });
63+ waitForFxEvents ();
64+ return node .isHover ();
65+ } catch (JavaFXLibraryNonFatalException nfe ) {
66+ throw nfe ;
67+ } catch (TimeoutException te ) {
68+ throw new JavaFXLibraryTimeoutException ("Given element \" " + node + "\" was not found within given timeout of "
69+ + HelperFunctions .getWaitUntilTimeout () + " " + "SECONDS" );
70+ } catch (Exception e ) {
71+ RobotLog .trace ("Exception in hoverable matcher: " + e + "\n " + e .getCause ().toString ());
72+ throw new JavaFXLibraryNonFatalException ("hoverable matcher failed: " , e );
73+ }
5374 }
5475
5576 public static boolean hasValidCoordinates (Node node ) {
0 commit comments