renatoathaydes / Automaton

Simple framework which allows the testing of Swing and JavaFX2 applications.
Apache License 2.0
100 stars 21 forks source link

JFX: Menu entries are not correctly found #28

Closed mirceade closed 9 years ago

mirceade commented 9 years ago

In JavaFx apps, "clicking" on a menu entry works but clicking on the resulting sub-menu items doesn't. JRE 8 - u 51

renatoathaydes commented 9 years ago

Which selector did you try when selecting the sub-menu items? text:, type: or some complex selector?

mirceade commented 9 years ago

It was "text:" but I'll double-check to see if it wasn't more than one component with that text on the screen at that moment.

renatoathaydes commented 9 years ago

Please make sure to use a good "narrowing" selector, something like matchingAll( "type:MenuItem", "text:My Text" ). If this does not work right, I'll have a look, it's possible the search algorithm missed something.

mirceade commented 9 years ago

We've tried it with the id selection: fxer.clickOn("#aboutMenuItem") and it DOES move the mouse near the element but not ON the element. It also could be clicking outside it.

We've also tried with a selector: fxer.clickOn(matchingAll("type:MenuItem", "text:About")) and it does not work because we get an exception like this: com.athaydes.automaton.GuiItemNotFound: Could not locate ComplexSelector(matchType:ALL,queries:[type:MenuItem, text:About])

Doing fxer.getAt("#aboutMenuItem") to get a reference of the element works but fxer.getAt(matchingAll("type:MenuItem", "text:About")) throws the same exception:

com.athaydes.automaton.GuiItemNotFound: Could not locate ComplexSelector(matchType:ALL,queries:[type:MenuItem, text:About])

renatoathaydes commented 9 years ago

Ok, thank you for all the details. I will fix this as soon as I can. Should release a fix in a few days.

renatoathaydes commented 9 years ago

Confirmed the bug. The y-coordinate of the menuItem is incorrect. Affects Java 7 and Java 8.

renatoathaydes commented 9 years ago

This bug was caused by a workaround for a JavaFX bug in which the Scene's position was reported incorrectly.

You can remove that workaround by running the following Groovy code in the same JVM where your tests will run:

com.athaydes.automaton.FXAutomaton.metaClass.static.getScenePosition = { Node node ->
    new Point( node.scene.x as int, node.scene.y as int )
}

I will publish a fix for this soon, if you prefer to wait.

mirceade commented 9 years ago

Hi, we will wait for a proper release because we've already implemented a quite fragile workaround: clicking based on relative coordinates. Thank you for your effort!

renatoathaydes commented 9 years ago

Released the fix. Change your Automaton version to 1.2.2.

mirceade commented 9 years ago

Fix confirmed.