Search code examples
javatestingjavafxtestfx

Why isn't the correct TextField being clicked TestFX?


I have 2 text fields inside a button bar. I have given both a fxid. Both Textfields are next to each other.

The left text field has a fx:id newCol While the texfield to it's right has a fx:id of Name

I am doing the following test

 @Test
    public void ensureNewColIsCreated() {
        clickOn("#newCol").write("To do list!");
        sleep(2000);
        clickOn("#Name").write("New page");
        sleep(2000);
    }

Expected outcome should be it first goes to the left textfield, rights the command. It should then type the another message into the right textfield.

However what happens instead is after the first message is typed into the left Textfield, the next message which should be typed into the right textfield also gets typed into the left texfield. Right before the second message the mouse does move ever so slightly to the right.

Now when I swap the two lines as shown below

 @Test
    public void ensureNewColIsCreated() {
        clickOn("#Name").write("To do list!");
        sleep(2000);
        clickOn("#newCol").write("New page");
        sleep(2000);
    }

The message should be typed into the right textfield first. However, it is still being typed into the left textfield. Both messages are.

If i just do the following without specifying the fx:id, it still types into the left textfield

@Test
    public void ensureNewColIsCreated() {
        write("Test");
    }

I'm guessing I am using testfx horribly wrong or something because I am very new to it and it is my first time doing any kind of testing. If someone can help me out that would be great.

Edit: Ok i tested it out again by having the test click on my button that closes the application, however it fails to do so indicating the test not clicking on the fx:ids i give it. Why is this the case? I have no idea.


Solution

  • OK, so the reason for why it was not working was because I was using 4.0.13-alpha for testfx-core and testfx-junit4 for dependencies along with jdk 11. However, someone please correct me if I'm wrong, but anything to do with mouseMove did not work correctly on jdk 11 and all this was corrected in 4.0.15-alpha and testfx-junit5 for dependencies.