I want to test my written JavaFX GUI with TestFX. In one step there are some ChoiceBoxs that i want to test.
I have tried the following code so far:
this.step("fill creation view", () -> {
this.clickOn("#receiverChoiceBox").clickOn("Max Mustermann");
verifyThat("#receiverChoiceBox",
ComboBoxMatchers.hasSelectedItem(this.userInformationMap.get(2)));
});
However, this will result in the following error message:
java.lang.AssertionError:
Expected: ComboBox has selection "xxx.model.dto.UserInformationDto@d84f7f5d"
but: was a xxx.gui.control.xxxChoiceBox (<xxxChoiceBox[id=receiverChoiceBox, styleClass=choice-box]>)
Expected :ComboBox has selection "xxx.model.dto.UserInformationDto@d84f7f5d"
Actual :a xxx.gui.control.xxxChoiceBox (<xxxChoiceBox[id=receiverChoiceBox, styleClass=choice-box]>)
I know I'm using a ComboBox Matcher, but I've tried other options before, which didn't work either. Is there a similar Matcher for ChoiceBox?
I have now solved the problem as follows:
verifyThat("#receiverChoiceBox", node -> this.userInformationMap.get(2).equals(((ChoiceBox)node).getValue()));