assertj / assertj/assertj-swing
JComboBoxFixture.selectItem don't always work as expected
- Dominant language
- Java
- Stars
- 121
- Forks
- 52
- PR merge metrics
- No merged PRs in 30d
Description
Hi Joel.
First of all, thank you for your very interesting work. I've been using assertJ-core and assertJ-swing for several weeks now (and I like it a lot), but I'm experiencing random failures in my tests when playing with comboboxes.
Consider the following loop :
```
for (int i = 0; i < 10; i++) {
GuiActionRunner.execute(() -> {
JComboBox combo = new JComboBox<>();
combo.addItem("item_1");
combo.addItem("item_2");
jFrame = Containers.frameFor(combo);
jFrame.setName(this.getClass().getName());
jFrame.setVisible(true);
});
FrameFixture frame = new FrameFixture(jFrame);
frame.comboBox().selectItem(1);
frame.comboBox().requireSelection(1); // **** randomly fails *****
frame.cleanUp();
}
```
A ComparisonFailure is thrown most of the time, after a random number of iterations.
```
org.junit.ComparisonFailure: [javax.swing.JComboBox[name=null, selectedItem='item_1', contents=["item_1", "item_2"], editable=false, enabled=true, visible=true, showing=true] - property:'selectedIndex'] expected:<[1]> but was:<[0]>
```
I found a workaround by **explicitly clicking** on combo before selecting item.
```
frame.comboBox().click().selectItem(1);
```
I noticed the problem whenever selecting items using index or text.
What do you think ? Am I missing something or is it actually an issue ?
Regards
Contributor guide
Assessment
This issue has not been assessed yet.