TestFX中是否有功能可以测试选择框选择?

时间:2019-04-23 08:19:31

标签: java javafx testfx

我想用TestFX测试我编写的JavaFX GUI。第一步,我要测试一些ChoiceBox。

到目前为止,我已经尝试了以下代码:

this.step("fill creation view", () -> {
      this.clickOn("#receiverChoiceBox").clickOn("Max Mustermann");

      verifyThat("#receiverChoiceBox",
          ComboBoxMatchers.hasSelectedItem(this.userInformationMap.get(2)));
    });

但是,这将导致以下错误消息:

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]>)

我知道我正在使用ComboBox Matcher,但是之前我尝试过其他选项,但它们也不起作用。 ChoiceBox是否有类似的Matcher?

1 个答案:

答案 0 :(得分:0)

我现在已经解决了以下问题:

verifyThat("#receiverChoiceBox", node -> this.userInformationMap.get(2).equals(((ChoiceBox)node).getValue()));