Skip to content

Commit 793e3a7

Browse files
committed
Fix Node Should Be Hoverable Keyword to preperly move pointer, fixes #37
1 parent 95c424a commit 793e3a7

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/main/java/javafxlibrary/matchers/ExtendedNodeMatchers.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@
1919

2020
import javafx.geometry.Bounds;
2121
import javafx.scene.Node;
22+
import javafxlibrary.exceptions.JavaFXLibraryNonFatalException;
23+
import javafxlibrary.exceptions.JavaFXLibraryTimeoutException;
2224
import javafxlibrary.utils.HelperFunctions;
25+
import javafxlibrary.utils.RobotLog;
2326
import org.hamcrest.BaseMatcher;
2427
import org.hamcrest.Description;
2528
import org.hamcrest.Matcher;
2629

30+
import java.util.concurrent.TimeoutException;
31+
2732
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;
2836

2937
public 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

Comments
 (0)