0

I‘m new to TestFX GUI-testing with fxrobot (javafx).

My current task is about clicking on a choice on a drop down menu created with combobox. I didn‘t find any tutorials mentioning this issue.

Is it really possible to implement the clickOn() method selecting a text in a combobox/drop down menu? Is there an example how to do it?

Thanks a million!

Luky
  • 49
  • 1
  • 10
  • both. I‘m using internal test framework based on fxrobot that calls fxml id. But the framework doesn‘t have the clickon() method so I have to be creative on this issue. – Luky Feb 12 '19 at 13:44

1 Answers1

2

This is an example of a way where a user selects the given text in the given combobox.

void user_selects_combo_item(String comboBoxId, String itemToSelect) {
    ComboBox<?> actualComboBox = lookupControl(comboBoxId);

    // Find and click only on arrow button. This is important for editable combo-boxes.
    for (Node child : actualComboBox.getChildrenUnmodifiable()) {
        if (child.getStyleClass().contains("arrow-button")) {
            Node arrowRegion = ((Pane) child).getChildren().get(0);
            robot.clickOn(arrowRegion);
            Thread.sleep(100); // try/catch were skipped for shorter code.
            robot.clickOn(itemToSelect);
        }
    }
    Assert.fail("Couldn't find an arrow-button.");
}

private <T extends Node> T lookupControl(String controlId) {
    T actualControl = robot.lookup(controlId).query();
    assertNotNull("Could not find a control by id = " + controlId, actualControl);

    return actualControl;
}
Dmytro Maslenko
  • 2,247
  • 9
  • 16