首页 > 解决方案 > TestFX 中是否有测试选择框选择的功能?

问题描述

我想用 TestFX 测试我编写的 JavaFX GUI。在一个步骤中,我想测试一些选择框。

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

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 吗?

标签: javajavafxtestfx

解决方案


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

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

推荐阅读