TestFX中是否有测试选择框选择的功能?
Is there a function to test choice box selection in 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 匹配器,但我之前尝试过其他选项,但均无效。 ChoiceBox有没有类似的Matcher?
我现在已经解决问题如下:
verifyThat("#receiverChoiceBox", node -> this.userInformationMap.get(2).equals(((ChoiceBox)node).getValue()));
我想用 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 匹配器,但我之前尝试过其他选项,但均无效。 ChoiceBox有没有类似的Matcher?
我现在已经解决问题如下:
verifyThat("#receiverChoiceBox", node -> this.userInformationMap.get(2).equals(((ChoiceBox)node).getValue()));