19
19
20
20
import javafx .geometry .Bounds ;
21
21
import javafx .scene .Node ;
22
+ import javafxlibrary .exceptions .JavaFXLibraryNonFatalException ;
23
+ import javafxlibrary .exceptions .JavaFXLibraryTimeoutException ;
22
24
import javafxlibrary .utils .HelperFunctions ;
25
+ import javafxlibrary .utils .RobotLog ;
23
26
import org .hamcrest .BaseMatcher ;
24
27
import org .hamcrest .Description ;
25
28
import org .hamcrest .Matcher ;
26
29
30
+ import java .util .concurrent .TimeoutException ;
31
+
27
32
import 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 ;
28
36
29
37
public class ExtendedNodeMatchers {
30
38
@@ -48,8 +56,21 @@ public void describeMismatch(Object object, Description description) {
48
56
}
49
57
50
58
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
+ }
53
74
}
54
75
55
76
public static boolean hasValidCoordinates (Node node ) {
0 commit comments