2

I'm writing a JavaFX application with a menubar. I have given the menu items CSS ids, and I want to use TestFX to click on them. Here's the code:

clickOn("#menu-file").clickOn("#menu-file-new-project");

When I run this I can see my mouse move to the completely wrong place on the screen, and then the test fails saying it couldn't find any elements matching #menu-file-new-project. I'm assuming it can't find them because it's never opening the File menu, because it's clicking in the wrong location.

What should I do about that? Windows 10, Java 8u120, TestFX 4.0.6. For the record it fails the same way in monocle headless mode

Nick
  • 6,900
  • 5
  • 45
  • 66
  • I have a 4K monitor and Windows is running in 2x mode so it is almost certainly this issue: https://github.com/TestFX/TestFX/issues/245 unfortunately not fixed yet. whether a test passes or fails should definitely have nothing to do with the pixel density of my monitor... – Nick May 23 '17 at 03:02

1 Answers1

0

Okay, this has nothing to do with the scale and I'm not even sure why it works, but overriding the point method as follows in my Test Application instance seems to work for some reason:

@Override
public PointQuery point(Node node) {
    Point2D topLeftPoint = node.localToScreen(0, 0);
    Point2D pos = new Point2D(topLeftPoint.getX(), topLeftPoint.getY());

    return super.point(node).atOffset(pos);
}
Nick
  • 6,900
  • 5
  • 45
  • 66